/**
 * 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;
var vid = "";
var playlist_id = "";

$(document).ready(function(){	
	//window closing, do something!
	//$(window).bind('onbeforeunload', function() {
	
	
	//geo location data
	var city = $('input#city').val();
	var state = $('input#state').val();
	var zip = $('input#zip').val();
	var country = $('input#country').val();
	
	//load video documents
	loadDocuments(playlist_id);
	
	$('a#tn_'+playlist_id).parent().addClass('cur_item');
	
	/************ ACTA rollover ****************/
	$(document).delegate('a.playVideoCTA', 'hover', function(e)
	{
		e.preventDefault();
		$(this).parent().siblings('div.cta_desc').slideToggle('fast');
	});
	
	/*************** Video Controller rollovers *******************/
	$('li.btn a img').hover(function()
	{
		var num = $(this).attr('alt');
		$(this).attr('src', '/graphics/btns/'+num+'_over.png');
	},
	function() {
		var num = $(this).attr('alt');
		$(this).attr('src', '/graphics/btns/'+num+'.png');
	});
	//click-to-action buttons load
	if(playlist_id != "")
	{
		var video_list = mediaspace['cta'][0];
		var has_cta = mediaspace[playlist_id][0];
		loadClickToActions(playlist_id, video_list);
		
		if(has_cta == 0)
		{
			$('a.open-mcta').hide();
		}
		
	}
 	
 	$('input.searchtxt').click(function()
 	{
 		if( $(this).val() == 'Search')
 		{
 			$(this).val('');
 		}
 	});
 	$('select#sort').change(function()
 	{
 		$('#submit-sort').submit();
 	});
 	//replay video
 	$('a#replay_video').click(function(e) {
 		e.preventDefault();
 		//alert( so );
 		//so.play();
 		$('div#mcta-outer').hide('slow');
 		//var player = $('div#mediaspace');
 		//player.sendEvent('PLAY');
		//newVideoLoaded();
 	});
 	
 	$('a#play_next_video, a.video-next').click(function (e) {
 		e.preventDefault();
 		//alert(vid);
 		
 		var vlist = mediaspace['cta'][0];
 		var varr = vlist.split(',');
 		var del = varr.pop();
 		var lnth = varr.length;
 		var videoID = 0;
 		if(playlist_id == varr[lnth-1])
 		{
 			videoID = varr[0];
 		}
 		else
 		{
 			//var indx = varr.indexOf(vid);
 			//videoID = varr[indx+1];
 			
 			for(var i=0; i<varr.length; i++)
 			{
 				if(varr[i] == playlist_id)
 				{
 					videoID = varr[i+1];
 					break;
 				}
 			}
 		}
 		
 		has_cta = mediaspace[videoID][0]; //$('#mediaspace').data(videoID).vidCTA;
 		$.ajax({
				  url: urlLocation+'/scripts/video_list.php',
				  data: 'vid_id='+videoID,
				  type: 'POST',
				  dataType: 'json',
				  success: function(data) {
					if (data.vidFile != 'NoVideo')
					{
						type = data.vidType;
				 		var objVideo = data.vidFile;
				 		//alert(objVideo);
				 		//has_cta = data.vidCTA; // check if new video is CTA anchor
				 		//set the 0-1-5 variables
						videoFileName = data.vidOrigName;
						playlist_id = videoID;
				 		playVideo(objVideo, type);
				 		hightbckgrnd(videoID);
				 		$('p#cur_chan_num').text(data.vidNumber);
				 		$("#videoNumber span").empty().html(data.vidNumber);
				 		$("div#videoDescription p#vid-desc").empty().html(data.vidDescript);
				
						//load CTA buttons
						loadClickToActions(videoID, video_list);
						
						//the overlay on video player
						//if anchor video, then change the image to current anchor
						if(has_cta == 1)
						{
						
							$('a.open-mcta').show();
				 		}
				 		else
				 		{
				 			$('a.open-mcta').hide();
				 		}
				 		
				 		vid = videoID;
						
 					}
 					}
 				});
 		$('div#mcta-outer').hide('slow');
 	});
 	
 	$('a.video-prev').click(function (e) {
 		e.preventDefault();
 		//alert(vid);
 		
 		var vlist = mediaspace['cta'][0]; //$('#mediaspace').data('cta').video_list;
 		var varr = vlist.split(',');
 		var del = varr.pop();
 		var lnth = varr.length;
 		var videoID = 0;
 		if(playlist_id == varr[0])
 		{
 			videoID = varr[lnth-1];
 		}
 		else
 		{
 			//var indx = varr.indexOf(vid);
 			//videoID = varr[indx+1];
 			
 			for(var i=0; i<varr.length; i++)
 			{
 				if(varr[i] == playlist_id)
 				{
 					videoID = varr[i-1];
 					break;
 				}
 			}
 		}
 		
 		has_cta = mediaspace[videoID][0]; //$('#mediaspace').data(videoID).vidCTA;
 		$.ajax({
				  url: urlLocation+'/scripts/video_list.php',
				  data: 'vid_id='+videoID,
				  type: 'POST',
				  dataType: 'json',
				  success: function(data) {
					if (data.vidFile != 'NoVideo')
					{
						type = data.vidType;
				 		var objVideo = data.vidFile;
				 		//alert(objVideo);
				 		//has_cta = data.vidCTA; // check if new video is CTA anchor
				 		//set the 0-1-5 variables
						videoFileName = data.vidOrigName;
						playlist_id = videoID;
				 		playVideo(objVideo, type);
				 		hightbckgrnd(videoID);
				 		$('p#cur_chan_num').text(data.vidNumber);
				 		$("#videoNumber span").empty().html(data.vidNumber);
				 		$("div#videoDescription p#vid-desc").empty().html(data.vidDescript);
				
						//load CTA buttons
						loadClickToActions(videoID, video_list);
						
						//the overlay on video player
						//if anchor video, then change the image to current anchor
						if(has_cta == 1)
						{
						
							$('a.open-mcta').show();
				 		}
				 		else
				 		{
				 			$('a.open-mcta').hide();
				 		}
				 		
				 		vid = videoID;
						
 					}
 					}
 				});
 		$('div#mcta-outer').hide('slow');
 	});
 	
 	$("a.playVideo").click(function (e) {
 		
 		var video_list = mediaspace['cta'][0]; //$('#mediaspace').data('cta').video_list;
		e.preventDefault();
		//update video 0-1-5 record
		//updateVideoPlay(city, state, zip, country);
		// hide the MCTA buttons
		$('div#mcta-outer').hide('slow');
		
		//variables
		var data = null;
		var new_type;
 		var videoID = $(this).attr('id');
 		videoID = videoID.split("_")[1];
 		has_cta = mediaspace[videoID][0]; //$('#mediaspace').data(videoID).vidCTA;
 		
 		$.ajax({
				  url: urlLocation+'/scripts/video_list.php',
				  data: 'vid_id='+videoID,
				  type: 'POST',
				  dataType: 'json',
				  success: function(data) {
					if (data.vidFile != 'NoVideo')
					{
						type = data.vidType;
				 		var objVideo = data.vidFile;
				 		//alert(objVideo);
				 		//has_cta = data.vidCTA; // check if new video is CTA anchor
				 		//set the 0-1-5 variables
						videoFileName = data.vidOrigName;
						playlist_id = videoID;
				 		playVideo(objVideo, type);
				 		hightbckgrnd(videoID);
				 		$('p#cur_chan_num').text(data.vidNumber);
				 		$("#videoNumber span").empty().html(data.vidNumber);
				 		$("div#videoDescription p#vid-desc").empty().html(data.vidDescript);
				
						//load CTA buttons
						loadClickToActions(videoID, video_list);
						
						//the overlay on video player
						//if anchor video, then change the image to current anchor
					
						if(has_cta == 1)
						{
							
							$('a.open-mcta').show();
				 		}
				 		else
				 		{
				 			$('a.open-mcta').hide();
				 		}
				 		vid = videoID;
						
 					}
 					}
 				});
  		//alert(data);
		
 	});
 	
 	$(document).delegate('a.playVideo2', 'click', function (e) {
 		var video_list = mediaspace['cta'][0]; //$('#mediaspace').data('cta').video_list;
		e.preventDefault();
		
		//update video 0-1-5 record
		//updateVideoPlay(city, state, zip, country);
		// hide the MCTA buttons
		$('div#mcta-outer').hide('slow');
		
		//variables
		var data = null;
		var new_type;
 		var videoID = $(this).attr('id');
 		videoID = videoID.split("_")[1];
 		has_cta = mediaspace[videoID][0]; //$('#mediaspace').data(videoID).vidCTA;
 		
 		
 		$.ajax({
				  url: urlLocation+'/scripts/video_list.php',
				  data: 'vid_id='+videoID,
				  type: 'POST',
				  dataType: 'json',
				  success: function(data) {
					if (data.vidFile != 'NoVideo')
					{
						type = data.vidType;
				 		var objVideo = data.vidFile;
				 		//alert(objVideo);
				 		//has_cta = data.vidCTA; // check if new video is CTA anchor
				 		//set the 0-1-5 variables
						videoFileName = data.vidOrigName;
						playlist_id = videoID;	
				 		playVideo(objVideo, type);
				 		hightbckgrnd(videoID);
				 		$('p#cur_chan_num').text(data.vidNumber);
				 		$("#videoNumber span").empty().html(data.vidNumber);
				 		$("div#videoDescription p#vid-desc").empty().html(data.vidDescript);
				
						//load CTA buttons
						loadClickToActions(videoID, video_list);
						
						//the overlay on video player
						//if anchor video, then change the image to current anchor
					
						if(has_cta == 1)
						{
							
							$('a.open-mcta').show();
				 		}
				 		else
				 		{
				 			$('a.open-mcta').hide();
				 		}
				 		vid = videoID;
						
 					}
 					}
 				});
  		//alert(data);
		
 	});
 	
 	$(document).delegate('a.main-vid', 'click', function (e) {
 		var video_list = mediaspace['cta'][0]; //$('#mediaspace').data('cta').video_list;
		e.preventDefault();
		$(this).slideUp('slow');
		$('div#mcta-outer').hide('slow');
		
		//variables
		var data = null;
		var new_type;
 		var videoID = $(this).attr('id');
 		videoID = videoID.split("_")[1];
 		has_cta = mediaspace[videoID][0]; //$('#mediaspace').data(videoID).vidCTA;
 		
 		
 		$.ajax({
				  url: urlLocation+'/scripts/video_list.php',
				  data: 'vid_id='+videoID,
				  type: 'POST',
				  dataType: 'json',
				  success: function(data) {
					if (data.vidFile != 'NoVideo')
					{
						type = data.vidType;
				 		var objVideo = data.vidFile;
				 		//alert(objVideo);
				 		//has_cta = data.vidCTA; // check if new video is CTA anchor
				 		//set the 0-1-5 variables
						videoFileName = data.vidOrigName;
						playlist_id = videoID;
				 		playVideo(objVideo, type);
				 		hightbckgrnd(videoID);
				 		$('p#cur_chan_num').text(data.vidNumber);
				 		$("#videoNumber span").empty().html(data.vidNumber);
				 		$("div#videoDescription p#vid-desc").empty().html(data.vidDescript);
				
						//load CTA buttons
						loadClickToActions(videoID, video_list);
						
						//the overlay on video player
						//if anchor video, then change the image to current anchor
					
						if(has_cta == 1)
						{
							$('a.open-mcta').show();
				 		}
				 		
				 		else
				 		{
				 			$('a.open-mcta').hide();
				 		}
				 		
				 		vid = videoID;
						
 					}
 					}
 				});
  		//alert(data);
		
 	});
 	
	 $(document).delegate('a.playVideoCTA', 'click', function (event) {
		//alert('Hey!');
		event.preventDefault();
		//updateVideoPlay(city, state, zip, country);
		$('div#mcta-outer').hide('slow');
		var data;
 		var videoID = $(this).attr('id');
 		videoID = videoID.split("_")[1];
 		var video_list = mediaspace['cta'][0]; //$('#mediaspace').data('cta').video_list;
 		vid = videoID;
 		
 		$.ajax({
			  url: urlLocation+'/scripts/video_list.php',
			  data: 'vid_id='+videoID,
			  type: 'POST',
			  dataType: 'json',
			  success: function(data) {
				if (data.vidFile != 'NoVideo') 
				{
					type = data.vidType;
			 		var objVideo = data.vidFile;
					videoFileName = data.vidOrigName;
					playlist_id = videoID;	
			 		playVideo(objVideo, type);
			 		hightbckgrnd(playlist_id);
			 		$('p#cur_chan_num').text(data.vidNumber);
			 		$("#videoNumber span").empty().html(data.vidNumber);
			 		$("div#videoDescription p#vid-desc").empty().html(data.vidDescript);
				}},
				error: function(a, b, c)
				{
					alert('Big trouble!');
				}
		});
		
		if( $(this).hasClass('next-video') )
 		{
 			//load CTA buttons
			loadClickToActions(videoID, video_list);
 		}
		if(has_cta == 1)
 		{
 			$('a.main-vid').slideDown('slow');
 		}
	 		
 		else
 		{
 			//$('a.open-mcta').hide();
 		}
 		$('a.playVideoCTA').each(function() {
 			if( $(this).hasClass('cur_btn') )
 			{
 				$(this).removeClass('cur_btn').addClass('visited');
 			}
 		});

 		$('a.playVideoCTA').removeClass('cur_btn');
 		$(this).removeClass('visited').addClass('cur_btn');
 	});
 	
 	
 	$("#small_enter_video_box, #channel_input").keypress(function (e)  { 
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
	    	return false;
		}
		else if(e.which == 8)
		{
			return false;
		}
	});
 	
 	$("#channel_input").keypress(function (e)  { 
		if(e.which == 8)
		{
			return false;
		}
	});
	
 	$("#channelSearchVideo").submit(function () {
 		$.post(urlLocation+"/scripts/jq_videosearch.php",
 				$("#channelSearchVideo").serialize(), 
 				function(data){ 
 					if (data.videoname != 'NoVideo') {
 						videoFileName = data.videoOrigName;
 						var objVideo = data.videoname;
						var type = data.videotype;
						playlist_id = data.videoid;
 						playVideo(objVideo, type);
 					}
 					hightbckgrnd(playlist_id);
 					$('p#cur_chan_num').text(data.vidnumber);
 					$("#videoNumber span").html(data.videonumber);
 					$("#videoDescription").html(data.videodescript);
 					//$.post(urlLocation+'/scripts/jq_updatevidplayct.php', { videoid: data.videoid} );
 				}, "json");
 		
 		return false;
 	});

$("#submit-search").click(function (e) {
			$('div#mcta-outer').hide('slow');
			var srchNetwork = $("#srchNetwork").val();
			var srchChannel = $("#srchChannel").val();
			var srchVideo = $("#small_enter_video_box").val();
			//alert('Hi there!');
			$.ajax({
				  url: urlLocation+'/scripts/jq_videosearch.php',
				  data: 'srchNetwork='+srchNetwork+'&srchChannel='+srchChannel+'&srchVideo='+srchVideo,
				  type: 'POST',
				  dataType: 'json',
				  success: function(data) {
				
					//data = jQuery.parseJSON(data);
					
					//alert(data.videoname);
					//alert(data2);
					if (data.videoname != 'NoVideo') {
						
						//update video 0-1-5 record
						//updateVideoPlay(city, state, zip, country);
						videoFileName = data.videoOrigName;
 						var objVideo = data.videoname;
						var type = data.videotype;
						playlist_id = data.videoid;
						
 						playVideo(objVideo, type);
 						hightbckgrnd(playlist_id);
 						$('p#cur_chan_num').text(data.vidNumber);
	 					$("#videoNumber span").html(data.videonumber);
	 					$("#videoDescription").html(data.videodescript);
 					}
				  }
				  
				});
			
			e.preventDefault();
	});

$('input#vid_input').click(function(e) {
	if($(this).val() == "# Here")
	{
		$(this).val('');
	}
});

$('input#vid_input').keypress(function(e) {
   //alert(e.which);
    $('div#mcta-outer').hide('slow');
    
	if((e.which >=47 && e.which <= 57) || e.which == 8)
	{
		if($(this).val() == "# Here")
	    {
	    	$(this).val('');
	    }
	}
	else if(e.which == 13)
	{
		if($(this).val() != "")
		{
			searchAndPlayVideo();
			e.preventDefault();
		}
	}
	else
	{
		e.preventDefault();	
	}
});

$("#new_search").click(function (e) {	
			$('div#mcta-outer').hide('slow');
			searchAndPlayVideo();
			e.preventDefault();
	});


$(window).unload(function() {
	//updateVideoPlay(city, state, zip, country);
});

//Channel Friends Pop up
$('a#channel_friends').click(function(e)
{
	$('#friend_list').slideDown();
	e.preventDefault();
});

$('a#channel_friends').click(function(e)
{
	e.preventDefault();
});

//modal view
    $('a#view-more').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#friend_list').slideUp();
        //Get the A tag
        var id = $(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(1000);   
        $('#mask').fadeTo("slow",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000);
     
    });
     
     //modal view
    $('a#view-more-api').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#friend_list').slideUp();
        //Get the A tag
        var id = $(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = 1000;
        var maskWidth = 640;
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(1000);   
        $('#mask').fadeTo("slow",0.8); 
     
        //Get the window height and width
        var winH = 1000;
        var winW = 640;
               
        //Set the popup window to center
        $(id).css('top', 100);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000);
     
    });
    
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });    
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });

		

$('a.close_btn').click(function(e)
{
	$('#friend_list').slideUp();
	e.preventDefault();
});


// video previous and next buttons
$('a.video-prev').click(function (e)
{
	//alert(vid);
	e.preventDefault();
});
$('a.video-next').click(function (e)
{
	//alert(vid);
	e.preventDefault();
});

// Main CTA actions
$('a.open-mcta').live('mousedown', function(e)
{
	e.preventDefault();
	$('div#overlay').slideUp();
	$('div#mcta-outer').slideDown('slow');
	$('div#mcta-container').slideDown('slow');
	//alert('Hey');
});

$('a.cta-action').live('mousedown', function(e)
{
	e.preventDefault();
	$(this).addClass('active');
	$(this).siblings('div.mcta-content').slideDown('slow');
});
$('div#mcta-outer a.close').live('mousedown', function(e){
	$('div#mcta-outer').hide('slow');
	$('div#overlay').slideUp();
	$('div#mcta-container').slideUp();
	e.preventDefault();
});

$('div#mcta-outer input#send_request').live('mousedown', function() {
	var uname = $('input#uname').val();
	var email = $('input#co_email').val();
	var uemail = $('input#uemail').val();
	var uphone = $('input#uphone').val();
	var umsg = $('#umsg').val();
	
	if(uname== "" || uemail == "" || uphone == "" || umsg == "")
	{
		$('p#error').slideDown('slow');
	}
	else
	{
		$.ajax({
		  url: 'library/ajax_calls.php',
		  data: 'task=send_request&uname='+uname+'&email='+email+'&uemail='+uemail+'&uphone='+uphone+'&umsg='+umsg,
		  type: 'POST',
		  success: function(data) {
		  	  $('p#error').slideUp('fast');
			  $('p#success').slideDown('slow');
			  $('div#mcta-outer input[type=text], div#mcta-outer textarea').val('');
		  }
		});
	}
});

/*
 * 
 * Actions and events for the video list accordion
 *
 */
	$('ul.olist li a.tab').click(function(e)
	{
		e.preventDefault();
		if( $(this).hasClass('cur-tab'))
		{
			$(this).removeClass('cur-tab');
			$(this).siblings('ul.ilist').slideUp('slow');
		}
		else
		{
			$(this).addClass('cur-tab');
			$(this).siblings('ul.ilist').slideDown('slow');
		}
	});
	
/* Video search */
$('#stext').click(function()
 	{
 		if( $(this).val() == 'Search')
 		{
 			$(this).val('');
 		}
 	});

$('#search_video').submit(function(e)
{
	e.preventDefault();
	var chanid = $("#vid_userid").val();
	var stext = $("#stext").val();
	$('div#search-results').slideUp('slow');
	if(stext != "")
	{
		$.ajax({
		  url: 'library/search_videos.php',
		  data: 'chanid='+chanid+'&stext='+stext,
		  type: 'POST',
		  success: function(data) {
		  	$('div#search-results').slideDown('slow').html(data);
		  	//alert(data);
		  }
		});
	}
});

//Video Search Close 
$(document).delegate('a#close-search', 'click', function (e)
{
	$('div#search-results').slideUp();
	e.preventDefault();
});

// Tool tip for document 
/*
$(document).delegate('div#vid_docs a', 'mouseover', function()
{
	var title = $(this).attr('rel');
	var pos = $(this).position();
	$(this).siblings('span').css('left', pos.left+40);
	$(this).siblings('span').css('top', pos.top+7);
	$(this).siblings('span').text(title).show();
	//$(this).parent().append('<span>'+title+'</span>');
});
*/
$(document).delegate('div#vid_docs a', 'mouseout', function()
{
	$(this).siblings('span').hide();
});

});


/*
function playerReady(obj) {
	player = document.getElementById(obj['id']);
	alert('New video');
};
*/
	
function searchAndPlayVideo()
{
	var srchNetwork = $("#srchNetwork").val();
	var srchChannel = $("#srchChannel").val();
	var srchVideo = $("#vid_input").val();
	$('#vid_input').val('');
	//alert(srchVideo);
	$.ajax({
		  url: urlLocation+'/scripts/jq_videosearch.php',
		  data: 'srchNetwork='+srchNetwork+'&srchChannel='+srchChannel+'&srchVideo='+srchVideo,
		  type: 'POST',
		  dataType: 'json',
		  success: function(data) {
			if (data.videoname != 'NoVideo') {
				
				//update video 0-1-5 record -- get geo-location data
				var city = $('input#city').val();
				var state = $('input#state').val();
				var zip = $('input#zip').val();
				var country = $('input#country').val();
				//updateVideoPlay(city, state, zip, country);
				var objVideo = data.videoname;
				var type = data.videotype;
				playlist_id = data.videoid;
				playVideo(objVideo, type);
				hightbckgrnd(playlist_id);
				$('p#cur_chan_num').text(data.videonumber);
				$("#videoNumber span").html(data.videonumber);
				$("#videoDescription").html(data.videodescript);
				//$.post(urlLocation+'/scripts/jq_updatevidplayct.php', { videoid: data.videoid} );			
		  }},
		  error: function(jqXHR, a, b)
		  {
		  	alert(a+" | "+b);
		  }
		});
}

function loadClickToActions(playlist_id, vidlist) {
	//load MCTA buttons if available
	loadMainCTA(playlist_id);
	//load main CTA text
	loadMainCTAText(playlist_id);

	$.ajax({
	  url: 'library/video_cta.php',
	  data: 'vid='+playlist_id+'&video_list='+vidlist,
	  type: 'POST',
	  success: function(data) {
	  	$('div#cta_container').empty().append(data); 
	  }
	});
}

function loadMainCTA(vid) {
	$.ajax({
	  url: 'library/load_mcta.php',
	  data: 'vid='+vid,
	  type: 'POST',
	  success: function(data) {
		  //alert(data);
		  if(data != "nocta")
		  {
			$('div#mcta-container').html(data); 
		  }
	  }
	});
}

function loadDocuments(vid) {
	$.ajax({
	  url: 'library/load_docs.php',
	  data: 'vid='+vid,
	  type: 'POST',
	  success: function(data) {
		  if(data != "nocta")
		  {
			$('div#vid_docs').slideDown('slow').html(data); 
		  }
		  else
		  {
		  	$('div#vid_docs').slideUp('slow');
		  }
	  }
	});
}

function loadMainCTAText(vid) {
	$.ajax({
	  url: 'library/load_mcta_text.php',
	  data: 'vid='+vid,
	  type: 'POST',
	  success: function(data) {
		  //alert(data);
		  if(data != "nocta")
		  {
			$('a#open-mcta').html(data); 
		  }
	  }
	});
}
function playVideo(videoPath, type) {
	var obj = {file: videoPath, type:type};
	var cur_user_id = $('input#cur_user_id').val();
	jwplayer().load(obj);
	jwplayer().play(true); 
	vfilename = videoPath;
	vtype = type;
	newVideoLoaded(cur_user_id, playlist_id);
	loadDocuments(playlist_id);
}

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