/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var PName = "";
var PTitle = "";
var PCount = 0;
var PIndex = 0;
var SPIndex = "";
var PageName

function ShowProject(Page, ProjectName, ProjectIndex, ProjectCount)
{
	//set variable values
	PageName = Page;
	PTitle = ProjectName;
	PName = ProjectName + ProjectIndex;
	PCount = ProjectCount;
	PIndex = parseInt(ProjectIndex);
	
	//hide first
	HideProjects();
	//centering with css
	centerPopup();
	//load popup
	loadPopup();
}

function NextProject()
{
	if (PIndex == PCount)
	{
		HideProjects();
		PIndex = 1;
		PName = PTitle + '1';
		LoadNext();
	}
	else
	{
		HideProjects();
		PIndex = PIndex + 1;
		SPIndex = PIndex + '';
		PName = PTitle + SPIndex;
		LoadNext();
	}
}

function LoadNext()
{
	$(PName).fadeIn("slow");
	$(PName).css({"visibility": "visible"});
	centerPopup();
}

function SelectProject(ProjectName)
{
	HideProjects();
	$(ProjectName).fadeIn("slow");
	$(ProjectName).css({
		"position": "absolute",
		"top": 0,//windowHeight/2-popupHeight/2,
		"left": 0//windowWidth/2-popupWidth/2
	});
	$(ProjectName).css({"visibility": "visible"});
}

function ShowSubProject(ProjectName, top, left)
{
	$(ProjectName).fadeIn("slow");
	$(ProjectName).css({
		"position": "absolute",
		"top": top,//windowHeight/2-popupHeight/2,
		"left": left//windowWidth/2-popupWidth/2
	});
	$(ProjectName).css({"visibility": "visible"});
}

function SetProject(ProjectName, ProjectIndex, ProjectCount)
{
	PTitle = ProjectName;
	PName = ProjectName + ProjectIndex;
	PCount = ProjectCount;
	PIndex = parseInt(ProjectIndex);
	
	HideProjects();
	$(PName).fadeIn("slow");
	$(PName).css({
		"position": "absolute",
		"top": 0,//windowHeight/2-popupHeight/2,
		"left": 0//windowWidth/2-popupWidth/2
	});
	$(PName).css({"visibility": "visible"});
}
//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#BackGround").css({
			"opacity": "0.7"
		});
		$("#BackGround").fadeIn("slow");
		$("#ProjectHolder").fadeIn("slow");
		$(PName).fadeIn("slow");
		$(PName).css({"visibility": "visible"});
		//"#ProjectHolder"
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#BackGround").fadeOut("slow");
		$("#ProjectHolder").fadeOut("slow");
		$(PName).fadeOut("slow");
		
		HideProjects();
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#ProjectHolder").height();
	var popupWidth = $("#ProjectHolder").width();
	
	//width
	if (window.innerWidth) {
		windowWidth=window.innerWidth;
	}
	else
	if (document.documentElement && document.documentElement.clientWidth) {
		windowWidth=document.documentElement.clientWidth;
	}
	else
	if (document.body) {
		windowWidth=document.body.clientWidth;
	}
	var popupLeft = windowWidth/2-200;
	
	//centering
	$("#ProjectHolder").css({
		"position": "absolute",
		"top": 50,//windowHeight/2-popupHeight/2,
		"left": popupLeft
	});
	
	$(PName).css({
		"position": "absolute",
		"top": 0,//windowHeight/2-popupHeight/2,
		"left": 0//windowWidth/2-popupWidth/2
	});
	
	//only need force for IE6
	$("#BackGround").css({
		"height": 1100//windowHeight
		//set fixed value for IE
	});
	
}

function HideProjects()
{
	if (PageName == 'Main')
	{
		//web
		$("#CaseStudy1").fadeOut("slow");
		$("#CaseStudy1").css({"visibility": "hidden"});
	}
}


