window.onload = init;

/**************************************************
**This code Will run every time the window loads***
***************************************************/
function init(){
	//CREATE NAVIGATION BUTTON BEHAVIOURS
	
	var navigation = document.getElementById('navigation');
	var main = document.getElementById('main');
	var headerTop = document.getElementById("headerTop");
	
	navigation.onmouseout = function() { 
		var flashNavigation = document["site_navigation"];
		flashNavigation.default_tab();
	}
	main.onmouseover = function() { 
		var flashNavigation = document["site_navigation"];
		flashNavigation.default_tab();
	}
	headerTop.onmouseover = function() { 
		var flashNavigation = document["site_navigation"];
		flashNavigation.default_tab();
	}
	
	var forms = document.getElementById("forms");
	var fields = forms.length - 1; //minus 1 for the submit button
	var err_msg = document.getElementById("error_msg");
	var valid = true;
	forms.onsubmit = function(){
		for(var i=0; i<fields; i++){
			if(forms[i].value == ""){
				err_msg.innerHTML = "<b>*Some fields were not completed.</b><br />";
				forms[i].style.backgroundColor = "#ffffcc";
				valid = false;
			}
			else{
				forms[i].style.backgroundColor = "#ffffff";
				valid = true;
			}
		}
		return valid;
	}	
}
function popup(url,wname,width,height){	
	var w = window.open(url, wname, "width="+width+", height="+height+", status=yes, resizable=no, toolbar=no");
}
/* Channel Selection Scripts */
$(document).ready(function(){

	// For main pages
	$("#videoNav .row").mouseover(function() {$(this).addClass("selected");}).mouseout(function() {$(this).removeClass("selected");});
	$("#videoNav .row:odd").addClass("alt");
	
	// For channel pages
	$("#channelShowNav .row").mouseover(function() {$(this).addClass("selected");}).mouseout(function() {$(this).removeClass("selected");});
	$("#channelShowNav .row:odd").addClass("alt");

	$(".bottomChannelShowNav .row").mouseover(function() {$(this).addClass("selected");}).mouseout(function() {$(this).removeClass("selected");});
	$("#col-1.bottomChannelShowNav .row:even").addClass("alt");
	$("#col-2.bottomChannelShowNav .row:even").addClass("alt");
	$("#col-3.bottomChannelShowNav .row:even").addClass("alt");	
	
	
});



/* FLV Player Controls */


// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
function removeItem(idx) { thisMovie("mpl").removeItem(idx); }


// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};
	

// Custom WTV: loads the given media ID from system and begins playback
function loadPlayer(mid){
	var url = 'video_playlist.php?mid=' + mid;
	loadFile({file:url})
	
	// start playing at the second item in the playlist (first item is title card)
	setTimeout('sendEvent("playitem",1)',500);
	recommendUrl(mid);
}	

function dfChannelSelect(sName, cName, mURL, mid){
	//set global variables
	siteName = sName;
	channelName = cName;
	mediaURL = mURL;
	//call video displays function
	video_display(mid);
	
	initFlashProperties(
	{

		  prog_id : 3513,
		  skin_id : 12,
		  user_id : 182,
		  cust_id : 0,
		  cont_url : [mediaURL],
		  autoplay : 1,
		  still_image : "",
		  cont_title : [channelName],
		  server_url : "",
		  video_type : "",
		  video_id : "" 
	
	 }
	);
}
function submit_comment(){
	var commentForm = document.getElementById("commentForm");
	var commentArea = document.getElementById("commentArea");
	var url = commentForm.action; 
	var comment = commentForm.comment.value;
	var uid = commentForm.uid.value;
	var mid = commentForm.mid.value;
	
	commentForm.submit.disabled=true;
	commentForm.comment.disabled=true;
	commentForm.submit.value = "Comment Posted";
	// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
	//var comment = comment;
	comment = comment.replace(/&/g,"**am**");
	comment = comment.replace(/=/g,"**eq**");
	comment = comment.replace(/\+/g,"**pl**");
	
	var data = "comment="+comment+"&uid="+uid+"&mid="+mid;
	var el = commentArea;
	loadXMLPosDoc(url,data,el);
	
	//alert(commentForm.comment.value);
	//loadXMLPosDoc(url,posData)
}