
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function getWMURL(url){
	location.href= url+"?wm="+getCookie('PPWMID');
}

function renderpopup(){
	$("#maincentre").append('<div class="ddialog"><div id="flashcontainer"></div><div class="dclose"><a href="#"><img src="/images/homepage/dialog_close.png"/></a></div></div>');
	var flashvars = {
		url: "/td/flv/WPT_20sec.flv",
		autoplay: true,
		img: "img2.jgp"
	};
	var params = {
		quality: "high",
		salign: "t",
		menu: "false", 
		wmode: "transparent",
		allowScriptAccess: "sameDomain",
		allowFullScreen: "true"
	};
	var attributes = { };

	swfobject.embedSWF("/td/swf/PPHomePageVideo.swf", "flashcontainer", "100%", "100%", "9.0.0",false, flashvars, params, attributes);
	$(".ddialog .dclose a").unbind('click').click(function(){
		$(".ddialog").hide().remove();
		return false;
	});
	$(".ddialog").show();
}


$(function(){

$(".play_tv_ad a").click(function(){
	renderpopup();
	return false;
});

//plus icon
$(".hp_promo_footer_area:last-child").addClass('plus');
// promotions //

	$('#hp_promo .wrapper .item').hover(function(){$('img,.imagecontent,h2',$(this)).animate({top:'-170px'},{queue:false,duration:300});},function(){$('img,.imagecontent,h2',$(this)).animate({top:'0px'},{queue:false,duration:300});});
	/* old slider
	$('#hp_promo .wrapper .item').hover(function(){$(this).find('img').animate({top:'220px'},{queue:false,duration:300});},function(){$(this).find('img').animate({top:'0'},{queue:false,duration:300});});
	*/

var bmove=178,sign="+="+bmove+"px",itemcount=$(".wrapper-scroll .item").size(),maxitem=itemcount-2,titem=1,selitem=1;
$(".wrapper").scrollTo(0,0);
$(".wrapper").scrollTo('0px',1,{axis:'x'});
$("#hp_promo #arrow_left a,#hp_promo #arrow_right a").hide();
if(itemcount>3){
var promotimer=null;
$("#hp_promo #arrow_right a").show();
$("#hp_promo #arrow_left a").click(function(){
	clearInterval(promotimer);
	promotimer=null;
	if(selitem>1){
		$(".wrapper").scrollTo('-='+bmove+'px',500,{axis:'x'});
		$("#hp_promo #arrow_right a").fadeIn();
		selitem--;
	}
	if(selitem==1)$("#hp_promo #arrow_left a").fadeOut();
	return false;
});
$("#hp_promo #arrow_right a").click(function(){
	clearInterval(promotimer);
	promotimer=null;
	if(selitem<maxitem){
		$(".wrapper").scrollTo('+='+bmove+'px',500,{axis:'x'});
		$("#hp_promo #arrow_left a").fadeIn();
		selitem++;
	}
	if(selitem==maxitem)$("#hp_promo #arrow_right a").fadeOut();
	return false;
});
function scrollpromo(){
	if(selitem==maxitem){titem=-1;sign="-="+bmove+"px";}else if(selitem==1){titem=1;sign="+="+bmove+"px";}
	selitem+=titem;
	if(selitem>1)$("#hp_promo #arrow_left a").fadeIn();
	if(selitem<maxitem)$("#hp_promo #arrow_right a").fadeIn();
	if(selitem==1)$("#hp_promo #arrow_left a").fadeOut();
	if(selitem==maxitem)$("#hp_promo #arrow_right a").fadeOut();
	$(".wrapper").scrollTo(sign,500,{axis:'x'});
}
function setscrollpromo(){promotimer=setInterval(scrollpromo,5000);}
setscrollpromo();

	$("#hp_promo").hover(function(){clearInterval(promotimer);promotimer=null;},function(){setscrollpromo();});
	$("#hp_promo .item").click(function(){document.location.href=$(this).find('a:first').attr('href');});
}

	$("#hp_promo .wrapper-scroll .item:last-child").addClass('last_item');
	$("#hp_promo .wrapper-scroll").css({'width':(bmove*$("#hp_promo .wrapper-scroll .item").size())+'px'});
	/* old slider
	$("#hp_promo .wrapper-scroll .item:last-child").css({'width':(bmove-7)+'px'});
	$("#hp_promo .wrapper-scroll").css({'width':($("#hp_promo .wrapper-scroll .item").width()*$("#hp_promo .wrapper-scroll .item").size()-7)+'px'});
	*/

// tabs //
$("#tabs .tab-2 a").attr("href","#tab-2");
$('#tabs > ul').tabs().tabs('rotate',10000);
$('#tabs').hover(function(){$('#tabs > ul').tabs('rotate',0);},function(){$('#tabs > ul').tabs('rotate',5000);});
$(".scroller").jScrollPane({showArrows:true});

}); // and $(function())

//tournament feed
function hpgetlangid(){var aro={'en':'en_US','fr':'fr_FR'};var lang=document.getElementsByTagName('html')[0].getAttribute('lang');return (aro[lang]==="undefined")?aro['en']:aro[lang];}

function get_hp_tournament_feed(startsat){
$.getJSON('/news/feeds/PokerTourneyFeed_PARTYFR_'+hpgetlangid()+'.js',function(i){
	function sortby(a,b){var order='asc';var x=eval("a.timestamp.toString().toLowerCase()");var y=eval("b.timestamp.toString().toLowerCase()");return(order=='asc')?((x<y)?-1:((x>y)?1:0)):((x>y)?-1:((x<y)?1:0));}
	var mya=i,tmpa=[],y=0;
	for(var x=0;x<mya['Tournaments'].length;x++){
		var t=mya['Tournaments'][x],tl=t['Name'].toLowerCase();
		if(t['IsGuaranteed']=="Y"){tmpa[y]={'timestamp':t['StartDate'],'prize':t['PrizePool'],'limit':t['LimitType']};y++;}
	};
	tmpa.sort(sortby);
	$("#tab-2 .scroller").empty();
	for(var z=0;z<10;z++) $("#tab-2 .scroller").append("<p><a href=\"/tournaments/schedule.htm\"><strong>"+tmpa[z]['prize']+"</strong> Gtd <span>"+tmpa[z]['limit']+"</span> "+startsat+" <span>"+tmpa[z]['timestamp'].split(' ').slice(1,3).join(' ')+"</span></a></p>");
	$('#tab-2 .scroller').jScrollPane({showArrows:true});
});
}
//sifr//
var etelka={src:'/images/etelka.swf'};
sIFR.activate(etelka);
sIFR.replace(etelka,{selector:'#hp_branding_right h1',css:'.sIFR-root{font-size:20px;color:#ffffff;leading:4;}',wmode:'transparent'});
sIFR.replace(etelka,{selector:'#hp_branding_right h2',css:'.sIFR-root{font-size:16px;color:#EDBB27;leading:0;}',wmode:'transparent'});

	sIFR.replace(etelka,{selector:'#hp_promo h2',wmode:'transparent',css:['.sIFR-root { font-size:13px; text-align:center;color:#ffffff; }','.sIFR-root a { color:#ffffff;text-align:center; text-decoration: none; }','.sIFR-root a:hover { text-align:center;color:#ffffff; text-decoration: none; }','.sIFR-root a:visited { text-align:center;color:#ffffff; text-decoration: none; }']});
	/* old slider
	sIFR.replace(etelka,{selector:'#hp_promo h2',wmode:'transparent',css:['.sIFR-root { font-size:16px; color:#EDBB27; }','.sIFR-root a { color:#EDBB27; text-decoration: none; }','.sIFR-root a:hover { color:#EDBB27; text-decoration: none; }','.sIFR-root a:visited { color:#EDBB27; text-decoration: none; }']});
	*/

sIFR.replace(etelka,{selector:'#hp_promo_footer h3',css:'.sIFR-root{font-size:13px;color:#EDBB27;leading:0;cursor:pointer;text-align:center;}',wmode:'transparent',onRelease:function(){jQuery("#panel").slideToggle("slow");jQuery("#panel").toggleClass("active");if(jQuery("#panel").hasClass('active')){$(".hp_promo_footer_area:last-child").addClass('minus');}else{$(".hp_promo_footer_area:last-child").removeClass('minus');};return false;}});
sIFR.replace(etelka,{selector:'#hp_learn .one',css:'.sIFR-root{line-height:48px;font-size:17px;font-style:italic;color:#ffffff;leading:0;cursor:pointer;text-align:left;}',wmode:'transparent',onRelease:function(){location.href=jQuery("#hp_learn a:eq(0)").attr('href');}});
