/* Author: John Knowles */
$(document).ready(function(){
    
    /* Prevent browser outline on click */
    $('a').click(function() {
       $(this).blur(); 
    });
    
    $('.home-feature-panel').cycle({ 
        fx:     'scrollHorz', 
        speed:   1000, 
        timeout: 8000,
        delay:   0,
        pause:   1,
        sync:    1,
        next:   '#next',
        prev:   '#previous'
    });
    
    $('.toggle').toggle(function(){
       $(this).next('.hidden').show();
       return false;
    }, function(){
       $(this).next('.hidden').hide();
       return false;
    });
    
    $("a#zoomLink").fancybox();
    
    // starting the script on page load
    nzimeTooltip('.tooltip');
    
    //gallery navigation by thumbnail
    $('.product-detail-thumbs a').click(function(){

        //set the required variables
        var img = $(this).attr('href');
        var rel = $(this).attr('rel');
        var detail = $(this).attr('rev');

        //remove class active from all thumbs
        $('#product-detail-thumbs 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($("#product-detail-image img").attr('rel'))+1);
        var img = $('.product-detail-thumbs [rel='+imageNo+']').attr('href');
        var rel = $('.product-detail-thumbs [rel='+imageNo+']').attr('rel');
        var detail = img.replace('.jpg', '-high.jpg');

        if (rel > 0)
        {
            $('#product-detail-thumbs 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;
    });
    
});
