

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
var gPopupWindow = null;
var gCrossFade = null;
var gActiveID = null;
var DEMO_POPUP = 1;
var CASESTUDY_POPUP = 2;

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function PopupWindow(id, visibleCSS, hiddenCSS, nType, kind)
{
	this.fid = id;
	this.fvisibleCSS = visibleCSS;
	this.fhiddenCSS  = hiddenCSS;
	this.fnType = nType;
	this.fkind   = kind;
	this.fnOpacity = 0;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function CrossFadeData(idIn)
{
	this.fidIn  = idIn;
	this.fnOpacity = 0;
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function setAlpha(popup, object, val)
{
	if(popup != null)
	{
		popup.fnOpacity = val;
	}
	
	num = Number(val);
	if(num <= 1)
	{
		if(num >= 0.99 && isSafari())
			num = 0.99;
		object.style.opacity = num;
	}
	//if(isIE())
	//{
	//	var nIEX = Number(val) * 100;
	//	object.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=\"" + nIEX + "\")"; //" + (val*10) + "\")"; 
	//}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function incrementAlpha(popup, object, nInc)
{
	popup.fnOpacity = Number(popup.fnOpacity) + Number(nInc);
	if(popup.fnOpacity > 1)
		popup.fnOpacity = 1;
	setAlpha(popup, object, popup.fnOpacity);
	return Number(popup.fnOpacity);
}
	

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function fadeInPopup(popup)
{
	hideTopFlash();
	
	popup.finterval = setInterval("onPopupCallback()", 50);
	var object = document.getElementById(popup.fid);
	var objDrop = document.getElementById(popup.fidDrop);
	

	object.className = popup.fvisibleCSS;		
	if(popup.fnType == DEMO_POPUP)
	{
		object.innerHTML = "<b>" + getDemoTitle(popup.fkind) + "</b>";
	}
	var closeBox = document.getElementById('closeBox');
	
	setAlpha(popup, object, 0);
	setAlpha(null, closeBox, 0);
	//setAlpha(objDrop, 0);
	
	//objDrop.style.display = 'block';
	//objDrop.style.visibility = 'visible';
	object.style.display = 'block';
	object.style.visibility = 'visible';
	closeBox.style.visibility = 'visible';	
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function getDemoTitle(kind)
{
	switch(kind)
	{
	case 'slug':
		return "Slug Cubed Demo";
	case 'crop':
		return "Crop Cubed Demo";
	case 'job':
		return "Job Spec Cubed Demo";
	case 'color':
		return "Color Spec Cubed Demo";
	}
	return "";
}


//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function onPopupCallback()
{	
	var popup = gPopupWindow;
	var object   = document.getElementById(popup.fid);
	var closeBox = document.getElementById('closeBox');
	
	var nNext = incrementAlpha(popup, object, 0.1);
	if(nNext  >= 1)
	{
		setAlpha(null, closeBox, 1);
		clearInterval(popup.finterval);
		popup.finterval = 0;
		
	 
		if(popup.fnType == DEMO_POPUP)
		{
			object.innerHTML = "<b>" + getDemoTitle(popup.fkind) + "</b><script type=\"text/javascript\">\n";
			var strMovieURL = "http://www.tripletriangle.com/DemoPreloader.swf?subject=" + popup.fkind;
			if(isWindows())
			{
				var strSWF = "";
				switch(popup.fkind)
				{
				case "slug":
					strSWF = "DemoSlug.swf";
					break;
				case "crop":
					strSWF = "DemoCrop.swf";
					break;
				case "job":
					strSWF = "DemoJob.swf";
					break;
				case "color":
					strSWF = "DemoColor.swf";
					break;
				}
				strMovieURL = "http://www.tripletriangle.com/" + strSWF;
				
			}
			
			object.innerHTML += AC_FL_RunContentDyn(
				'codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width','802','height','630','id','DemoPreloader',
				'align','top','src',strMovieURL,'loop','false','quality','high','bgcolor','#FFFFFF','name','DemoPreloader',
				'allowscriptaccess','sameDomain','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',strMovieURL,
				'subject', popup.fkind );
		}

	}
	else
	{
		setAlpha(null, closeBox, nNext);
	}
}
	


//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function crossfade(idIn)
{
	//alert("started crossfade to: " + idIn);
	if(gActiveID != null)
	{
		var obj = document.getElementById(gActiveID);
		obj.style.display = 'none';
		obj.style.visibility = 'hidden';
		setAlpha(null, obj, 0);
	}
	
	gActiveID = idIn;
	
	
	var objIn = document.getElementById(idIn);
	if(objIn != null)
	{
		objIn.style.display = 'block';
		objIn.style.visibility = 'visible';
	if(isIE())
	{
		objIn.style.position = 'absolute';
		objIn.style.left = 90;
		objIn.style.top =  0;
	}
	
	gCrossFade = new CrossFadeData(idIn);
	gCrossFade.finterval = setInterval("onCrossFadeCallback()", 50);
	 
	}
	
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function isIE()
{
	return (navigator.appVersion.indexOf("MSIE")!=-1);
}

function isSafari()
{
	return (navigator.appVersion.indexOf("WebKit")!=-1);
}


function isWindows()
{
	return (isIE() || navigator.platform.indexOf("Win") != -1 ||  navigator.platform.indexOf("win") != -1); 	
}


//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function onCrossFadeCallback()
{
	var fade = gCrossFade;
	var objIn   = document.getElementById(fade.fidIn);
	var nNext = incrementAlpha(fade, objIn, 0.05);

	if(Number(nNext) >= 1)
	{
		clearInterval(fade.finterval);
		//alert("finished crossfade to " + fade.fidIn + " opacity is " + objIn.style.opacity + " platform: " + navigator.appVersion);
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function onClosePopup()
{
	var swf = document.getElementById('topcontent');
	if(swf != null)
	{
		swf.style.visibility = 'visible';
	}
	
	var closeBox = document.getElementById('closeBox');
	if(closeBox != null)
	{
		closeBox.style.visibility = 'hidden';
	}
	
	var obj = document.getElementById(gPopupWindow.fid);

	obj.style.display = 'none';
	obj.style.visibility = 'hidden';
	setAlpha(gPopupWindow, obj, 0);
	
	if(gPopupWindow.fnType == DEMO_POPUP)
	{
		if(isIE())
		{
			document.location.reload();
		}
	}
	
	gPopupWindow = null;

}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function hideTopFlash()
{
	var swf = document.getElementById('topcontent');
	if(swf != null)
	{
		swf.style.visibility = 'hidden';
	}
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function onDemo(kind) {
	//if(gPopupWindow != null)
	//	closePopup(gPopupWindow);
				
	gPopupWindow = new PopupWindow('demoPopup', 'demoWindow', 'hiddenWindow', DEMO_POPUP, kind);
	fadeInPopup(gPopupWindow);
}

//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
function onCaseStudy(id) {
	gPopupWindow = new PopupWindow(id, 'caseStudyWindow', 'hiddenWindow', CASESTUDY_POPUP, '');	
	fadeInPopup(gPopupWindow);
}
