/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){


    $('#thumbs li a').click(function(){
        var nam = $(this).index('li a');
        $('div.scrollimage').scrollLeft(1500 * nam);

    });

});

$(function(){
    //Get our elements for faster access and set overlay width
    var div = $('div.scrollimage');

    //Remove scrollbars
    div.css({overflow: 'hidden'});

});



$(function(){
    //Get our elements for faster access and set overlay width
    var div = $('div.scrollthumbs'),
         ul = $('#thumbs'),
                 // unordered list's left margin
                 ulPadding = 15;

    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars
    div.css({overflow: 'hidden'});

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e){

      //As images are loaded ul width increases,
      //so we recalculate it each time
      var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

      var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / (divWidth * 1);


      div.scrollLeft(left);
    });
});



$(function() {
    $( "#accordion" ).accordion({
            autoHeight: false,
            selected: '.bold',
            header: 'h3',
            collapsible: true
    });
});


function slideSwitch() {
    
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    $active.animate({opacity: 0.0}, 1000, function() {
            $active.addClass('active last-active');
        });

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(function() {

    $('#slideshow img:first-child').addClass('active')
    setInterval( "slideSwitch()", 3000 );

});


