var cookiename = "jookzbabes";

function setCookie()
{
	value = 1;
	var domain = document.domain;
	var exdate = new Date();
	var expiredays = 365;
	exdate.setDate(exdate.getDate() + expiredays);

	//reset previous keyword
	document.cookie = cookiename + "=;path=/;expires=-1;";
	document.cookie = cookiename + "=" + escape( value ) + ";path=/" + ( ( exdate ) ? ";expires=" + exdate.toGMTString() : "" ) + ";";
}
	
function readCookie()
{
	if (document.cookie.length > 0)
	{
		c_start=document.cookie.indexOf(cookiename + "=");
		if (c_start!=-1) {
			c_start = c_start + cookiename.length+1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

function validation() {
	var isVisited = readCookie();
	if(!isVisited) {
		setCookie();
	}
	goto("babes");
}

function goto(page) {
	location.href = "http://www.jookz.com/?tmp=jookz_screensaver_" + page + "&prt=" + prt + "&v=" + currVer;	
}

function replaceCharacters(conversionString,inChar,outChar)
{
  var convertedString = conversionString.split(inChar);
  convertedString = convertedString.join(outChar);
  return convertedString;
}

function showDetail(atag, exeLink, sectName) {
	if(typeof sectName == "undefined") {
		sectName = null;
	} else {
		switch(sectName) {
			case "holidays":
				currID = pref + "-" + holidaysId + "-";
				break;
			case "valentine":
				currID = pref + "-" + holidaysId + "-";
				break;
			case "halloween":
				currID = pref + "-" + holidaysId + "-";
				break;
			case "thanksgiving":
				currID = pref + "-" + holidaysId + "-";
				break;
			case "christmas":
				currID = pref + "-" + holidaysId + "-";
				break;
			case "stpatricks":
				currID = pref + "-" + holidaysId + "-";
				break;
			case "nature":
				currID = pref + "-" + natureId + "-";
				break;
			case "babes":
				currID = pref + "-" + babesId + "-";
				break;
			case "animals":
				currID = pref + "-" + animalsId + "-";
				break;
			case "cars":
				currID = pref + "-" + carsId + "-";
				break;
			case "sports":
				currID = pref + "-" + sportsId + "-";
				break;
			case "bikes":
				currID = pref + "-" + bikesId + "-";
				break;
			case "homepage":
				currID = pref + "-" + homepageId + "-";
				break;
		};
		exePath = 'custom/images/ftpdest/' + installerDir + '/' + currID;
	}

	if($("detailBox")) {
		var tagname = '#'+atag;
		var imagePath = $(tagname + " img:first").attr("src");
		imagePath = replaceCharacters(imagePath, "-tiny", "-large");
		imagePath = replaceCharacters(imagePath, "-thumb", "-large");
		imagePath = replaceCharacters(imagePath, "-mid", "-large");

		gE("dbthumb").style.width = "200px";
		gE("dbthumb").style.padding = "50px";
		gE("dbthumb").src = imgPath + "loading.gif";
		gE("dbH1").innerHTML = "";
		gE("dbDesc").innerHTML = "";
		gE("dbDownloadLink").href = "";

		gE("dbthumb").src = imagePath;
		gE("dbthumb").style.width = "";
		gE("dbthumb").style.padding = "";

		var title = $('#'+atag + " span.title").text();
		var description = $('#'+atag + " span.description").text();
		gE("dbH1").innerHTML = title;
		gE("dbDesc").innerHTML = description;
		gE("dbDownloadLink").href = exePath + exeLink;
		gE(atag).href = tbPath;
		gE(atag).setAttribute("title", title + " Screensaver");
		
		title=null;
		descriptioin=null;
		tagname=null;
		imagePath=null;
	}
}

//Dropdown menu params
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('#submenu').eq(0).css('display', 'block');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('display', 'none');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}


$(document).ready(function(){

	//dropdown menu
	if(document.getElementById("jsddm")) {		
		$('#jsddm > li').bind('mouseover', jsddm_open);
		$('#jsddm > li').bind('mouseout',  jsddm_timer);
		document.onclick = jsddm_close;
	}
	
	//slider
	if(document.getElementById("slider")) {
		$("#slider").easySlider({
			controlsBefore:	'<p id="controls2">',
			controlsAfter:	'</p>',		
			prevId: 'prevBtn2',
			nextId: 'nextBtn2'	
		});			
	}

	$("a[rel*='homepage']").click(function(){
		pageTracker._trackPageview('/screensaver-homepage/'+ $(this).attr('href'));
	 });
	$("a[rel*='animals']").click(function(){
		pageTracker._trackPageview('/screensaver-animals/'+ $(this).attr('href'));
	 });
	$("a[rel*='babes']").click(function(){
		pageTracker._trackPageview('/screensaver-babes/'+ $(this).attr('href'));
	 });	
	$("a[rel*='sports']").click(function(){
		pageTracker._trackPageview('/screensaver-sports/'+ $(this).attr('href'));
	 });	
	$("a[rel*='cars']").click(function(){
		pageTracker._trackPageview('/screensaver-cars/'+ $(this).attr('href'));
	 });	
	$("a[rel*='nature']").click(function(){
		pageTracker._trackPageview('/screensaver-nature/'+ $(this).attr('href'));
	 });	
	$("a[rel*='bikes']").click(function(){
		pageTracker._trackPageview('/screensaver-bikes/'+ $(this).attr('href'));
	 });	
	$("a[rel*='holidays']").click(function(){
		pageTracker._trackPageview('/screensaver-holidays/'+ $(this).attr('href'));
	 });	
	$("a[rel*='valentine']").click(function(){
		pageTracker._trackPageview('/screensaver-valentine/'+ $(this).attr('href'));
	 });	
	$("a[rel*='halloween']").click(function(){
		pageTracker._trackPageview('/screensaver-halloween/'+ $(this).attr('href'));
	 });	
	$("a[rel*='thanksgiving']").click(function(){
		pageTracker._trackPageview('/screensaver-thanksgiving/'+ $(this).attr('href'));
	 });	
	$("a[rel*='christmas']").click(function(){
		pageTracker._trackPageview('/screensaver-christmas/'+ $(this).attr('href'));
	 });	
	$("a[rel*='stpatricks']").click(function(){
		pageTracker._trackPageview('/screensaver-stpatricks/'+ $(this).attr('href'));
	 });	
	$("a[rel*='sorry']").click(function(){
		pageTracker._trackPageview('/screensaver-sorry/'+ $(this).attr('href'));
	 });		
	$("a[rel*='thankyou']").click(function(){
		pageTracker._trackPageview('/screensaver-thankyou/'+ $(this).attr('href'));
	 });		
});