$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li, #subnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
		
        //Start Gallery modal
        $('.gallery-thumbs-img').lightBox();
		$('.gallery-thumbs-mask').lightBox();

        rotatingHeader();
        rotateClick();
	}
);

function rotateClick()
{
    $('ul#header-rotator li a').click(function(e){
        e.preventDefault();
        var cur = $(this).parent();
        $("ul#header-rotator li").removeClass('active');
        cur.addClass('active');
       
        clearTimeout(rotater);
        changeHeader();
    });
}

function rotatingHeader()
{
    
    var curPos = $("ul#header-rotator li.active").index();
    curPos++;
    
    if(curPos >= $("ul#header-rotator li").length)
    {
        curPos = 0;
    }
    
    $("ul#header-rotator li").removeClass('active');
    $("ul#header-rotator li:eq(" + curPos + ")").addClass('active');
        
    changeHeader();
}

function changeHeader()
{
    $('#home-bg-rotator-img1').attr('src',$("ul#header-rotator li.active img").attr('src'));
    
    
    $('#home-bg-rotator-img1').fadeIn(1500, function(){
		setTimeout("switchImages()", 200);
                
        
         
    });
    
    $('p#header-slogan').fadeOut(100, function(){
        $('p#header-slogan').html($("ul#header-rotator li.active img").attr("alt"));
        
        Cufon.replace('p#header-slogan');
        
        $('p#header-slogan').fadeIn(500);    
    });
    

    rotater = setTimeout("rotatingHeader()", 5000);	
}

function switchImages()
{
	$('#home-bg-rotator-img2').hide();
	$('#home-bg-rotator-img2').attr('src',$("ul#header-rotator li.active img").attr('src'));
	$('#home-bg-rotator-img2').show();

	$('#home-bg-rotator-img1').hide();
}

