/*
 * 2010
 */
$(document).ready(function(){
    initOnState();
    initFonts();
    if ($('.slider').length){
        initSlider();
    }
    if ($('.panel').length){
        initLoop();
    }

    $('.locations a').click(function(){
       return false;
    });
    //ie 6 png fix
    initPNG();
    initCars();
});

function initFonts(){
    Cufon.replace('.replace');
}

function initSlider(){
    
    $('.slide:first').fadeIn();

    $('.slide:first').addClass('showing');

    setInterval(function(){
        $('.hero .showing').fadeOut('slow',function(){
            $(this).next('.slide').fadeIn('slow');
            $(this).next('.slide').addClass('showing');
            var thisHtml = $(this).html();
            $(this).removeClass('showing');
            var tClasses = $(this).attr('class');
            var tStyles = $(this).css('background-image');

            $('.slider').append('<div class="'+tClasses+'">'+thisHtml+'</div>');
            $(this).remove();
        });
    },5000);

   
}

function initLoop(){
    
    $('.loop').children('.item:first').show();
    $('.loop').children('.item:first').addClass('showing');

    setInterval(function(){

        $('.loop .showing').fadeOut(function(){
            var nextItem = $('.loop').children('.showing').next('.item');
            var thisHtml = $(this).html();
            nextItem.fadeIn();
            nextItem.addClass('showing');
            $('.loop').append('<div class="item">'+thisHtml+'</div>');
            $(this).remove();
        });
        
    },10000);
}

function initOnState(){
    var el = '.left a[href="'+window.location+'"]';
    $(el).addClass('lightblue');
    $(el).parent('li').parent('ul').prev('a').addClass('lightblue');
}

function initPNG(){

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
		var ieversion = new Number(RegExp.$1); 
	 	if(ieversion == 6){
	  		DD_belatedPNG.fix('.fix');
		}
	}
    
}

function initCars(){
    $('.images img').not('.main_image').mouseover(function(){
       var newImgSrc = $(this).attr('src').replace('thumb','large')
       $('.main_image').attr('src',newImgSrc);
    });
}
