var bottomAdsTiming;
var numberOfSet = 0;
var picsPerSet = 0;
var currentSet = 0;

function showVariableContent(divID, url) {
	jQuery(""+divID+"").load(url, function() {
		jQuery(""+divID+"").slideDown("slow");
	});
}

function showInfoForm() {
	setPopUpCenter("submitInfo");
	jQuery("#submitInfo").fadeIn("slow");
}

function hideInfoForm() {
	jQuery("#submitInfo").fadeOut("fast");
}

function setPopUpCenter(id) {
	   var intH = 0, intW = 0;

	    if(self.innerHeight) {
	       intH = window.innerHeight;
	       intW = window.innerWidth;
	    }
	    else {
		if(document.documentElement && document.documentElement.clientHeight) {
		    intH = document.documentElement.clientHeight;
		    intW = document.documentElement.clientWidth;
		}
		else {
		    if(document.body) {
			intH = document.body.clientHeight;
			intW = document.body.clientWidth;
		    }
		}
	    }

			intH = document.body.clientHeight;
			var intWindow = document.documentElement.clientHeight;
			var intScroll = document.documentElement.scrollTop;
	var xCenter = (intW/2)-320;
	xCenter = parseInt(xCenter);
	var yCenter = intScroll + (intWindow/2) - 150;
	yCenter = parseInt(yCenter);

	document.getElementById(id).style.top= yCenter + 'px';
	document.getElementById(id).style.left= xCenter + 'px';
}

function ajaxConnectToProcess() {
	var theName = document.getElementById('theName').value;
	var theEmail = document.getElementById('theEmail').value;
	var theCode = document.getElementById('ticketCode').value;
	jQuery("#ajaxValue").load("processCow.php", {name : theName , email : theEmail, ticketCode:theCode}, function() {
		if(document.getElementById('ajaxValue').innerHTML=="pass"){
			window.print();
		}
		else{
			alert(document.getElementById('ajaxValue').innerHTML);
		}

	});
	return false;
}

function showSecretButton() {
	var rand_no = Math.random();
	rand_no = rand_no * 100;
	rand_no = Math.ceil(rand_no);
	var randomGET = "randomNo="+rand_no;
	jQuery("#ipexist").load("checkIP.php",randomGET,  function() {
		if(document.getElementById('ipexist').innerHTML=="iie") {
			var basicContent = '<div id="hiddenButton"><a href="secretPinkCow.php"><img src="img\/thescene\/pinkcow\/secret-button.gif" \/><\/a><\/div>';
			jQuery("#thepinkcowplace").append(basicContent);
		}
	});
}

function initBottomAds(setNo,setPics,setCurrent) {
	numberOfSet = setNo;
	picsPerSet = setPics;
	currentSet = setCurrent;
	initDisplaySets();
}

function fadeInTheImageSeq(theID, theMax) {
	if(theID<theMax) {
		jQuery(".bottom-ads #placeholder_"+theID).fadeIn("normal", function() {
			var tempID = theID;
			var tempMax = theMax;
			tempID = tempID+1;
			fadeInTheImageSeq(tempID,tempMax);
		});
	}
	else {
		bottomAdsTiming = setTimeout("runTheSwitch()", 8000);
	}
}

function runTheSwitch() {
	switchSets(currentSet);
}

function initDisplaySets() {
	var dSet=0;
	for (dSet=0;dSet<picsPerSet;dSet=dSet+1){
		var tempHTML = jQuery("#set_0 .set_item"+dSet).html();
		jQuery(".bottom-ads #placeholder_"+dSet).html(tempHTML);
	}//end of loop
	fadeInTheImageSeq(0,picsPerSet);
}

function switchSets(setNumber) {
	var dSet=0;
	currentSet = setNumber+1;
	if(currentSet==numberOfSet) {
		currentSet = 0;
	}

	fadeInTheImageSeq2(0,picsPerSet);
}

function fadeInTheImageSeq2(theID, theMax) {
	if(theID<theMax) {

		jQuery(".bottom-ads #placeholder_"+theID).css("display","none");
		var tempHTML = jQuery("#set_"+  currentSet+" .set_item"+theID).html();
		jQuery(".bottom-ads #placeholder_"+theID).html(tempHTML);

		jQuery(".bottom-ads #placeholder_"+theID).fadeIn("normal", function() {
			var tempID = theID;
			var tempMax = theMax;
			tempID = tempID+1;
			fadeInTheImageSeq2(tempID,tempMax);
		});
	}
	else {
		bottomAdsTiming = setTimeout("runTheSwitch()", 8000);
	}
}

function setTheSession() {
	jQuery("#checkTheSession").load("setSession.php", function() {
		window.location = "scene_promo.html";
	});
}

function checkTheSession() {
	jQuery("#theSession").load("checkSession.php", function() {
			if(jQuery("#theSession").html()=="visible") {
				jQuery("#sub-navi-pinkcow").html("Pink Cow");
			}
	});
}

function attachTheCow() {
	jQuery(".showCow").hover(
	function() {
		jQuery("#showCow").css("display","none");
		jQuery("#showCow").fadeIn("fast");
	}, function() {
		jQuery("#showCow").css("display","none");
	}
	);
}
