/*
$(document).ready(function () {
  // hide all ULs inside LI.drawer except the first one
  $('#library-menu ul li.sub-cat ul').hide(); 
  
  $('#library-menu ul li.sub-cat').click(function () {
    // hide the currently visible drawer contents
    $('#library-menu ul li.sub-cat ul:visible').slideToggle('fast');
    
    // remove the open class from the currently open drawer
    $('#library-menu ul li.open').removeClass('open');
    
    // show the associated drawer content to 'this' (this is the current li element)
    // since the drawer content is the next element after the clicked li, we find
    // it and show it using this:
    $(this).find('ul').slideToggle('fast');
    
    // set a class indicating on the li that the drawer is open
    $(this).addClass('open');
  });
});
*/


$(document).ready(function () {
  // hide all ULs inside LI.drawer except the first one
  $('#library-menu ul li.sub-cat ul').hide();
  
  $('#library-menu ul li.sub-cat').click(function () {
  	
	if ($(this).hasClass('closed')) {
	
		// hide the currently visible drawer contents
		$('#library-menu ul li.sub-cat ul:visible').slideToggle('fast');
		
		// remove the open class from the currently open drawer
		$('#library-menu ul li.open').addClass('closed');
		$('#library-menu ul li.closed').removeClass('open');
		
		// show the associated drawer content to 'this' (this is the current li element)
		// since the drawer content is the next element after the clicked li, we find
		// it and show it using this:
		$(this).find('ul').slideToggle('fast');
		
		// set a class indicating on the li that the drawer is open
		$(this).addClass('open');
		$(this).removeClass('closed');
	}
	
  });
  
  $('#library-menu ul li ul li').click(function () {
  	if ($(this).hasClass('active') == false) {
		
		$('#library-menu ul li ul li').removeClass('active');
		$(this).addClass('active');
		
	}
  });
  
  // $("ul.tabs").tabs();
  
});


function getNewVideo(alias,id) { 
	ajaxThisPlayer("/ajax/getVideoID.cfm?id=" + id);
	ajaxIt("/ajax/getVideo.cfm?id=" + id + "&sid=" + Math.random(), "video_info");
	ajaxIt("/ajax/getCatPageLine.cfm?alias=" + alias + "&sid=" + Math.random(), "category_header_text");
	
	//alert(document.getElementById(alias + "_" + id).href);
	
	// PUSH UPDATED ANALYTICS
	// PUSH NEW ADS
	//load_GA_AD("Header_Leaderboard");
	//document.getElementById("footer_leaderboard").innerHTML = GA_googleFillSlot("Footer_Leaderboard");
	//document.getElementById("category_300").innerHTML = GA_googleFillSlot("Category_300");

	
	
}



// AJAX Initializer
function createRequestObject() { 
	var req;
	if(window.XMLHttpRequest){ // Firefox, Safari, Opera...
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) { // Internet Explorer 5+
			req = new ActiveXObject("Microsoft.XMLHTTP");
	} return req;
}  
    		
// Make the XMLHttpRequest object  

 
function ajaxIt(url,position) {  
	var http = createRequestObject(); 
	//document.getElementById(position).innerHTML = "loading ... ";  
	//alert(url);
	http.open('get', url+'&sid='+Math.random());  
	http.onreadystatechange = handleResponse;  
	http.send(null);  
	function handleResponse() {
		if(http.readyState == 4 && http.status == 200){ // Text returned FROM the PHP script 
			var response = http.responseText;
			if(response) { // UPDATE ajaxTest content  
				//alert(response);
				document.getElementById(position).innerHTML = response;  
			}
		}
	}
} 

function ajaxThisPlayer(url) {  
	var http = createRequestObject(); 
	http.open('get', url+'&sid='+Math.random());  
	http.onreadystatechange = handleResponse;  
	http.send(null);  
	function handleResponse() {
		if(http.readyState == 4 && http.status == 200){ // Text returned FROM the PHP script 
			var response = http.responseText;
			if(response) { // UPDATE ajaxTest content  
				//alert(response);
				
				var response_array=response.split("/");
				
				DelvePlayer.doPause();
				//alert(response_array[0] + ' AND ' + response_array[1]);
				//DelvePlayer.doLoadChannelAndSetMedia(response_array[0],response_array[1],true);
				DelvePlayer.doLoadMedia(response_array[1], true);
			}
		}
	}
} 


function delvePlayerCallback(id, eventName, data) {
  switch (eventName) {
    case 'onMediaComplete':
      DelvePlayer.doPause();
      doSet
  }
}

/*
 
function ajaxThisPlayer_old(url) {  
	var http = createRequestObject(); 
	http.open('get', url+'&sid='+Math.random());  
	http.onreadystatechange = handleResponse;  
	http.send(null);  
	function handleResponse() {
		if(http.readyState == 4 && http.status == 200){ // Text returned FROM the PHP script 
			var response = http.responseText;
			if(response) { // UPDATE ajaxTest content  
				//alert(response);
				DelvePlayer.doPause();
				DelvePlayer.doLoadChannelAndSetMedia('6953c81d5325449d82b312641a139028',response,true);
			}
		}
	}
} 
*/


function validate_email(field,alerttxt) {
	with (field) { 
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {alert(alerttxt);return false;}
		else { return true; }
	}
}
function validate_form(thisform,fieldtovalidate)
{
	with (thisform)
	{
	if (validate_email(fieldtovalidate,"Not a valid e-mail address!")==false)
	  { return false;}
	}
}

function popUp1(message) {

var x = 20;
var y = 20;

	var windowparam = "width=" + 500 + ",height=" + 625 + ",scrollbars=yes,menubar=no,left="+x+",top="+y+",screenX="+x+",screenY="+y;
	popwin = window.open(message, "popwin", windowparam)
	popwin.opener = self;
	popwin.focus()
}

function popUp2(message) {

var x = 20;
var y = 20;

	var windowparam = "width=" + 500 + ",height=" + 625 + ",scrollbars=no,menubar=no,left="+x+",top="+y+",screenX="+x+",screenY="+y;
	popwin = window.open(message, "popwin", windowparam)
	popwin.opener = self;
	popwin.focus()
}


function embed_openbtn() { 
	document.getElementById("embedcode_textarea").style.display="block";
}
function embed_closebtn() { 
	document.getElementById("embedcode_textarea").style.display="none";
}




/* sharethis variables */
var addthis_pub="bienpstv";
var addthis_options='favorites, digg, delicious, facebook, myspace, google, reddit, live, stumbleupon, twitter, more';
var addthis_brand = "PlaySportsTV";
var addthis_header_color = "#ffffff";
var addthis_header_background = "#614279";


