/*
+--------------------------------------
|   iWiccle v1.20
|   ==================================
|   by Markus Loponen & Keith Killilea
|   (c) 2009-2010 Bridge Media Ltd.
|   http://www.www.wiccle.com
|   Email: info@wiccle.com
|   ==================================
|   Time: 2010-02-05 | File version: 1.202
+-------------------------------------
|  	Please read the iWiccle license 
|   Available at docs/license.txt
+-------------------------------------
*/







/* Special effects department */


function slideIn(divId, divHeight, divIncr, divTime)
{
	justShow(divId);
		
	if (window.currentSlide)
	{
		document.getElementById(window.currentSlide).style.zIndex=2;
		
		if (window.previousSlide)
			document.getElementById(window.previousSlide).style.zIndex=1;
			
		window.previousSlide = window.currentSlide;
	}
	window.currentSlide = divId;

	document.getElementById(divId).style.zIndex=3;
	
	
	var slideDiv = document.getElementById(divId);
	
	slideDiv.style.height = '1px';
	
	var thisTime = 0;
	

	if (IE) 
	{
		divIncr = divIncr * 3;
		opaSteps = opaSteps / 3;
	}
	
	
	for (i=1; i < divHeight; i=i+divIncr)
	{
		setTimeout('increaseDivHeight(\''+divId+'\', '+i+')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	
}



function slideInLeft(divId, divWidth, divIncr, divTime, opaSteps, opaTime)
{

	if (!opaSteps) var opaSteps = 50;
	if (!opaTime) var opaTime = divTime;
	
	justShow(divId);
		
	if (window.currentSlide)
	{
		document.getElementById(window.currentSlide).style.zIndex=2;
		
		if (window.previousSlide)
			document.getElementById(window.previousSlide).style.zIndex=1;
			
		window.previousSlide = window.currentSlide;
	}
	window.currentSlide = divId;

	var slideDiv = document.getElementById(divId);
	slideDiv.style.width = '1px';
	slideDiv.style.zIndex = '3';
	
	var thisTime = 0;
	

	if (IE) 
	{
		divIncr = divIncr * 3;
		opaSteps = opaSteps / 3;	
	}
	

	
	for (i=1; i < divWidth; i=i+divIncr)
	{
		setTimeout('document.getElementById(\''+divId+'\').style.width=\''+i+'px\'', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	setTimeout('document.getElementById(\''+divId+'\').style.width=\''+divWidth+'px\'', (thisTime+divTime) );
	
	/* Opacity processor */
	
	var thisOpa = 0;
	var thisTime = 0;
	var opaIncr = (100 / opaSteps);
	
	for (i=1; i < opaSteps; i++)
	{
		thisOpa = thisOpa + opaIncr;
	
		if (IE)
		{
			setTimeout('document.getElementById(\''+divId+'\').style.filter=\'alpha(opacity='+thisOpa+')\'', (thisTime+opaTime) );
		}
		else
		{
			var fadeOpa = thisOpa / 100;
			setTimeout('document.getElementById(\''+divId+'\').style.opacity=\''+fadeOpa+'\'', (thisTime+opaTime) );
		}
		
		setTimeout('fadeOpacity('+thisOpa+', \''+divId+'\')', (thisTime+opaTime) );
		thisTime = thisTime + opaTime;
	}
	
	if (IE)
	{
		setTimeout('document.getElementById(\''+divId+'\').style.filter=\'alpha(opacity=100)\'', (thisTime+opaTime) );
	}
	else
	{
		setTimeout('document.getElementById(\''+divId+'\').style.opacity=\'1\'', (thisTime+opaTime) );
	}
	
	
	
}

function cascadeBack(divPrefix, targetShow, showDiv)
{
	var divList = document.getElementsByTagName('div');
	var i = divList.length;
	
	var thisTime = 0;
	var divFadeTime = 20;
	var divTime = 30;
	var divSteps = 50;
	var divIncr = 2;
	
	window.currentCascade='';
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id != showDiv) 
		{
			setTimeout('fadeOpacity(100, \''+divList[i].id+'\')', (thisTime+divTime) );
			thisTime = thisTime + divTime;
		}
	}

}



function fadeOpacity(fade, objId)
{
	if (!fade_obj) var fade_obj = document.getElementById(objId);
	var fadeOpa = fade / 100;
	
	if (IE)
	{
		fade_obj.style.filter = "alpha(opacity=" + fade +")";
	}
	else
	{
		fade_obj.style.opacity = fadeOpa;
	}
}

function fadeOutDiv(divId, divTime, divSteps, divIncr, divOpaStop)
{				
	if (!divSteps) var divSteps = 100;
	if (!divIncr) var divIncr = 1;
	if (!divOpaStop) var divOpaStop = 0;
	
	var thisTime = 0;
	
	for (i=divSteps; i >= 0; i=i-divIncr)
	{
		if (i <= divOpaStop) break;
		setTimeout('fadeOpacity('+i+', \''+divId+'\')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	setTimeout('fadeOpacity('+divOpaStop+', \''+divId+'\')', (thisTime+divTime) );
}



function cascadePopup(divPrefix, targetShow, showDiv)
{
	var divList = document.getElementsByTagName('div');
	var i = divList.length;
	
	var thisTime = 0;
	var divFadeTime = 20;
	var divTime = 30;
	var divSteps = 50;
	var divIncr = 2;
	
	
	if (IE)
	{
	var thisTime = 0;
	var divFadeTime = 10;
	var divTime = 20;
	var divSteps = 20;
	var divIncr = 2;
	
	}
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id != showDiv) 
		{
			setTimeout('fadeOutDiv(\''+divList[i].id+'\', '+divFadeTime+', '+divSteps+', '+divIncr+', 20)', (thisTime+divTime) );
			thisTime = thisTime + divTime;
		}
		else if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id == showDiv) 
		{
			window.currentCascade = targetShow;
		}
	}

	showCascadePopup(divPrefix, targetShow);
}


function showCascadePopup(divPrefix, targetShow)
{
	justShow('wide_pop_window'); 
	showLoader('wide_pop_inner', 'ajax_wide_loader'); 
	submitAjaxGet('wide_pop_inner', 'units&action=load_layout&base=0&layout='+targetShow);
}


function showLargeImage(divId, imageName, imageSize)
{
	
	fadeInBody('out');
	
	putToCenter(500, 500, 'general_ajax');
	document.getElementById('general_ajax').innerHTML='<div style="position: relative; z-index: 300; cursor: crosshair;" id="pop_img_holder" onclick="fadeInBody(\'in\');">'+
	'<div style="width: 640px; margin: auto; text-align: center;">'+
	'<img src="uploads/'+moduleIdent+'/thumbs/s'+imageSize+'_'+imageName+'" alt="" style="cursor: crosshair; border: 15px solid #bbb; padding: 1px; margin-bottom: 10px; background-color: #666;" id="pop_img" onclick="fadeInBody(\'in\');" />';

	

}





function fadeInBody(action)
{
	
	if (action == "out")
	{	
		var body_overlay = document.getElementById('body_overlay');
		justShow('body_overlay');
		body_overlay.style.cursor = 'crosshair';
		body_overlay.style.position = 'absolute';
		
		
		body_overlay.style.height = getViewSize() + 'px';
		
		body_overlay.style.width = '100%';
		body_overlay.style.zIndex = '100';
		body_overlay.style.backgroundColor = '#f5f5f5'; // 'url(black70.png)';
		
		if (IE)		body_overlay.style.filter = 'alpha(opacity=0)';
		else	body_overlay.style.opacity = '0';
		
	
		var thisTime = 0;
		var thisOpa = 0;
		var opaIncr = 2;
		// var opaTime = 10;
		// var opaSteps = 35;


		var opaSteps = 40;
		var opaIncr = 2;
		var opaTime = 3;

		/*for (i=1; i < 80; i=i+2)
		{
			setTimeout('fadeInActual('+i+')', (thisTime+timeOffset) );
			thisTime = thisTime + timeOffset;
		}*/
		
		for (i=1; i <= opaSteps; i++)
		{
			thisOpa = thisOpa + opaIncr;
			thisTime = thisTime + opaTime;
		
			if (IE)
			{
				setTimeout('document.getElementById(\'body_overlay\').style.filter=\'alpha(opacity='+thisOpa+')\'', (thisTime) );
			}
			else
			{
				var fadeOpa = thisOpa / 100;
				setTimeout('document.getElementById(\'body_overlay\').style.opacity=\''+fadeOpa+'\'', (thisTime) );
			}
		}
		
		
	}
	else {
		justHide('body_overlay');
		var body_overlay = document.getElementById('body_overlay');
		body_overlay.style.backgroundImage = '';
		body_overlay.style.cursor = 'default';
		body_overlay.style.zIndex = '-1';
		hideDivsByPrefix('tourbox_');
		document.getElementById('general_ajax').innerHTML='';		
	}

}


function fadeBody(action)
{
	/* DEPRECATED -> REMOVE */
	// if (action == "out")
	// {
		// var body_overlay = document.getElementById('body_overlay');
		// body_overlay.style.backgroundImage = 'url(templates/default/images/black70.png)';
		// body_overlay.style.cursor = 'crosshair';
		// body_overlay.style.position = 'absolute';
		// body_overlay.style.height = '100%';
		// body_overlay.style.width = '100%';
		// body_overlay.style.zIndex = '2';
	// }
	// else {
		// var body_overlay = document.getElementById('body_overlay');
		// body_overlay.style.backgroundImage = '';
		// body_overlay.style.cursor = 'default';
		// body_overlay.style.zIndex = '-1';
	// }

	//winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
}