$.fn.hoverClass = function(c) {

	return this.each(function(){
	$(this).hover(
	function() { $(this).addClass(c); },
	function() { $(this).removeClass(c); }

		);
	});
};

function menu(){
//$("#menu li").hover(function(){$("ul", this).hide(); $("ul", this).fadeIn('slow'); },function() { }	);
	$("ul#main-nav > li").hover( function() { 					
		$("ul.child").hide(); $("ul.child", this).stop(true,true).fadeIn('slow');
		$(this).addClass("sfHover"); 
		
	}, function() { 
		$(this).removeClass("sfHover"); 
			$('a.active').parent('li').addClass("sfHover");
			$('a.active').next("ul.child").stop(true,true).fadeIn('slow'); 										
	});
	$("ul.child > li").hover( function() { 
		$("ul", this).hide(); $("ul.sub-child", this).stop(true,true).fadeIn('slow'); 
		$(this).addClass("sfHover"); 
	}, function() { 
		$(this).removeClass("sfHover");
		$("ul", this).hide(); 
	});
	$('a.active').parent('li').addClass("sfHover");
	$("ul.child", $('a.active').parent('li')).stop(true,true).fadeIn('slow'); 

}
function topMenu(){
	$("#top li").click(function(){$('#top li').children('a').removeClass('active'); $(this).children('a').addClass('active');$(".top-down:eq("+$("#top li").index(this)+")").show("20")},function() { }	);
	if (document.all) {	$("#top li").hoverClass ("sfHover");}
	$("#top li").mouseout(function(){$(".top-down").hide()});
	/*$("#top li").mouseout(function(){$(".top-down").hide();});*/
	$(".top-down").mouseover(function(){$(this).show();});
	$(".top-down").mouseout(function(){$(this).hide(); $('#top li').children('a').removeClass('active'); });
}
function searchForm(){
	$('#search').mouseover(function(){	$('#search .input:first').fadeIn('slow'); $('#search .input:first').focus(); $('#search .submit').removeAttr('disabled');  });
	$('#search .input:first').blur(function(){ if($(this).val()==''){	$(this).hide(); $('#search .submit').attr("disabled", true);}});
}
/*function loadMenu(title)
{
	$(".top-down").html('');
	$(".top-down").removeClass('quick-links');
	if(title=='quick-links')
	{
		$(".top-down").addClass('quick-links');
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request");
	 return;
	 }
	var url="loadmenu.php";
	url=url+"?url="+title;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}*/
function newsLetter()
{
	$('#popup').children('img.close').click(function(){$('#popup-container').css('display','none');$('#popup').fadeOut();});
	$('#popup-container').click(function(){$(this).css('display','none');$('#popup').fadeOut();});
	if($('#subscription').length > 0)
	{
		$('#subscription').validate();	
	}
}

function showPop()
{
	$('#popup-container').css('display','block'); $('#popup').fadeIn('50');
}

function logIn()
{
	$('.login-box').click(function(){
						$('#login-popup-container').css('display','block'); $('#login-popup').fadeIn('50');							
						});
	$('#login-popup').children('img.close').click(function(){$('#login-popup-container').css('display','none');$('#login-popup').fadeOut();});
	$('#login-popup-container').click(function(){$(this).css('display','none');$('#login-popup').fadeOut();});
	
	$('#login').validate();
	
}

function stateChanged() 
{ 	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 $(".top-down").html(xmlHttp.responseText);
	 var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		if (window.addthis){
			window.addthis = null;
		}
		$.getScript( script );
	 }
	 else
	 {
		 $(".top-down").html('<img src="/siteimages/images/loader.gif" alt="Loading" class="loader"/>');	 
	 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function tabHandler()
{
	if($('.tab').length > 0)
	{
		$('.tab-content:eq(0)').show();
		$('.tab:eq(0)').addClass('active');
			var obj=$('.tab-content:eq(0)');
		$('.tab').click(function(){
			if($(this).hasClass('active')!=true)
			{
				$('.tab-content').hide();
				$('.tab').removeClass('active');
				$(this).addClass('active');
				$('.tab-content:eq('+$('.tab').index(this)+')').fadeIn('slow');
				
			}
		});
	}
}
/***********/

function scrollVideo()
{
	var count=$('.thumb').length;
	if(count > 2)
	{	
		$('img.left-move').click(function(){
			$('.thumb-scroller').animate({marginLeft:'-120px'},'slow');
			setTimeout('moveLeft()',700);
		});
		$('img.right-move').click(function(){
			$('#scrolling').animate({marginLeft:'120px'},'slow');
			setTimeout('moveRight()',700);
		});
	}
}

	function moveLeft()
	{
		$obj=$('.thumb-scroller').children('.thumb:first');
		$('.thumb-scroller').children('.thumb:first').remove();
		$('.thumb-scroller').append('<div class="thumb">'+$obj.html()+'</div>');
		$('.thumb-scroller').css('margin-left','0px');	
	}
	function moveRight()
	{
		$obj=$('.thumb-scroller').children('.thumb:last');
		$('.thumb-scroller').children('.thumb:last').remove();
		$('.thumb-scroller').html('<div class="thumb">'+$obj.html()+'</div>'+$('.thumb-scroller').html());
		$('.thumb-scroller').css('margin-left','0px');
	}

function loadCategoryVideo(id)
{
	$('span#channel-title').html($('li#channel-'+id+' a').html());
	$('#video-cat li').removeClass('active');
	$('li#channel-'+id).addClass('active');
	$(".thumb-scroller").html('<img src="/siteimages/images/loadingAnimation.gif" alt="loading" style="postion:ralative; margin-top:55px; margin-left:15px;" />');
	$.post("/loadcatvideo.php", { id: id}, function(data) {
				$(".thumb-scroller").html(data);
				scrollVideo();
			});
}

function loadVideo(id)
{
	$("#video-detail").html('<img src="/siteimages/images/loadingAnimation.gif" alt="Loading" style="position:absolute; top:150px; left:200px;" />');
	$.post("/loadvideo.php", { id: id}, function(data) {
				$("#video-detail").html(data);
				tabHandler();
				closeShare();
			});
}
function shareButton()
{
	$('#share').click(function(){
		$('#share-code').slideToggle();					   
	});
	
	
}

function closeShare()
{
	$('img.close-share').click(function(){
		$('#share-code').slideUp();									
	});	
}

