// JavaScript Document

$(document).ready(function(){
	
	var loadMsg = '<table><tr><td align="center" valign="middle"><br /><img id="move" src="images/loadingAnimation.gif" /><br />&nbsp;</td></tr></table>';
	//Bind Scroller
	$('#mycarous').jcarousel({
        vertical: true,
        scroll: 1
    });
    $('#mycarousel').jcarousel();
	
	//Search Category
	$('.searchCat').click(function(){
		var sid = $(this).attr("rel");
		if(oldId != '')
		{
			$('#'+oldId).removeClass('redlnks').addClass("blklnks");
		}
		oldId = $(this).attr("id");
		$(this).removeClass('blklnks').addClass("redlnks");
		$("#msgTitle").html($(this).text());
		//Show Indicator
		$("#msgResult").html(loadMsg);
		
		//Call Ajax
		$.ajax({
		  type: "POST",
		  url: siteURL+"searchVideo.php",
		  data: "sid="+sid,
		  success: function(msg){
				// Show msg
				$("#c"+sid).html(msg);
				$("#img"+sid).attr("src", "images/less-icon.gif");
				
				$('#mycarous').jcarousel({
					vertical: true,
					scroll: 1
				});
				
				//Show Indicator
				$("#msgResult").html(loadMsg);
				
				//Call Ajax
				$.ajax({
				  type: "POST",
				  url: siteURL+"searchVideo.php",
				  data: "cid="+sid,
				  success: function(msg){
						// Show msg
						//alert(msg);
						$("#msgResult").html(msg);
						$('#mycarousel').jcarousel();
						showVideo();
						
						$('.searchAll').click(function(){
							var cid = $(this).attr("rel");
							$("#msgTitle").html($(this).text());
							//Call Ajax
							$.ajax({
							  type: "POST",
							  url: siteURL+"searchVideo.php",
							  data: "cid="+cid,
							  success: function(msg){
									// Show msg
									$("#msgResult").html(msg);
									$('#mycarousel').jcarousel();
									showVideo();
								}
							});
							return false;
					
						});
						
						//Hide Indicator
						$('#move').hide();
					}
				});
			}
		});
		
		//Hide Indicator
		//$('#move').hide();
		
		return false;

	});
	 
		
	function showVideo()
	{
		
		//Show Indicator
		$("#searchResult").ajaxStart(function(){
			  $(this).show();
		});
	
		//Hide Indicator
		$("#searchResult").ajaxStop(function(){
			  $(this).hide();
		});
		
		//Search Video
		$('.searchVideo').click(function(){
			var vid = $(this).attr("rel");
			if(oldId2 != '')
			{
				$('#'+oldId2).removeClass('redlnks').addClass("blklnks");
			}
			oldId2 = $(this).attr("id");
			$(this).removeClass('blklnks').addClass("redlnks");
			//Call Ajax
			$.ajax({
			  type: "POST",
			  url: siteURL+"searchVideo.php",
			  data: "vid="+vid,
			  success: function(msg){
					// Show msg
					$("#msgVideo").html(msg);
					flag = 0;
					
					//Load and execute a JavaScript file.
					$.ajax({ type: "GET",  url: "./js/thickbox.js",  dataType: "script" });
				}
			});
			
			return false;
	
		});
	}
	
	
});// End Ready