﻿/*
---------------------------------------------------------------+
									+
		X	M	A	G	I	C		+
									+
---------------------------------------------------------------+
*/
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}('(2(){3(A g=="s"||!g){4 f=W.p;4 g=f.k={};4 $=f.$=f.k};g.X=2(a){5 6.B(a)?6.B(a):l};g.Y=2(a,b){b=b?b:6;5 b.C(a)?b.C(a):l};g.Z=2(b,c){8=\'8\';10(b){t\'D\':6.D=2(a){3(a){m(c+\'(8)\')}o{m(c+\'(p.8)\')}};u;t\'E\':6.E=2(a){3(a){m(c+\'(8)\')}o{m(c+\'(p.8)\')}};u;t\'F\':6.F=2(a){3(a){m(c+\'(8)\')}o{m(c+\'(p.8)\')}};u;11:12\'13 14 s\';5 l};5 r};g.15=2(e){5 g.v(e).16};g.v=2(e){3(e.G){5 e.G}o{5 e.v}};g.17=2(a,b){4 c=a.7.w(" ");x(n=0;n<c.9;n++){3(c[n]==b)5 l};a.7=a.7?(a.7+\' \'+b):b;5 r};g.18=2(a,b){4 c=a.7.w(" ");a.7=\'\';4 d=l;x(n=0;n<c.9;n++){3(c[n]==b){d=r}o{a.7=a.7?(a.7+\' \'+c[n]):c[n]}};5 d};g.19=2(a,b){4 c=a.7.w(" ");x(n=0;n<c.9;n++){3(c[n]==b){5 r}};5 l}})();(2(){3(A i=="s"||!i){4 i=p.q={}};i.H=2(a,b,c,d,e,f,g){4 h=a+"="+I(b)+((c)?"; J="+c.1a():"")+((d)?"; K="+d:"")+((e)?"; L="+e:"")+((f)?"; 1b":"");3(!g||(a+"="+I(b)).9<=1c){6.j=h}o 3(1d("1e 1f 1g 1h 1i 1j 1k\\!")){6.j=h}};i.y=2(a){4 b=a+"=";4 c=6.j.M(b);3(c==-1)5 1l;4 d=6.j.M(";",c+b.9);3(d==-1)d=6.j.9;5 1m(6.j.1n(c+b.9,d))};i.N=2(a,b,c){3(i.y(a)){6.j=a+"="+((b)?"; K="+b:"")+((c)?"; L="+c:"")+"; J=1o, O-1p-1q P:P:O 1r"}};i.Q=2(a){4 b=R S(0);4 c=b.z();3(c>0)a.T(a.z()-c)};i.U=2(a){4 b=R S();Q(b);b.T(b.z()+a*1s*V*V*1t);5 b}})();k.1u=q.y;k.1v=q.H;k.1w=q.N;k.1x=q.U;',62,96,'||function|if|var|return|document|className|event|length||||||||||cookie|Xmagic|false|eval||else|window|cookieEngine|true|undefined|case|break|target|split|for|getCookie|getTime|typeof|getElementById|getElementsByTagName|onclick|onmouseover|onmouseout|srcElement|setCookie|escape|expires|path|domain|indexOf|deleteCookie|01|00|fixDate|new|Date|setTime|cookieDate|60|this|hasId|hasTagName|listenEvent|switch|default|throw|eventName|is|targetName|tagName|addClass|removeClass|hasClass|toGMTString|secure|4000|confirm|Cookie|exceeds|4KB|and|will|be|cut|null|unescape|substring|Thu|Jan|70|GMT|24|1000|readCookie|addCookie|removeCookie|expire'.split('|'),0,{}));
 

var autoPlay = false;
var eventLock = false;
var playerPosition = false;

function positionListener(obj) { 
	playerPosition = obj.position; 
}

var xhr = false;
function AjaxCall(url){
	if(player.sendEvent) {
		player.sendEvent('STOP');
	}
	if(xhr) {
		xhr.abort();
		xhr = false;
	}
	
	eventLock = true;
	var htmlDoc;
	try {
		htmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (exception) {
	}
	if(htmlDoc) {
	} else {
		htmlDoc = new XMLHttpRequest();
	}
	xhr = htmlDoc;
	
	htmlDoc.open("GET", url, false);
	htmlDoc.send(null);
	
	var doc = htmlDoc.responseText;
	htmlDoc = doc;
	
	eventLock = false;
	xhr = false;
	
	if(player.sendEvent) {
		player.sendEvent('STOP');
	}
	
	return htmlDoc;
	
	
}

var currentPropertyValue, limit, lock, target;
var container = $.hasId('video-entries');

function slideUp() {window.clearInterval(lock);
	currentPropertyValue = container.style.marginTop ? parseInt(container.style.marginTop) : 0;
	target = limit =   parseInt(container.parentNode.offsetHeight) - parseInt(container.offsetHeight) - currentPropertyValue ;
	lock = window.setInterval(up, 25);
	return true;
}

function slideDown() {window.clearInterval(lock);
	limit = 0;
	target = 0;
	currentPropertyValue = container.style.marginTop ? parseInt(container.style.marginTop) : 0;
	lock = window.setInterval(down, 25);
	return true;
}

(function(){

window.up = function() {
	if(limit < -0.3) {		
		container.style.marginTop = (currentPropertyValue - 8) + 'px'; 
		currentPropertyValue = currentPropertyValue - 8;
		limit = target - currentPropertyValue;
	} else {
		window.clearInterval(lock);
	}
}


window.down = function() {
	if(currentPropertyValue < -0.3) {
		container.style.marginTop = (currentPropertyValue + 8) + 'px'; 
		currentPropertyValue = currentPropertyValue + 8;
		limit = target - currentPropertyValue;
	} else {
		window.clearInterval(lock);
	}
}
})();





function slideLeft() {window.clearInterval(lock);
	currentPropertyValue = container.style.marginLeft ? parseInt(container.style.marginLeft) : 0;
	target = limit = parseInt(container.parentNode.offsetWidth) - parseInt(container.offsetWidth) + (parseInt(container.offsetWidth)/10000);
	lock = window.setInterval(left, 25);
	return true;
}

function slideRight() {window.clearInterval(lock);
	limit = 0;
	target = 0;
	currentPropertyValue = container.style.marginLeft ? parseInt(container.style.marginLeft) : 0;
	lock = window.setInterval(right, 25);
	
	return true;
}

(function(){

window.left = function() {
	if(currentPropertyValue > (parseInt(container.parentNode.offsetWidth) - parseInt(container.offsetWidth))) {
		container.style.marginLeft = (currentPropertyValue - 12) + 'px'; 
		currentPropertyValue = currentPropertyValue - 12;
		limit = target - currentPropertyValue;
	} else {
		window.clearInterval(lock);
	}
}


window.right = function() {
	if(currentPropertyValue < 0) {
		container.style.marginLeft = (currentPropertyValue + 12) + 'px'; 
		currentPropertyValue = currentPropertyValue + 12;
		limit = target - currentPropertyValue;
	} else {
		window.clearInterval(lock);
		container.style.marginLeft = 0;
	}
}
})();







function entryClick(e) {
	if($.hasId('selectedEntry')) {
		$.hasId('selectedEntry').style.backgroundImage = 'url(/images/bg_video.gif)';
		$.hasTagName('img', $.hasId('selectedEntry'))[1].src = '/images/play.gif';
		$.hasId('selectedEntry').style.color = '#666';
		$.hasId('selectedEntry').id = 'hh';
	}
	var ele = $.target(e) || e;
	if(ele.tagName != 'LI') {
		ele = ele.parentNode;
	}
	ele.id = 'selectedEntry';
	$.hasTagName('img', ele)[1].src = '/images/play_selected.gif';
	ele.style.backgroundImage = 'url(/images/bg_video_hover.gif)';
	ele.style.color = 'black';
}

function entryHover(e) {
	var ele = $.target(e);
	if(ele.tagName != 'LI') {
		ele = ele.parentNode;
	}
	if(ele.id != 'selectedEntry' && ele.tagName == 'LI') {
		$.hasTagName('img', ele)[1].src = '/images/play_hover.gif';
	}
}
function entryOut(e) {
	var ele = $.target(e);
	if(ele.tagName != 'LI') {
		ele = ele.parentNode;
	}
	if(ele.id != 'selectedEntry' && ele.tagName == 'LI') {
		$.hasTagName('img', ele)[1].src = '/images/play.gif';
	}
}

(function(){
	var carousel = window.carousel = {};
	carousel.setup =  {
		direction: 'horizontal',
		elementTagName: 'li',
		container: 'horizontal-carousel', /*Can be either obj or id*/
		buttonForward: '',
		buttonReverse: ''
	};
	var property, limit, currentPropertyValue;
	


	carousel.slider = function (direction, step){

		if(carousel.setup.direction == 'vertical') {
			property = 'marginTop'; limit =  parseInt(container.parentNode.offsetHeight) - parseInt(container.offsetHeight);
		} else { 
			property = 'marginLeft'; limit = parseInt(container.parentNode.offsetWidth) - parseInt(container.offsetWidth);
		}

		currentPropertyValue = container.style[property] ? parseInt(container.style[property]) : 0;

		if(direction == 'up') {
			step = '-' + step;
			limit = '-' + limit;
			if((currentPropertyValue + step) > limit && (currentPropertyValue > limit)) {
				limit = limit - currentPropertyValue;
				return carousel.slider.moveUp(limit, step);
			} else {
				window.clearInterval(lock);
				container.style[property] = limit + 'px';
				return false;
			}
		} else if ((currentPropertyValue + step) < 0 && (currentPropertyValue < 0)) {
			limit = 0 - currentPropertyValue;
		} else {
			container.style[property] = limit + 'px';
			window.clearInterval(lock);
			return false;
		}
		
		//container.style[property] = currentPropertyValue + parseInt(step) + 'px';
			
	}
	
	
	carousel.slider.moveUp = function (limit, step){		
		for(currentPropertyValue; parseInt(container.style[property]) > limit;) {
			container.style[property] = (parseInt(container.style[property]) - 1) + 'px';
			limit = limit - parseInt(container.style[property]);
		}
		return true;
	}
	
})();

function jet(direction) {
	container = $.hasId('video-entries');
	slideUp();
	return true;
}
function jetD(direction) {
	container = $.hasId('video-entries');container = $.hasId('video-entries');
	slideDown();
	return true;
}
function jetC(direction) {
	window.clearInterval(lock);
	window.clearInterval(lock);
}

function jetR(direction) {
	container = $.hasId('horizontal-carousel');
	slideRight();
	return true;
}
function jetL(direction) {
	container = $.hasId('horizontal-carousel');
	slideLeft();
	return true;
}

function hide(i,o) {

	if(parseInt(blockObj[i].style.height) > 0) {

	 	blockObj[i].style.height = ((parseInt(blockObj[i].style.height) - (parseInt(blockObj[i].style.height)/splide)) + 'px');

		if(hideIntvl) {

		} else {

			hideIntvl = setInterval("hide("+i+")", speedTime);

			iHide = i;

		}

	} else {

		clearInterval(hideIntvl);

		hideIntvl = 0;

		iHide = 10000;

		titleObj[i].className = 'textOnOff bgOff';

	}

}





var videoMarket;
var videoCategory = 'TV Shows';
function toggleState(ele,market) {
	videoMarket = market;
	$.addCookie('playerMarket', videoMarket);
	$.addCookie('playerCategory', videoCategory);
	if(!eventLock) {
		var tabs = $.hasId('video-market-tabs').getElementsByTagName('li');
		for(var n = 0; n < tabs.length; n++) {
			tabs[n].className = '';
		}
		ele.parentNode.className = 'selected';
		$.hasId('video-entries').innerHTML = '<img src="../images/loading.gif" alt="Loading..." />';
		$.hasId('video-entries').innerHTML = AjaxCall('/ywtv1/videoList.php?market=' + market + '&category=' + videoCategory  + '&cache=' + new Date());
		loadAdvertisements(market, 'TV Shows');
	}
}

function selectCategory(ele, category) {
	videoCategory = category;
	$.addCookie('playerMarket', videoMarket);
	$.addCookie('playerCategory', videoCategory);
	if(!eventLock) {
		var tabs = $.hasId('tab-box1').getElementsByTagName('li');
		for(var n = 0; n < tabs.length; n++) {
			tabs[n].className = '';
		}
		ele.parentNode.className = 'selected';
		$.hasId('video-entries').innerHTML = '<img src="../images/loading.gif" alt="Loading..." />';
		$.hasId('video-entries').innerHTML = AjaxCall('/ywtv1/videoList.php?market=' + videoMarket + '&category=' + category + '&cache=' + new Date());
		loadAdvertisements(videoMarket, videoCategory);
	}
	
}

function loadNationalVideo() {
	if(!eventLock) {
		$.hasId('horizontal-carousel').innerHTML = '<img src="../images/loading.gif" alt="Loading..." />';
		$.hasId('horizontal-carousel').innerHTML = AjaxCall('/ywtv1/national_videoList.php?cache=' + new Date());
		$.hasTagName('li', $.hasId('horizontal-carousel')).length;
		$.hasId('horizontal-carousel').style.width = ($.hasTagName('li', $.hasId('horizontal-carousel')).length * 144) + 'px';
	}
}
var advId = new Array();
var advSrc = new Array();
var advLink = new Array();
function loadAdvertisements(market, category) {
	if(market == 'National') {
		advNational = true;
	}
	advId = new Array();
	advSrc = new Array();
	advLink = new Array();
	advNo = 0;
	var advScript = AjaxCall('/ywtv1/advertisementList.php?market=' + market + '&category=' + category + '&cache=' + new Date());
	eval(advScript);
	if($.hasTagName('li', $.hasId('video-entries'))[0]) {
		if(document.createEvent) {
		  var evt = document.createEvent("MouseEvents");
		  evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		  var cb = $.hasTagName('li', $.hasId('video-entries'))[0]; 
		  var canceled = !cb.dispatchEvent(evt);
		} else {
			$.hasTagName('li', $.hasId('video-entries'))[0].fireEvent("onclick");
		}
	} else {
		$.hasId('video-entries').innerHTML = 'Sorry, there is no video available to show in this category.'
	}
	jetD('down');
}