$(function(){

    $("ul#nav li").hover(function(){
        $(this).addClass("hover");
		if($(this).children("ul").length) {
			$('a:first',this).addClass("hassub");
			}
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
         $(this).removeClass("hover");
		$('a:first',this).removeClass("hassub");
        $('ul:first',this).css('visibility', 'hidden');
    });
	
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	// Dialog Link
	$('#dialog_link').click(function(){
		$('#dialog').dialog('open');
		return false;
	});
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
	$(".logo").click(function() { 
		window.location = "index.asp"; 
		return false; 
	}); 
	
	$("#tab_next_match").click(function(){
		$("#tab_next_match").css("background","none");
		$("#tab_score").css("background","url(/static/project/images/tab_home_red_stand.gif)");
		$("#content_next_match").show();
		$("#content_score").hide();
	});

	$("#tab_score").click(function(){
		$("#tab_next_match").css("background","url(/static/project/images/tab_home_red_volgendewedstrijd.gif)");
		$("#tab_score").css("background","none");
		$("#content_next_match").hide();
		$("#content_score").show();
	});
	
	$("#foto_player_thumb1,#foto_player_thumb2,#foto_player_thumb3,#foto_player_thumb4").click(function () {
		no=$(this).attr('no');
		big_picture=$(this).attr('big_picture');
		$(".foto_player_thumb").show();
		$(this).hide();
		$(".foto_player_label").hide();
		$("#foto_player_label"+no).show();
		
		$("#foto_player").hide();
		$("#foto_player").attr("src",big_picture);
		$("#foto_player").fadeIn();
	});
		
	$("#video_player_thumb1,#video_player_thumb2,#video_player_thumb3,#video_player_thumb4").click(function () {
		no=$(this).attr('no');
		//big_picture=$(this).attr('big_picture');
		
		$(".video_player_thumb").show();
		$(this).hide();
		
		$(".video_player_label").hide();
		$("#video_player_label"+no).show();
		
		$(".video_player").hide();
		$("#video_player"+no).show();
		
		//$("#video_player").attr("src",big_picture);
		//$("#video_player").fadeIn();
	});

});

$(document).ready(function(){
	var delay=300;
	$("#hdr_news1").mouseover(function () {
		showItem(1);
	});
	$("#hdr_news2").mouseover(function () {
		showItem(2);
	});
	$("#hdr_news3").mouseover(function () {
		showItem(3);
	});
	
    $("#caroussel").bind("mouseenter",function(){
            clearTimeout(rotate_timer);
        }).bind("mouseleave",function(){
        timer_no=curr_no;
        var media=$("#hdr_news"+curr_no).attr("media");
        if(media!="video"){
            autoRotate();
        }
    });
    
	$("#tabs").tabs();
	
		
	$("#accordion").accordion({ header: "h3" });
	
	$("#DialogDiv").dialog({
		autoOpen: false,
		modal: true,
		height: 500,
		width: 500
	});
	
	autoRotate();
	
	$('.scroll-pane').jScrollPane();
	
	
});

var curr_no=1;
var timer_no=1;
var rotate_timer="";
var timer=5000;

function showItem(no){
	if(curr_no!=no){
		resetItems();
		//$("#caroussel_items").css("backgroundImage","url('/hsvhoek/img/bg_newson.jpg')");
		$("#news_image_"+no).fadeIn();
		t=32+(no*89)-89;
		$("#arrow_news").css("top",t+"px");
		$("#hdr_news"+no).css("backgroundImage","url('img/bg_newsoff.jpg')");
		//$("#hdr_news"+no).css("padding","18px");
		$("#hdr_news"+no).children().removeClass();

		//$("#hdr_news"+no).children("#black").addClass("hdr_news_big_black");
		//$("#hdr_news"+no).children("#white").addClass("hdr_news_big_white");
		curr_no=no;
	}
}

function resetItems(){
	$("#news_image_"+curr_no).fadeOut();
	$("#hdr_news"+curr_no).css("backgroundImage","url('img/bg_newson.jpg')");
	$("#hdr_news"+curr_no).children().removeClass();
	//$("#hdr_news"+curr_no).children("#black").addClass("hdr_news_small_black");
	//$("#hdr_news"+curr_no).children("#white").addClass("hdr_news_small_white");
}

function autoRotate(){
	showItem(timer_no);
	timer_no++;
	if(timer_no>3){
		timer_no=1;
	}
	rotate_timer=setTimeout("autoRotate()",timer);
}

function showDialog(widthVar, heightVar, urlVar, titleVar){
	$("#DialogDiv").html('<iframe id="modalIframeId" width="'+widthVar+'" height="'+heightVar+'" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="none" />').dialog("open");
	$("#modalIframeId").attr("src",urlVar);
	$("#DialogDiv").data("width.dialog", (widthVar+20));
	$("#DialogDiv").data("height.dialog", (heightVar+20));
	$("#DialogDiv").data("title.dialog", titleVar);
	//$("#divId").attr("width",widthVar);
	//$("#divId").attr("height",heightVar);
	return false;
}
