/* Author: John Knowles */

$(document).ready(function(){
    
    /*
    Gallery functions
    */
    $('a').click(function() {
       $(this).blur(); 
    });
    
    $(".homeFadeImages a").mouseover(function() {
      $(".hidden", this).stop(true, true).show();
    });
    $(".homeFadeImages a").mouseout(function() {
        $(".hidden", this).fadeOut(3500);
    });
    
    
    $('#zoomLink').colorbox();
    $('.zoomLink').colorbox();
    
    //Create an incremended index on the thumbnail links
    var i = 0;
    $('#productDetailGalleryNav li').each(function(index){
       $('a', this).attr('rel', Number(i));
       if (i==0)
       {
           $('a', this).addClass('active');
       }
       i++;
    });
    
    
    //gallery navigation by thumbnail
    $('.productDetailGalleryNav a').click(function() {

        //set the required variables
        var img = $(this).attr('href');
        var rel = $(this).attr('rel');
        var detail = img.replace('.jpg', '-high.jpg');
        
        //remove class active from all thumbs
        $('#productDetailGalleryNav a').removeClass('active');
        //add active class to clicked thumb
        $(this).addClass('active');
        //set the detail zoom image href
        $('#zoomLink').attr('href', detail);
        //set the src alt and rel attributes
        $('#imageDetail').attr('src', img).attr('rel', rel);
        
        return false;
    });

    //gallery navigation right
    $("#galleryControlRight").click(function() {

        //set the required variables
        var imageNo = (Number($("#imageDetail").attr('rel'))+1);
        var img = $('.productDetailGalleryNav [rel='+imageNo+']').attr('href');
        var rel = $('.productDetailGalleryNav [rel='+imageNo+']').attr('rel');
        var detail = img.replace('.jpg', '-high.jpg');
        
        if (rel > 0)
            {
                $('#productDetailGalleryNav a').removeClass('active');
                $('[rel='+imageNo+']').addClass('active');
                //set the detail zoom image href
                $('#zoomLink').attr('href', detail);
                //set the src alt and rel attributes
                $("#imageDetail").attr('src', img).attr('rel', rel);
            }
            
        return false;
    });

});
