//Jcval = '22887;;CBS Homepage;;';

/* MG: JSON class constructor - use this one instead of the one in omniture.js */
Array.prototype.jsonClass=function(){
	var x=this;
	var constr=function(){
		var a=arguments; var u;
		for(var i=0;i<x.length;i++){
			if(typeof x[i]=="object"){
				for(var j in x[i]){this[j]=this[j]!=u?this[j]:x[i][j]}
			};
			if(typeof x[i]!="string" || a[i]===u){continue};
			this[x[i]]=a[i];
		}
	};
	var nextProto=false;
	for(var i=0;i<=x.length;i++){
		var a=x[i]||constr;
		if(typeof a=="function"){
			a.prototype=nextProto||a.prototype;
			nextProto=new a();
		}
	};
	constr.addMembers=function(obj){
		for(var i in obj){constr.prototype[i]=obj[i]}
	};
	return constr
};

/* extending members sample: MyClass.addMembers({key:'value'}) */


/* MG: ajax caller */
includeJS=function(url,onload,allowCache){
     url=allowCache?url:url+'&nocache='+Math.random();
     url=url.split('?').length>1?url:url.replace(/\&/,'?');
     onload=typeof onload=="function"?onload:function(){};
     var js=document.createElement('script');
     js.setAttribute('src',url);
     js.addEventListener && function(){js.addEventListener('load',onload,false)}();
     js.onreadystatechange=
          function(){this.readyState=='complete' && onload.call()};
     document.getElementsByTagName('head').item(0).appendChild(js);
};


/* MG: definition for the main video item function */
videoProperties=[
'vprop0','vprop1','vprop2','vprop3','vprop4','vprop5','vprop6','vprop7','vprop8','vprop9','vprop10','vprop11','vprop12','vprop13','vprop14','vprop15',
     {
          vprop0:'empty',
          vprop1:'empty',
          vprop2:'empty',
          vprop3:'empty',
          vprop4:'empty',
          vprop5:'empty',
          vprop6:'empty',
          vprop7:'empty',
          vprop8:'empty',
          vprop9:'empty',
          vprop10:'empty',
          vprop11:'empty',
          vprop12:'empty',
          vprop13:'empty',
          vprop14:'empty',
          vprop15:'empty',
          getVprop0:function(){return this.vprop0},
          getVprop1:function(){return this.vprop1},
          getVprop2:function(){return this.vprop2},
          getVprop3:function(){return this.vprop3},
          getVprop4:function(){return this.vprop4},
          getVprop5:function(){return this.vprop5},
          getVprop6:function(){return this.vprop6},
          getVprop7:function(){return this.vprop7},
          getVprop8:function(){return this.vprop8},
          getVprop9:function(){return this.vprop9},
          getVprop10:function(){return this.vprop10},
          getVprop11:function(){return this.vprop11},
          getVprop12:function(){return this.vprop12},
          getVprop13:function(){return this.vprop13},
          getVprop14:function(){return this.vprop14},
          getVprop15:function(){return this.vprop15}
     }
].jsonClass();

/* MG: translation table
vprop0	empty
vprop1	$video_title1 
vprop2	$video_title2 
vprop3	$video_series_title 
vprop4	$video_season_number
vprop5	$video_description 
vprop6	$video_episode_number 
vprop7	$video_primary_cid 
vprop8	$video_category_type
vprop9	$video_runtime 
vprop10	$video_pid 
vprop11	$video_marker_thumb 
vprop12	$video_marker_full 
vprop13	$ <local> in xml - the current category value for the existing show pages
vprop14	$ <name> in xml - site name in xml, lowercased and trimmed to match the value passed from the left menu
vprop15	empty

*/

/* MG: definition for the main video item function */
videoCategories=[
'name','id','description','local',
     {
          name:'empty',
          id:'empty',
          description:'empty',
          local:'empty',
          getName:function(){return this.name},
          getId:function(){return this.id},
          getDescription:function(){return this.description},
          getLocal:function(){return this.local}
     }
].jsonClass();



function init() {
	showPlayOverlays('well')
}

function showTab(tabsId,panelNum) {
	var tabsArray = new Array;
	tabsArray = $(tabsId).select('ul.video-tabs-controls')[0].select('a');
	var panelsArray = new Array;
	panelsArray = $(tabsId).select('div.tab-panel');
	for (i=0;i<tabsArray.length;i++){
		if ($(tabsArray[i]).hasClassName('on')) {
			$(tabsArray[i]).removeClassName('on')
		} 
	}
	$(tabsArray[panelNum]).addClassName('on')
	
	for (i=0;i<panelsArray.length;i++){
		if ($(panelsArray[i]).getStyle('display') == 'block') {
			$(panelsArray[i]).setStyle({'display' : 'none' })
		} 
	}
	$(panelsArray[panelNum]).setStyle({'display' : 'block'})
}

function showPlayOverlays(containerDiv) {
	var parentDiv = new Array();
	var playThumbsArray = new Array();
	playThumbsArray = $(containerDiv).select('div.playThumb');
	for (i=0;i<playThumbsArray.length;i++) {
		if (playThumbsArray[i].select('a')[0]) {
			//var linkHref = playThumbsArray[i].select('a')[0].readAttribute('href');	
			//var a = new Element('a', { href: linkHref}).addClassName('playBtnOverlay');
			//playThumbsArray[i].insert(a);
			parentDiv[i] = playThumbsArray[i].up();
			parentDiv[i].observe('click', respondToClick)
		}
	}
	
	
	/*var parentDiv1080p = new Array();
	var playThumbsArray1080p = new Array();
	playThumbsArray1080p = $(containerDiv).select('div.playThumb1080p');
	for (i=0;i<playThumbsArray1080p.length;i++) {
		if (playThumbsArray1080p[i].select('a')[0]) {
			var linkHref = playThumbsArray1080p[i].select('a')[0].readAttribute('href');	
			var a = new Element('a', { href: linkHref}).addClassName('playBtnOverlay');
			playThumbsArray1080p[i].insert(a);
			parentDiv1080p[i] = playThumbsArray1080p[i].up();
			parentDiv1080p[i].observe('click', respondToClick)
		}
	}*/
	
}

function respondToClick(event) {
	parent.location.href = this.select('a')[0].readAttribute('href')
}

function calloutGo(elem) {
	if (($(elem).select('a')[0]!=null)&&($(elem).select('a')[0].href!='')) {
		if ($(elem).select('a')[0].target=='_blank') {
			window.open($(elem).select('a')[0].href)
		}
		else {
			document.location = $(elem).select('a')[0].href
		}
		return false;
	}
}


