$().ready( function(){
	$("#gol_main_menu li").hover(function(){
		$("#sub_menu").children("ul").css("display", "none");
	
		var submenu = "#sub" + $(this).attr("id");
		$(submenu).css("display", "block");			
	},	function(){
		var submenu = "#sub" + $(this).attr("id");
	});
	
	$("#sub_menu ul").hover(function(){
		$(this).css("display", "block");			
	},	function(){
		$(this).fadeOut("normal");
	});
																				
	$("#newsletter").submit(submitNewsletter);
	$("#newsletter_email").focus(focusNewsletter);
	$("#newsletter_email").blur(blurNewsletter);
	
	$("#search_query").focus(focusSearch);
	$("#search_query").blur(blurSearch);
/*
	if( typeof startCarousel=='function') {
		startCarousel();
	}
*/

	//-- Blogs
	if($("#newComment").length > 0){
			$("#newComment form").submit( function(){ 
				$.get("/blog/blog_comment.php", $(this).serialize(), function(data){
				var $result = data.split(",");
				if( $result[0] == "true" ){
					$("#newComment").html("");
				}
				
				alert($result[1]);	
			});
				
			return false;
		});
	}
	
	//-- Experts
	if($("#newQuestion").length > 0){
			$("#newQuestion form").submit( function(){ 
				$.get("/expert/ask_expert.php", $(this).serialize(), function(data){
				var $result = data.split(",");
				if( $result[0] == "true" ){
					$("#newQuestion").html("");
				}
				
				alert($result[1]);	
			});
				
			return false;
		});
	}
	/*
	if( $("#channel_related_div").length > 0 ) {
		$("#channel_related_div > ul li a").click( function() {
			var $channel_id = $(this).attr("href").slice(16);
			//$tempGlobal = $("#video_related_div ul.vid_list").html();
			$("#video_related_div ul.vid_list").fadeOut("fast");
			$.get("/video/video_related.php?channel="+$channel_id, function(data) {
				$("#video_related_div ul.vid_list").html( data ).slideDown("fast");																
			});
			return false;
		});
	}
	*/
	
	if( $("#channel_related_div").length > 0 ) {
		$("#channel_related_div > ul li a").click( function() {
			var $channel_id = $(this).attr("href").slice(16);
			//$tempGlobal = $("#video_related_div ul.vid_list").html();
			$("#video_related_div").fadeOut("fast");
			$.get("/video/video_related.php?channel="+$channel_id, function(data) {
				$("#video_related_div").html( data ).slideDown("fast");																
			});
			return false;
		});
	}
	
	if( $("#video_playlist").length > 0 ) {
		
		$("video_playlist > ul li").hover( 
			function() { $(this).addClass("video_playlist_hover") } , 
			function() { $(this).removeClass("video_playlist_hover") } 
		);
		
		$("#video_playlist > ul li").click( function() {
//			$(this).children("span.play a").attr("id");	

			createplayer($(this).attr("id"), true);
			return false;
		});
	
	}
	
	
});

function submitNewsletter(){
	var newsletter_email = $("#newsletter_email").val();
	
	if(newsletter_email != ""){
		$.get("/includes/ajax.newsletter.php", {email: newsletter_email}, function(data){
			alert(data.toString());
		});
	} else {
		alert('Please submit a valid email');
	} 
	
	return false;
}

function focusNewsletter(){
	var newsletter_email = $("#newsletter_email");

	newsletter_email.removeClass("input_bg");
}

function blurNewsletter(){
	var newsletter_email = $("#newsletter_email");
	
	if(newsletter_email.val() == ""){
		newsletter_email.addClass("input_bg");
	}
}

function focusSearch(){
	var search_query = $("#search_query");

	search_query.removeClass("input_bg");
}

function blurSearch(){
	var search_query = $("#search_query");
	
	if(search_query.val() == ""){
		search_query.addClass("input_bg");
	}
}