
// eventListener-functions to be bound to player events
var listener_showchg = function(ev){ player_show_changed(ev); };	// show changed in player
var listener_channelchg = function(ev){ player_channel_changed(ev); };	// show changed in player
var activeCell;
var activeShow;
var channels = new Array();


function player_load(uri) {
	//kyteplayer = new Kyte.Player(uri, { premium: true, producerMode: "never", hideShowsTab:true, layoutMode: "wide" }, "player");
	kyteplayer = new Kyte.Player(uri, { width: 462, height: 260,  wmode: "transparent", p: "3"}, "player");
	kyteplayer.addEventListener("Navigation.ShowChanged", listener_showchg);
	kyteplayer.addEventListener("Navigation.ChannelChanged", listener_channelchg);
	show_play(uri);
}

function player_show_changed(event) {
	activeShow = event.data.uri;
	handle_bgc("activate", activeShow);
	printShowData(activeShow);
	printEmbed(activeShow);
//	initComments = "yes";
//	updateComments(activeShow);
}
function player_channel_changed(event) {
	
}

/*function redir(uri) {
	if (!uri) uri = $('channelSelectionDD').value;
	window.location=""+ uri;
}*/

function show_play(uri) {
	kyteplayer.setURI(uri);
}



function printShows(orderSpec, page) {	
	var searchKey;

	
	if (orderSpec != "search" && page == false) $('searchKey').value = "";
	else if ($('searchKey').value != "") {
		searchKey = $('searchKey').value;
	} 

	var myAjax = new Ajax.Request("kyte/functionsVideo.php", {
		parameters: {
			"action": "printShows",
			"searchKey": searchKey,
			"page": page,
			"orderSpec": orderSpec
		},

			
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("showThumbs").innerHTML = response;
			/////////////////////////////////////////////////////////////////////////////////////
			//Change the filter setStyle colors to match your link color for the Sort buttons.//
			///////////////////////////////////////////////////////////////////////////////////
			$('filter_createdTime-d').setStyle({color: "black"});
			$('filter_totalWatches-d').setStyle({color: "black"});
			$('filter_averageTenths-d').setStyle({color: "black"});
			//////////////////////////////////////////////////////////////////////////////////////////////////
			//Change the color value of this line to change the SELECTED LINK COLOR FOR THE SORT ORDER LINKS//
			//////////////////////////////////////////////////////////////////////////////////////////////////
			if ($('searchKey').value == "") $('filter_'+ orderSpec).setStyle({color:"blue"});
			//////////////////////////////////////////////////////////////////////////////////////////////////
			//Change the color value of this line to change the SELECTED LINK COLOR FOR THE SORT ORDER LINKS//
			//////////////////////////////////////////////////////////////////////////////////////////////////
		},
		onFailure: function() {
			
		}
	});
	
	handle_bgc("activate", activeCell);
}


function printShowsPost(orderSpec, page) {	
	var searchKey;

	
	if (orderSpec != "search" && page == false) $('searchKey').value = "";
	else if ($('searchKey').value != "") {
		searchKey = $('searchKey').value;
	} 

	var myAjax = new Ajax.Request("functionsVideo.php", {
		parameters: {
			"action": "printShowsPost",
			"searchKey": searchKey,
			"page": page,
			"orderSpec": orderSpec
		},

			
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("showThumbsPost").innerHTML = response;
			/////////////////////////////////////////////////////////////////////////////////////
			//Change the filter setStyle colors to match your link color for the Sort buttons.//
			///////////////////////////////////////////////////////////////////////////////////
			$('filter_createdTime-d').setStyle({color: "black"});
			$('filter_totalWatches-d').setStyle({color: "black"});
			$('filter_averageTenths-d').setStyle({color: "black"});
			//////////////////////////////////////////////////////////////////////////////////////////////////
			//Change the color value of this line to change the SELECTED LINK COLOR FOR THE SORT ORDER LINKS//
			//////////////////////////////////////////////////////////////////////////////////////////////////
			if ($('searchKey').value == "") $('filter_'+ orderSpec).setStyle({color:"blue"});
			//////////////////////////////////////////////////////////////////////////////////////////////////
			//Change the color value of this line to change the SELECTED LINK COLOR FOR THE SORT ORDER LINKS//
			//////////////////////////////////////////////////////////////////////////////////////////////////
		},
		onFailure: function() {
			
		}
	});
	
	handle_bgc("activate", activeCell);
}

function printShowData(uri) {
	var myAjax = new Ajax.Request("kyte/functionsVideo.php", {
		parameters: {
			"action": "printShowData",
			"uri": uri
	
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("showData").innerHTML = response;
			$("dynamicShareContent").innerHTML = $("hiddenShareContent").innerHTML;
		},
		onFailure: function() {
			//smth
		}
	});
}
function printEmbed(uri) {
	var myAjax = new Ajax.Request("functionsVideo.php", {
		parameters: {
			"action": "printEmbed",
			"uri": uri
	
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("postText").innerHTML = response;
			$("dynamicShareContent").innerHTML = $("hiddenShareContent").innerHTML;
		},
		onFailure: function() {
			//smth
		}
	});
}



/*var initComments = "yes";
function updateComments(page) {
	var myAjax = new Ajax.Request("kyte/functionsVideo.php", {
		parameters: {
			"action": "updateComments",
			"uri": activeShow,
			"page": page,
			"nick": escape($F("cmdNick")),
			"init": initComments,
			"comment": escape($F("cmdContent"))
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			if (true || response != "error") {
				$('dynamicCSP').innerHTML = response;
				$("cmdContent").value = "";
				//$("cmdNick").value = "";
				initComments = false;
			}
		},
		onFailure: function() {
			//smth
		}
	});
}*/


function handle_bgc(action, element) {
	if (action == "activate") {
		handle_bgc("deactivate", activeCell);
		activeCell = false;
	} else if (element == activeCell && action != "deactivate") return;
	//////////////////////////////////////////////////////////////////////
	//Change the color elements for the SHOW BROWSER ACTIVATED COLORS/////
	//Make sure deavtivate is set to your BG color in the main style.css//
	//////////////////////////////////////////////////////////////////////
	if ($(element)) {
		switch (action) {
			case "onmouseover":
				$(element).setStyle({backgroundColor:"#c7d9e5" });
				$("play_"+element).show();
				break;
			case "onmouseout":
			case "deactivate":
				$(element).setStyle({backgroundColor:"#bfd2df" });
				$("play_"+element).hide();			
				break;
			case "activate":
				$(element).setStyle({backgroundColor:"#d9e9f6" });
				$("play_"+element).hide();	
				activeCell = element;
				break;		
		}
	}
}
	//////////////////////////////////////////////////////////////////////
	//Change the color elements for the SHOW BROWSER ACTIVATED COLORS/////
	//Make sure deavtivate is set to your BG color in the main style.css//
	//////////////////////////////////////////////////////////////////////

function handle_bgcChannel(action, element) {
	if ($(element)) {
		switch (action) {
			case "onmouseover":
				$(element).setStyle({backgroundColor:"#0f0d0e" });
				break;
			case "onmouseout":
				$(element).setStyle({backgroundColor:"#000000" });				
				break;		
		}
	}	
}

/*function copyText(obj) {
	$(obj).select();
	//alert($(obj).value);
}

var chTeaser = 0;
var chTDisable = false;
function browseChannels(direction) {
	if (chTDisable) return;
	
	if (direction) Effect.toggle('ct_'+channels[chTeaser],'appear');
	
	if (direction == "prev") {
		chTeaser = chTeaser-1;
		if (chTeaser < 0) chTeaser = channels.length-1;
	} else if (direction == "next") {
		chTeaser = chTeaser+1;
		if (chTeaser > channels.length-1) chTeaser = 0;
	}
	
	Effect.toggle('ct_'+channels[chTeaser],'appear');
	chTDisable = true;
	setTimeout('enableChannelBrowse()',1000);
}

function enableChannelBrowse() {
	chTDisable = false;
}

function commentsShowAll() {
	Effect.toggle('showMoreComments', 'appear');
	Effect.toggle('hiddenCommentsPart', 'slide');
	//$('showMoreComments').hide();
}

function chg_star(element, star, active) {
	$(element+'_star5').src="star_inact.png";
	$(element+'_star4').src="star_inact.png";
	$(element+'_star3').src="star_inact.png";
	$(element+'_star2').src="star_inact.png";
	$(element+'_star1').src="star_inact.png";		
	
	if (!star) star = parseInt($(element+'_cr').value);
	src = "star_act.png";

	switch(star) {
		case (5):
			$(element+'_star5').src=src;	
		case (4):
			$(element+'_star4').src=src;
		case (3):
			$(element+'_star3').src=src;	
		case (2):
			$(element+'_star2').src=src;	
		case (1):
			$(element+'_star1').src=src;	
	}
}

function vote(uri, uniqueId, vote) {
	var myAjax = new Ajax.Request("kyte/functionsVideo.php", {
		parameters: {
			"action": "receiveVote",
			"uri": activeShow,
			"vote": vote
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$('rating_'+ uniqueId).innerHTML = response;
		},
		onFailure: function() {
			//smth
		}
	});	
}*/

