$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
        
         //Teaser
        //var rotatTimer = setTimeout("rotatingHeader()", 5000);
        
        rotatingHeader();
        rotatingHeaderHover();
        
        bindVideo();
        

	}
);



/* Teaser
***********************************/

function rotatingHeader()
{
    if($("#header-rotator li.active").length == 0)
    {
        var iIndex = 0;
    }else{
        var iIndex = $("#header-rotator li.active").attr("id").replace("header-rotator","");
        if (iIndex >= 0)
        {
            iIndex++;
            
            if (iIndex >= $(".homeImg").size())
            {
               var iIndex = 0;
            }
        }
    }
      
    changeItem(iIndex);
}

function rotatingHeaderHover()
{
	$("#header-rotator li").hover(
		function()
		{
            curID   = $("#header-rotator li.active").attr("id").replace("header-rotator","");
            id      = $(this).attr("id").replace("header-rotator","");
            if(curID != id)
            {
                clearTimeout(rotater);
                changeItem(id);              
            }
		}
	);
}

function changeItem(iIndex)
{          
    $(".homeImg").fadeOut(1000);
    $("#home"+iIndex).fadeIn(1000);

    //$("#home"+iIndex).css('display','block');
    
    $("#header-rotator .active").removeClass("active");
    $("#header-rotator"+iIndex).addClass('active');
    
    $("#header-img-slogan").html($("#home"+iIndex).attr("alt"));
            
    rotater = setTimeout("rotatingHeader()", 5000);	
}

function bindVideo()
{
    $('a.videolink').click(
    	function()
    	{
		    $("#movie").flash({
		    	swf: "/swf/bergerden.swf",
		    	height: 470,
		    	width: 800
		    });	
	
	        fillBackground();
   	
    		$('.close').unbind("click");
    		
	        $('.close').click(function(){
	            $("body div#ccSHADOW").fadeOut();
		        $("#modal-wrap").css({display: "none"});
				
				$("#movie").flash().remove();
	        });
    	}
    );
}



function fillBackground()
{
	var iWidth = $("body").width();
		
    if ($("body div#ccSHADOW").length == 0)
	{
		var shadow = $("<div></div>").attr("id", "ccSHADOW")
				.css({
						background: "#000000",
						opacity: "0.6",
						position: "absolute",
						left: "0",
						top: "0",
						'z-index': 900
				});
		
		var iHeight = $(document).height();
		shadow.width(iWidth+"px");
		shadow.height(iHeight+"px");
		$("body").append(shadow);
	}
	else
	{
		var shadow = $("body div#ccSHADOW");
	}	
	
	shadow.show();
    
    iLeft = (iWidth/2) - 400;
    $("#modal-wrap").css({left: iLeft+"px"}).show();

}
