$(document).ready(function() {
    //browser detection
    /*if(typeof(BrowserDetect) != 'undefined') {
        if((BrowserDetect.browser == 'Explorer') && (BrowserDetect.version <= '6')){
            var output = '<div id="stupid_ie">IE 6 is stupid! upgrade/change your browser!</div>';
            $("body").append(output);
            $("div#stupid_ie").css({
                "width": "100px",
                "position": "absolute",
                "top": "0",
                "left": "0",
                "color": "red"
            });
        }   
    }*/
    
    //language form
    $("select#lang").change(function(){
        $("form#language").submit();
    });
    
    //fancy box
    $("ul.images li a.image").fancybox({
        'hideOnContentClick': true,
        'overlayShow': false
    });
    
    //side images
    var preview = $("div.preview");
    var image = $("div.preview img");
    
    $("a.preview").each(function(){
       $(this).click(function(){
            var url = $(this).attr('href');
            var image_src = $(image).attr('src');
            
            if(url != image_src){
                $(image).fadeOut(function(){
                    $(preview).height($(this).height()).addClass('loading');
                    $(this).attr('src', url);
                    $(this).load(function(){
                        $(preview).animate({"height": $(this).height()}).removeClass('loading');
                        $(this).fadeIn();
                    });
                });    
            }
            return false;
        }); 
    });
    
    //zebra for product specs
    $('ul.result > li:nth-child(even)').addClass('alt');

    //homepage slide show
    var images = $('div.slideshow img');

    //hide all, show first
    $(images).hide();
    $(images[0]).show();
    
    setInterval("slide_show()", 10000);
});

function slide_show(){
    var active = $('div.slideshow img.active');
    if(active.length == 0) var active = $('div.slideshow img:first');
    
    var next = active.next();
    if(next.length == 0) var next = $('div.slideshow img:first');
    
    active.fadeOut(700, function(){
        active.removeClass('active');
        next.fadeIn(1000).addClass('active');
    });
}
