/* 	
	
	What are you looking at?
	
	All programming property of Plyweb.  
	Don't steal!  Innovate!
	
*/

var imagePath='images/themes/';
var imagePrefix='image_';
var imageCount=10;
var imageExt='.jpg';
var effect = [
			[254,34,41,227,127,231,143,9,56,339],
			[21,145,87,175,240,68,73,132,232,198],
			[15,235,340,175,78,265,190,120,321,169],
			[111,126,269,226,307,173,3,183,305,107],
			[211,81,157,35,158,169,286,330,201,320],
			[281,180,309,63,321,54,285,7,214,63]
		];

var imageDefaultspeed=(1);
var imageDefaulteffect=0;
var effectGenOn=1;
var switchMultiplier=0.54;
var effectGenLow=0/switchMultiplier;
var effectGenHigh=185/switchMultiplier;
var effectBlackTime=250/switchMultiplier;
var viewportLoadTime=80/switchMultiplier;
function switch_image(themeName,queryOptions) {	
	if(effectGenOn!=1) { var randEffect=randInt(effect.length,0); }
	if(!queryOptions) queryOptions='';
	if(window.setTimerId)
		for(iT=0;iT<window.setTimerId.length;iT++)
			clearTimeout(window.setTimerId[iT]);
	else
		window.setTimerId = new Array();
	if(window.setTimerId2)
		for(iT2=0;iT2<window.setTimerId2.length;iT2++)
			clearTimeout(window.setTimerId2[iT2]);
	else
		window.setTimerId2 = new Array();
	if(window.setTimerId3) clearTimeout(window.setTimerId3);
	bTarget=document.getElementById("baseTarget").target;
	window.setTimerId3=setTimeout("viewSwitch('"+bTarget+"','"+themeName+"','"+queryOptions+"');",viewportLoadTime);
	if(window.themeName!=themeName) {
		window.statusS='';
		if(effectGenOn!=1) {
			if(!randEffect) randEffect=0;
			for(i=0;i<effect[randEffect].length;i++) {
				window.setTimerId[i]=setTimeout( "doSwitch( "+i+",'"+themeName+"');",(effect[randEffect][i]+effectBlackTime) );
				
				window.statusS=window.statusS+"image_"+(i+1)+":"+Math.round(effect[randEffect][i]);
				window.statusS=window.statusS+" / "+Math.round(effect[randEffect][i]+effectBlackTime)+"\n";
				
				if(effectBlackTime) {
					window.setTimerId2[i]=setTimeout( "blackOut("+i+");", effect[randEffect][i]);
				}
			}
		} else {
			for(j=0;j<imageCount;j++) {
				imageTiming=((Math.floor(Math.random() * ((effectGenHigh) - effectGenLow)) + effectGenLow));
				window.setTimerId[j]=setTimeout( "doSwitch("+j+",'"+themeName+"');",imageTiming+ effectBlackTime);
				
				window.statusS=window.statusS+"image_"+(j+1)+":"+Math.round(imageTiming);
				window.statusS=window.statusS+" / "+Math.round(imageTiming+effectBlackTime)+"\n";
				
				if(effectBlackTime) {
					window.setTimerId2[j]=setTimeout( "blackOut("+j+");", imageTiming);
				}
			}
		}
	}
	window.themeName=themeName;
}
function doSwitch(i,themeName) {
	imageId=document.getElementById(imagePrefix+(i+1));
	imageId.style.backgroundImage='url('+imagePath+themeName+'/'+imagePrefix+(i+1)+imageExt+')';	
}
function blackOut(i) {
	imageId=document.getElementById(imagePrefix+(i+1));
	imageId.style.backgroundImage='url('+imagePath+'black/'+imagePrefix+(i+1)+imageExt+')';
}
function viewSwitch(target,themeName,queryOptions) {
	document.getElementById(target).src="viewport.php?view="+themeName+"&queryOptions="+queryOptions;
}
function randInt(low,high) {
	output=(((Math.floor(Math.random() * ( high - low ) ) ) + low ) -1);
	return output;
}