// Product Detail Page Scripts

$(document).ready(function() {
    
    // Tab switcher.
    $('#productTabs dl#nav dt').each(function() {
        $(this).click(function() {
            if ($(this).attr('class') != 'current') {
                $('#productTabs dl#nav dt').removeClass('current');
                $('#productTabs dl#nav dd').hide();
                $(this).addClass('current');
                var currentContent = $(this).find('a').attr('href');
                $(currentContent).fadeIn();
                //$('#productTabContents')
                //    .html($(currentContent).html())
                //    .fadeIn();
            }
            return false;
        });
        
    });
    
    // Onload: make first tab current and display the first tab's content.
    $('#productTabs dl#nav dt:first').addClass('current');
    $('#productTabs dd.tabContent:first').fadeIn();
    //$('#productTabContents').html($('#productTabs dd.tabContent:first').html()).fadeIn();
    
    // Write a Review Popup.
    var getStoreDomain = $('input#varStoreDomain[type=hidden]').val(); // find the value of hidden input 'varStoreDomain'
    var getProductId = $('input#storeProductId[type=hidden]').val(); // find the value of hidden input 'storeProductId'
    
    $('a.writeReviewLink').click(function() {
        window.open('' + getStoreDomain + 'ProductReviewPopup.aspx?productID=' + getProductId + '#Write','Images','width=600, height=400, menubar=no, scrollbars=yes, resizable=yes, status=no, toolbar=no');
        return false;
    });
    
    // Email This Page Popup.
    $('a.emailPop').click(function() {
        window.open('' + getStoreDomain + 'EmailFriend.aspx?productID=' + getProductId + '#Write','Images','width=400, height=210, menubar=no, scrollbars=yes, resizable=yes, status=no, toolbar=no');
        return false;
    });
    
    // Add product title to the end of the breadcrumbs.
    var productTitle = $('h1').text();
    $('#breadCrumbs a:last').after('&nbsp;&raquo;&nbsp;' + productTitle);
    
    // Handle the image switching here:
    
    $('.thumbs img').each(function() {
        $(this).click(function() {
            var thisPath = $(this).attr('src');
            $('div.largeImage img')
                .attr('src',thisPath)
                .parent().attr('href',thisPath);
            return false;
        });
    });
    
    $('div.largeImage a').attr('href',$('.thumbs img:first').attr('src'));
    
    // Pixelsilk Method:
    $('div.largeImage img.cmsImage').click(function() {
        var thisImgUrl = $(this).parent().attr('href');
        window.open(thisImgUrl, 'Images', 'width=520,height=520,menubar=no,scrollbars=no,resizable=yes,status=no,toolbar=no');
        return false;
    });
    
    
});
