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();





/* SL: html constructor for home page video tabs  */

function startFeedSelector(){

	$$("#video-tabs-1-feed-selector li","#video-tabs-2-feed-selector li").each(function(node){
		var ul = $A(node.getElementsByTagName("ul")).first();
		if(ul != null){
			node.onmouseover = node.onmouseout = function(){
				Element.show(ul);
			}
			node.onmouseout = node.onmouseout = function(){
				Element.hide(ul);
			}
		}
	});

}

function buildVideoTabs(videoArray, tabsId, size, title, categoryType, viewAllURL) {
	
	var total = videoArray.length;
	var videosPerTab = 0;
	if (total > size) total = size;
	
	var videoPageArray = videoArray;
	if (total > 0) {
		var tabsString = '';
		
		tabsString = tabsString + buildVideoTabsFeedSelector(title, tabsId, size);
		
		tabsString = tabsString + '<div class="video-tabs" id="'+ tabsId + '"><ul class="video-tabs-controls">';
		
		for (var i = 0 ;i < Math.ceil(0); i++) {
			tabsString = tabsString + '<li ';
			if (i == 0) tabsString = tabsString + 'class="first"';
			tabsString = tabsString + '><a href="#" onclick="return false"'
			if (i == 0) tabsString = tabsString + ' class="on"';
			tabsString = tabsString + ' onmouseover="showTab(\'' + tabsId + '\',' + i + ')">&bull;</a></li>';
		}
		tabsString = tabsString + '</ul>';
		
		for (var i = 0 ;i < total; i++) {
			if (i == 0) {
				tabsString = tabsString + '<div class="tab-panel" style="display:block">';
			}
			else if ((i != 0)&&(i % videosPerTab == 0)) {
				tabsString = tabsString + '<div class="tab-panel" style="display:none">';
			}
			tabsString = tabsString
			+ '<div class="featured" title="'+ videoPageArray[i].vprop3.replace(/\"/g,'\'\'') + ' - ' + videoPageArray[i].vprop2.replace(/\"/g,'\'\'') +'">';
			if (categoryType != 'hd') {
				tabsString = tabsString	+ '<div class="playThumb">';
			}
			else {
				tabsString = tabsString	+ '<div class="playThumb1080p">';
			}
			tabsString = tabsString	+ '<a target="_parent" href="/' + videoPageArray[i].vprop1 + '?cid=' + videoPageArray[i].vprop7 + '&pid=' + videoPageArray[i].vprop10 + '&category=' + categoryType + '&play=true">'
						+ '<img id="' + tabsId + '_img' + i + '" src="' + videoPageArray[i].vprop11 + '" width="114" height="66" border="0" alt="'+ videoPageArray[i].vprop3.replace(/\"/g,'\'\'') + ' - ' + videoPageArray[i].vprop2.replace(/\"/g,'\'\'') +'" title="'+ videoPageArray[i].vprop3.replace(/\"/g,'\'\'') + ' - ' + videoPageArray[i].vprop2.replace(/\"/g,'\'\'') +'" /></a></div>' 
			+ '<div class="content">'
			+ '<h5 class="showname">' + videoPageArray[i].vprop3.truncate(18) + '</h5>'
			+ '<h5>' + videoPageArray[i].vprop2.truncate(36) + '</h5>'
			+ '<p class="season_episode">';
			/*if (videoPageArray[i].vprop4 != '') tabsString = tabsString + 'Season ' + videoPageArray[i].vprop4.truncate(6);
			if ((videoPageArray[i].vprop4 != '')&&(videoPageArray[i].vprop6 != '')&&(videoPageArray[i].vprop6 != '0')&&(videoPageArray[i].vprop6 != '00')) tabsString = tabsString + ': ';
			if ((videoPageArray[i].vprop6 != '')&&(videoPageArray[i].vprop6 != '0')&&(videoPageArray[i].vprop6 != '00')) tabsString = tabsString + 'Ep. ' + videoPageArray[i].vprop6.truncate(8);*/
			if (videoPageArray[i].vprop14 != '') tabsString = tabsString + 'Original Airdate: ' + videoPageArray[i].vprop14;
			tabsString = tabsString +'</p><p class="duration">' + videoPageArray[i].vprop8 + ' (' + videoPageArray[i].vprop9 + ')</p><div class="clear"></div></div><div class="clear"></div></div>';
			if ((i == total-1)||(i % videosPerTab == videosPerTab-1)) tabsString = tabsString + '</div>';			
		}
	}
	
	if ((viewAllURL!=null)&&(viewAllURL!='')) tabsString = tabsString + '<a href="' + viewAllURL + '" class="btn" style="float:right;margin-top:-2px"><span>View All</span></a><div class="clear"></div>';
	
	tabsString = tabsString + '</div>';
	
	return tabsString;
}

function applyRoundedCornersModules() {
	var modulesArray = new Array;
	modulesArray = $$('div.cbs-mod-rc');
	for (i=0; i<modulesArray.length; i++) {
		$(modulesArray[i]).setStyle({ padding: '9px 16px' })
		$(modulesArray[i]).insert({'before' : '<b class="cbs-mod"><b class="cbs-mod1"><b></b></b><b class="cbs-mod2"><b></b></b><b class="cbs-mod3"></b><b class="cbs-mod4"></b><b class="cbs-mod5"></b></b>'});
		$(modulesArray[i]).insert({'after' : '<b class="cbs-mod"><b class="cbs-mod5"></b><b class="cbs-mod4"></b><b class="cbs-mod3"></b><b class="cbs-mod2"><b></b></b><b class="cbs-mod1"><b></b></b></b>'});
	}
	//$('footer-2').setStyle({ paddingTop: '18px' })
	//$('footer-2').insert({'before' : '<b class="cbs-footer"><b class="cbs-footer1"><b></b></b><b class="cbs-footer2"><b></b></b><b class="cbs-footer3"></b><b class="cbs-footer4"></b><b class="cbs-footer5"></b></b>'});
}

function applyRoundedCornersMain() {
	$('content').setStyle({ padding: '0' });
	$('content').insert({'before' : '<b class="cbs-content"><b class="cbs-content1"><b></b></b><b class="cbs-content2"><b></b></b><b class="cbs-content3"></b><b class="cbs-content4"></b><b class="cbs-content5"></b></b>'});
	$('content').insert({'after' : '<b class="cbs-content"><b class="cbs-content5"></b><b class="cbs-content4"></b><b class="cbs-content3"></b><b class="cbs-content2"><b></b></b><b class="cbs-content1"><b></b></b></b>'});
	
}

function init() {
	//showTimeSlot();
	startFeedSelector();
	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
		}
	}
}

