/* 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();


/* MG: main html constructor function for listings */

function videoDisplayEpisodes(count, show, offset, order) {
	if ((order == 'desc')&&(category_type == 'episodes')) videoPageArray.reverse();
	var total = count;
	var page = offset;
	var itemsPerPage = show;
	var itemsToShow = itemsPerPage;
	var number_of_pages = count / itemsPerPage;
	number_of_pages = Math.ceil(number_of_pages);
	if (itemsToShow > total - itemsPerPage * page) itemsToShow = total - itemsPerPage * page;
	
	document.write("<div class=\"clear\"></div>");
	document.write("<div class=\"paginationWrapper\" id=\"pagination1\">");
		if (page!=0) document.write("<a style=\"outline:none\" href=\"list.php?category=" + category_type + "&order=" + order + "&offset=" + (page-1) + "\"><img src=\"/video/images/common/arrow_left.gif\" border=\"0\" alt=\"Previous Page\" title=\"Previous Page\" width=\"22\" height=\"18\" align=\"absmiddle\" style=\"margin-right:5px;\"></a>")
		if (total !=0) document.write("<span class=\"size14 bold\">" + (page+1) + "&nbsp;/&nbsp;" + number_of_pages + "</span>");
		if (page + 1 < number_of_pages) document.write("<a style=\"outline:none\" href=\"list.php?category=" + category_type + "&order=" + order + "&offset=" + (page+1) + "\"><img src=\"/video/images/common/arrow_right.gif\" border=\"0\" alt=\"Next Page\" title=\"Next Page\" width=\"22\" height=\"18\" align=\"absmiddle\" style=\"margin-left:5px;\"></a>")
		else {document.write("<img src=\"/Common/images/spacer.gif\" width=\"27\" height=\"1\" border=\"0\"/>")}
	document.write("</div><div class=\"clear\"></div>");
	

	if (videoPageArray.length > 0) {
		for (var i = 0 + itemsPerPage*page;i < itemsPerPage*page + itemsToShow; i++) {
			if ((i==0)||(i%2 == 0)) document.write("<div class=\"featured\" style=\"margin-right:40px\">")
			else document.write("<div class=\"featured\">");
			document.write("<div class=\"playThumb\"><a href=\"/" + videoPageArray[i].vprop1 + "?cid=" + videoPageArray[i].vprop7 + "&pid=" + videoPageArray[i].vprop10 + "&category=" + category_type + "&play=true\"><img src=\"" + videoPageArray[i].vprop11 + "\" width=\"120\" height=\"90\" border=\"0\" /></a></div><div class=\"content\">");
			document.write("<h5>" + videoPageArray[i].vprop2 + "</h5>");
			document.write("<p class=\"season_episode\">");
			if (videoPageArray[i].vprop4 != '') document.write("Season " + videoPageArray[i].vprop4);
			if (videoPageArray[i].vprop6 != '') document.write(": Ep. " + videoPageArray[i].vprop6);
			document.write("</p><p class=\"duration\">" + videoPageArray[i].vprop8 + " (" + videoPageArray[i].vprop9 + ")</p></div></div>")
			if (i%2 != 0) document.write("<div class=\"verticalSpacer40\"></div>");
		}
	}
	else {
		document.write("<br/><h5>There are currently no videos in this category.<br/><br/>Please, check back later.</h5><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>")
	}
	
	document.write("<div class=\"clear\"></div><div class=\"paginationWrapper\" id=\"pagination2\">");
		if (page!=0) document.write("<a style=\"outline:none\" href=\"list.php?category=" + category_type + "&order=" + order + "&offset=" + (page-1) + "\"><img src=\"/video/images/common/arrow_left.gif\" border=\"0\" alt=\"Previous Page\" title=\"Previous Page\" width=\"22\" height=\"18\" align=\"absmiddle\" style=\"margin-right:5px;\"></a>")
		if (total !=0) document.write("<span class=\"size14 bold\">" + (page+1) + "&nbsp;/&nbsp;" + number_of_pages + "</span>");
		if (page + 1 < number_of_pages) document.write("<a style=\"outline:none\" href=\"list.php?category=" + category_type + "&order=" + order + "&offset=" + (page+1) + "\"><img src=\"/video/images/common/arrow_right.gif\" border=\"0\" alt=\"Next Page\" title=\"Next Page\" width=\"22\" height=\"18\" align=\"absmiddle\" style=\"margin-left:5px;\"></a>")
		else {document.write("<img src=\"/Common/images/spacer.gif\" width=\"27\" height=\"1\" border=\"0\"/>")}
	document.write("</div>");
}

function showClipInfo(videoArray,count,pid) {
	var videoPageArray = videoArray;
	var videoCount = count;
	var videoId = pid;
	for (var i = 0;i<videoCount; i++) {
		if ((videoId == videoPageArray[i].vprop10)||(videoId == videoPageArray[i].vprop15)) {
				document.write('<h5>' + videoPageArray[i].vprop3 + ' - ' + videoPageArray[i].vprop2 + '</h5>');
				document.write('<p class="duration"><b>' + videoPageArray[i].vprop9 + '</b></p>');
				//document.write('<p>' + videoPageArray[i].vprop2 + '</p>');
				document.write('<p>' + videoPageArray[i].vprop5 + '</p>');

		}
	}
}

function getProp(videoArray,count,pid, prop) {
	var videoPageArray = videoArray;
	var videoCount = count;
	var videoId = pid;
	var propNum = prop;
	for (var i = 0;i<videoCount; i++) {
		if ((videoId == videoPageArray[i].vprop10)||(videoId == videoPageArray[i].vprop15)) {
			var propContent = videoPageArray[i][propNum]
			return propContent
		}
	}
}
