/**
 * This code was written by Mike Moore November 2009 and is the property of OnNowTV.com Broadcasting Association...Copyright 2008
 * This code MAY NOT BE USED without the expressed written consent of 
 * OnNowTV.com Broadcasting Association - all rights reserved.
 
 * File name:     jwlongtail_controller.js
 * Description:   define common global variables below:
 * History:       
 *   mm/dd/yyyy - Name - brief description of changes              
 */

var player;
var urlLocation = 'http://'+location.hostname;
$(document).ready(function(){
 	$("a.playVideo").click(function () {
 		var videoID = this.id;
 		videoID = videoID.split("_")[1];
 		var objVideo = 'http://hwcdn.net/c5d4y9g9/fms/'+$('#mediaspace').data(videoID).vidFile+'.smil';
 		playVideo(objVideo);
 		hightbckgrnd(videoID);
 		$("#videoNumber span").html($('#mediaspace').data(videoID).vidNumber);
 		$("#videoDescription").html($('#mediaspace').data(videoID).vidDescript);
 		$.post(urlLocation+'/scripts/jq_updatevidplayct.php', { videoid: videoID} );
 	});
 	
 	$("#small_enter_video_box").keypress(function (e)  { 
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
	    	return false;
		}	
	});
 	
 	$("#channelSearchVideo").submit(function () {
 		$.post(urlLocation+"/scripts/jq_videosearch.php",
 				$("#channelSearchVideo").serialize(), 
 				function(data){ 
 					if (data.videoname != 'NoVideo') {
 						var objVideo = 'http://hwcdn.net/c5d4y9g9/fms/'+data.videoname+'.smil';
 						playVideo(objVideo);
 					}
 					$("#videoNumber span").html(data.videonumber);
 					$("#videoDescription").html(data.videodescript);
 					$.post(urlLocation+'/scripts/jq_updatevidplayct.php', { videoid: data.videoid} );
 				}, "json");
 		
 		return false;
 	});
 
 });

function playerReady(obj) {
	player = document.getElementById(obj['id']);
};

function playVideo(videoPath) {
	var obj = {file: videoPath, type:"highwinds"}; 
	player.sendEvent("LOAD", obj);
	player.sendEvent("PLAY","true");
};

function hightbckgrnd(videoid) {
	$( "#videoListUL li").each(function(i) {
		$(this).removeClass("vidlistbckgrndplaying");
	});
	$("#vidlistitem_"+videoid).addClass("vidlistbckgrndplaying");
}