/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('q.5=J(a,b,c){4(8 b!=\'B\'){c=c||{};4(b===p){b=\'\';c.3=-1}2 d=\'\';4(c.3&&(8 c.3==\'s\'||c.3.u)){2 e;4(8 c.3==\'s\'){e=E A();e.z(e.y()+(c.3*w*o*o*v))}n{e=c.3}d=\'; 3=\'+e.u()}2 f=c.7?\'; 7=\'+c.7:\'\';2 g=c.m?\'; m=\'+c.m:\'\';2 h=c.r?\'; r\':\'\';6.5=[a,\'=\',G(b),d,f,g,h].F(\'\')}n{2 j=p;4(6.5&&6.5!=\'\'){2 k=6.5.D(\';\');C(2 i=0;i<k.9;i++){2 l=q.x(k[i]);4(l.t(0,a.9+1)==(a+\'=\')){j=H(l.t(a.9+1));I}}}K j}};',47,47,'||var|expires|if|cookie|document|path|typeof|length|||||||||||||domain|else|60|null|jQuery|secure|number|substring|toUTCString|1000|24|trim|getTime|setTime|Date|undefined|for|split|new|join|encodeURIComponent|decodeURIComponent|break|function|return'.split('|'),0,{}))

var timeoutVar; 
var delayTime = 8000;
		
$(document).ready(function(){
	showHeader();
	homePage();
	ledger();
	langVer();
	//toggleRow();
	initPopup();
	
	
	/* english paypal buttons */
	$(".buy-this-scooter").mouseover(function(){
		$(this).attr("src","buy-this-scooter-hover.png");
	});
	$(".buy-this-scooter").mouseout(function(){
		$(this).attr("src","buy-this-scooter.png");
	});
	$(".buy-now").mouseover(function(){
		$(this).attr("src","buy-now-hover.png");
	});
	$(".buy-now").mouseout(function(){
		$(this).attr("src","buy-now.png");
	});
	
	/* polish paypal buttons */
	$(".kup-ten-skuter").mouseover(function(){
		$(this).attr("src","http://bell-mount-trading.com/pl/kup-ten-skuter-hover.png");
	});
	$(".kup-ten-skuter").mouseout(function(){
		$(this).attr("src","http://bell-mount-trading.com/pl/kup-ten-skuter.png");
	});
	$(".kup-juz-teraz").mouseover(function(){
		$(this).attr("src","http://bell-mount-trading.com/pl/kup-juz-teraz-hover.png");
	});
	$(".kup-juz-teraz").mouseout(function(){
		$(this).attr("src","http://bell-mount-trading.com/pl/kup-juz-teraz.png");
	});
	$(".z").mouseover(function(){
		$(this).attr("src","http://bell-mount-trading.com/pl/zawartosc-koszyka-hover.png");
	});
	$(".z").mouseout(function(){
		$(this).attr("src","http://bell-mount-trading.com/pl/zawartosc-koszyka.png");
	});
	
});

function showHeader(){
	var winName = window.name;
	if(winName == "popup"){
		$("#header").hide();
		$("#nav").hide();
		$(".prodIndex").hide();
		$("#wrapper").addClass("popped");
		$("#main").addClass("popped");
		$("#homeLeftCol").css({width: "812px"});
		$(".price").css({fontSize: "2.5em"});
		$(".details").addClass("popped");
		$(".img").addClass("popped");
		$(".ledger").addClass("popped");
		$("#footer").addClass("popped");
		this.focus();
		$(".buy-this-scooter").click(function(){
			window.onunload = window.resizeTo(1280,768)
		});
		$(".kup-juz-teraz").click(function(){
			window.onunload = window.resizeTo(1280,768)
		});
	}
}

function toggleRow(){
	$(".toggleNextRow").click(function(){
		$(this).next().slideToggle("medium");
		return false;
	});	
}

function langVer(){
	var currentLanguage = $.cookie("bell-mount-trading-language");
	var langIndicator = $("a[rel='lang']").attr("class");

	var url = window.location.href;
	var isEN = url.indexOf(".com/")+5;
	var isPL = url.indexOf(".com/pl/")+8;
	var hrefLength = url.length;
	
	var pageName = url.substring(isEN,hrefLength);
	var PolishPageName = url.substring(isPL,hrefLength);
	
	$("a").focus(function(){
		$(this).blur();
	});
	$("a[rel='lang']").click(function(){
		if(langIndicator == "pl"){
			window.location.replace(url.substring(0,isEN)+"pl/"+pageName);
		}
		if(langIndicator == "en"){
			window.location.replace(url.substring(0,isEN)+PolishPageName);							
		}
		return false;		
	});
}

function ledger(){
	$(".ledger tr:even").addClass("even");
	$(".ledger tr:odd").addClass("odd");	
	$(".ledger tr").mouseover(function(){
		$(this).addClass("over");
	});
	$(".ledger tr").mouseout(function(){
		$(this).removeClass("over");
	});
}

function homePage(){
	clearTimeout(timeoutVar);
	timeoutVar = setTimeout("promo2()",delayTime);
	
	$('a.arrow').click(function(){
		var lnk = $(this).attr("href");
		
		if(lnk == "#marquee1"){
			promo1();			
			
		}
		if(lnk == "#marquee2"){
			promo2();
			
		}
		if(lnk == "#marquee3"){
			promo3();
			
		}
		return false;
	});
	
	$('a.pause').click(function(){
		var lnk = $(this).attr("href");
		
		if(lnk == "#pause"){			
			clearTimeout(timeoutVar);
		}
		return false;
	});
	
	var homeLeftColHeight = $("#homeLeftCol").height();
	var newRightColHeight = homeLeftColHeight-80;
	var RightColHeight = newRightColHeight+"px";
	
	//alert(homeLeftColHeight);
	$("#homeRightCol").css({height:RightColHeight});
	
}

function promo1(){
	$("#marquee1").show();
	$("#marquee2").hide();
	$("#marquee3").hide();
	clearTimeout(timeoutVar);
	timeoutVar = setTimeout("promo2()",delayTime);	
}
function promo2(){
	$("#marquee1").hide();
	$("#marquee2").show();
	$("#marquee3").hide();
	clearTimeout(timeoutVar);
	timeoutVar = setTimeout("promo3()",delayTime);
}
function promo3(){
	$("#marquee1").hide();
	$("#marquee2").hide();
	$("#marquee3").show();
	clearTimeout(timeoutVar);
	timeoutVar = setTimeout("promo1()",delayTime);
}

function initPopup(){
	$(".popup").click(function(){
		popup(this.href);
		return false;
	});
}

function popup(url){
	window.open(url, "popup", "height=640,width=900,resizable=yes,scrollbars=yes");
}