function load_video(id) {

	$.ajax
	({
	    type: "POST",
	    url: 'ajax/load-video.php?videoid=' + id,
		success: function(msg)
		{
			$('#video-player').html(msg);
			$('#video-player').fadeIn(200);
		},
		error: function(msg)
		{
			$('#video-player').html('Error: ' + msg.responseText);
		}
	});

	$('#pointer').show();
	$('#pointer').animate({
    	top: ($('#video' + id).position().top) - 9
  	}, 700, function() {
    	// Animation complete.
  	});

}


function load_pwp(id) {

	$.ajax
	({
      type: "POST",
      url: 'ajax/playlist-w-permalink.php?videoid=' + id,
      success: function(msg)
		{
			$('#video-playlist').html(msg);
			$('#video-playlist').fadeIn(200);
			$('#pointer').show();
		},
	  
	  error: function(msg)
		{
			$('#video-playlist').html('Error: ' + msg.responseText);
		}
      });	
			     
}

$(function() {

  $("#filter-submit").click(function() {
  		var topcat = $('input:radio[name=topcat]:checked').val();
		var subcat = $('select#subcats').val(); 
		
		var dataString = 'topcat='+ topcat + '&subcat=' + subcat;
		//alert (dataString);return false;
		
		$.ajax({
	      type: "POST",
	      url: 'ajax/playlist.php?' + dataString,
	      data: dataString,
	      success: function(msg)
			{
				$('#video-playlist').html(msg);
				$('#video-playlist').fadeIn(200);
				$('#pointer').hide();
			},
		  
		  error: function(msg)
			{
				$('#video-playlist').html('Error: ' + msg.responseText);
			}
	      });      

	return false;
			
	});
});
			      

$(function() {

  $("input:radio.topcat").click(function() {
  		var topcat = $('input:radio[name=topcat]:checked').val();
		
		var dataString = 'topcat='+ topcat;
		//alert (dataString);return false;
		
		$.ajax({
	      type: "POST",
	      url: 'ajax/subcat-load.php?' + dataString,
	      data: dataString,
	      success: function(msg)
			{
				$('#subcats').html(msg);
				$('#subcats').fadeIn(200);
			},
		  
		  error: function(msg)
			{
				$('#subcats').html('Error: ' + msg.responseText);
			}
	      });      

	//return false;
			
	});
		
});

$(document).ready(function() {
	var hash = location.hash;
		if (undefined != hash){
			var id = location.hash.split("/")[2];
			if (undefined != id) {
				load_pwp(id);
				load_video(id);			  
			}
		}
		
	$("a.video-link:visited").addClass("watched");	
});

