$(document).ready(function() {
    //Preloading function for product detail page //////////
    var aImagesToLoad = new Array();
    var the_one_image = $(".main_prod_img_wrap > a").attr("href");

    if ($(".prod_thumb").length > 0) {
        $(".prod_thumb > li").each(function() {
            var _self = this;
            var main_img = $(this).children("a").attr("href");
            var big_img = main_img.replace(/(\$productDetailMain\$)/g, "$productdetail_zoom_new$");
            aImagesToLoad.push(main_img, big_img);
        })
        myProgressBar = new ProgressBar(aImagesToLoad);
    } else {
        aImagesToLoad.push(the_one_image);
        myProgressBar = new ProgressBar(aImagesToLoad);
    }

    //360 show/hide function for product detail page //////////
    $(".product_flash").click(function() {
        if (!$(".flash_360_c").is(':visible')) {
            $(".flash_360_c, #flash_360").css("display", "block");
            $(this).css({ 'background': 'transparent url(/harrodsstore/new_images/buttons/enable_zoom.jpg) left top no-repeat', 'width': '99px' });
            $(this).attr("title", "Enable zoom");
        } else {
            $(".flash_360_c, #flash_360").css("display", "none");
            $(this).css({ 'background': 'transparent url(/harrodsstore/new_images/buttons/inter_360.jpg) left top no-repeat', 'width': '143px' });
            $(this).attr("title", "View interactive 360");
        } return false;
    })
    //creating the tabs and moving the ul from the description up next the selection on product detail page //////////
    if ($("#fragment-1 > ul").length > 0) {
        var features_list = $("#fragment-1 > ul");
        features_list.remove();
        $(".desc_list").append(features_list);

        if ($("#fragment-1 > p").length <= 0) {
            //alert('empty');
            $('.ui-tabs-nav > li:first').hide();
            $('.ui-tabs-nav > li').eq(1).addClass('first ui-tabs-selected');
            $('#fragment-1').hide();
            $('#fragment-2').removeClass('ui-tabs-hide').show();
        }
    }
    if ($("#product_hamper_landscape").length > 0) {
        $(".assistance_list li").eq(2).css({ width: '206px', borderRight: '0px' });
        $(".assistance_list li").eq(5).css({ width: '206px', borderRight: '0px' });
    }
    $('.product_features dl dt').eq(0).addClass('active');
    $('.product_features dl dd').eq(0).show();
    function hamperModal(ele, mdw, mdh, cont) {
        var theTitle = ele.attr("title");
        var theContent = cont.html();
        $("#hampers_dialog").text("");

        $("#hampers_dialog").dialog({
            width: mdw,
            height: mdh,
            title: theTitle,
            modal: true,
            overlay: {
                opacity: 0.9,
                background: "#000000"
            }
        }).fadeIn("slow");
        $(".ui-dialog-titlebar-close").text('');
        $("#hampers_dialog").append(theContent).fadeIn("slow");
    }
    $(".assistance_list li.delivery a").click(function() {
        if ($(this).attr('rel') == 'True') {
            $('.not_exportable').hide();
            hamperModal($(this), 555, 760, $("#h_delivery"));
        } else {
            $('.is_exportable').hide();
            hamperModal($(this), 555, 260, $("#h_delivery"));
        }
        return false;
    })
    $(".countries_list").live("click", function() {
        if ($(".assistance_list li.delivery a").attr('rel') == 'True') {
            $('.not_exportable').hide();
            hamperModal($(".assistance_list li.delivery a"), 555, 760, $("#h_delivery"));
        } else {
            $('.is_exportable').hide();
            hamperModal($(".assistance_list li.delivery a"), 555, 260, $("#h_delivery"));
        }
        return false;
    })
    $(".assistance_list li.order_dates a").click(function() {
        hamperModal($(this), 510, 230, $("#h_dates"));
        return false;
    })
    $(".assistance_list li.gift_messages a").click(function() {
        hamperModal($(this), 510, 180, $("#h_gifts"));
        return false;
    })
    $(".assistance_list li.hampers_faq a").click(function() {
        hamperModal($(this), 575, 450, $("#h_faq"));
        return false;
    })    

});