$(function(){
   
    // Preload images
    var i = 0;
    var oImage  = new Array();
    var images  = new Array();
    images.push('img/werkright.jpg');
    images.push('img/werkright_hover.jpg');
    images.push('img/arrow_left.gif');
    images.push('img/arrow_left_hover.gif');
    images.push('img/arrow_right.gif');
    images.push('img/arrow_right_hover.gif');
    for(i=0;i<=images.length;i++)
    { 
        oImage[i]  = new Image();
        oImage[i].src = images[i];
    }

    //  Init Slide show
    var slideItem;
    var sliderArray = new Array();
    var w = $('.preview').width();  // container width
    var h = $('.preview').height(); // container height
   
    w = w ? w : 420;
    h = h ? h : 275;
    
    $('.simpleSlideShow').each( function(i,obj){
        slideItem = $(obj).slideShow({
                    interval :'none',
                    slideSize:{ width:w, height:h }
        });
        sliderArray.push(slideItem);
    });
    
    $('.simpleSlideShow, .scrolltext').css('display','none');

    //  Init Scrolling
    var scroll = $("#scrollable").scrollable({
        size:4
    });
    $(".item").click(function() {

        $('.simpleSlideShow, .scrolltext').css('display','none');
        var id  = parseInt($(this).find('.picitem').attr("alt"));
        var slideBlock =  $('.simpleSlideShow').eq(id);
        slideBlock.fadeIn('medium');
        $('.scrolltext').eq(id).show();
        sliderArray[id].options.interval=3;
        sliderArray[id].auto();
          
    }).filter(":first").addClass('active').click();
    
    $('.buttonnext').hover(
            function(){
                $(this).fadeTo('fast',0.8).removeClass('buttonnext').addClass('buttonnexthover');
            },
            function(){
                $(this).fadeTo('fast',1).removeClass('buttonnexthover').addClass('buttonnext');
            }
    ).click(function(){
    
        $.each( sliderArray, function(i,obj ){ 
               if($(obj).is(':visible')) 
               {   
                    sliderArray[i].options.interval='none';
                    sliderArray[i].next();
               }          
        })

    });
    $('.sign').css({'display':'block','width':'20px','height':'10px','z-index':'50','text-decoration':'none','cursor':'text'}).click(function(){window.open('/index/sign','','toolbar=no,menubar=no,resizable=no,width=520,height=180');return false;});
    
});
