$(function(){

    $(".FieldListCSS option:selected").addClass("selected");
    
    $("#get_answer").click(function(){
        var checkOption = $(".FieldListCSS .selected").val(); 
      
        if (checkOption.indexOf("0|24")==0) {
            var squareFt = "4";
        } else if (checkOption.indexOf("0|26")==0) {
            var squareFt = "4";
        } else if (checkOption.indexOf("0|25")==0) {
            var squareFt = "5";
        } else if (checkOption.indexOf("0|27")==0) {
            var squareFt = "5";
        }
            
            var rolls = $("#rolls").val();
            var answer = squareFt*rolls;
            $(".Phuse_QuantityField").val((answer.toFixed(2)));
            var totalPrice = $("#carpet_price span").text()*answer.toFixed(2);
            $(".total_price").text("Total Price: \u00a3"+totalPrice.toFixed(2));
    });
    
    $(".fancybox").fancybox({"frameWidth":643,"frameHeight":483,"hideOnContentClick":false});
    
    
    
    $("textarea").attr("style","");
    
    $("#carpet_price span").each(function(){
        var textReplace = $(this).text();
        textReplace = textReplace.replace("\u00a3","");
        $(this).text(textReplace);
        $(this).parent().prepend("\u00a3");
    });
    
    
    
    $("#top_nav a:last").attr("style","border: 0;");
    $(".default_feed:last").attr("style","border: 0;");

    
    $(".browse_links .Phuse_SiteMap_LI").each(function() {
        $(this).html($(this).html().replace("</a>",",</a>"));
    });
    
    $(".CheckoutButtonCSS2, #CI2SB_CL").hide();
    if ($("#CI113SB_P_7_RL, #CI113SB_P_8_RL, #CI113SB_P_10_RL, #CI113SB_P_11_RL, #CI113SB_P_12_RL, #CI113SB_P_13_RL, #CI113SB_P_14_RL, #CI113SB_P_15_RL, #CI113SB_P_16_RL, #CI113SB_P_17_RL").is(":visible")) {
        $(".CheckoutButtonCSS2, #CI2SB_CL").show();
        $(".select_delivery").hide();
        
    }
    
    
    
    $(".charges .Phuse_AddToBasketButton").click(function() {
        self.close();
    });
    
    if ($(".checkout, .shop").is(":visible")) {
        $(".footer, .footer_top, .footer_btm, #top_nav").hide();
        
    }
    
    var cookieCount = $.cookie("itemCount");
    var itemCount = $("#itemCount").text();
    if (itemCount>cookieCount) { $("#updated").fadeIn();var timeout = setTimeout(function() {$("#updated").fadeOut()}, 3000);$.cookie("itemCount",itemCount); }

    
   var endPos = $(".totalprice").text().indexOf(".")-1;
    var newValue = $(".totalprice").text().substr(1,endPos).replace(",","")*1;
    
    if (newValue>495) {
        alert ("Your order is over \u00a3495 - delivery is FREE");
        
        $(".CheckoutButtonCSS2").show();
        $(".select_delivery").hide();
        if ($("#CI113SB_P_7_RL, #CI113SB_P_8_RL, #CI113SB_P_10_RL, #CI113SB_P_11_RL, #CI113SB_P_12_RL, #CI113SB_P_13_RL, #CI113SB_P_14_RL, #CI113SB_P_15_RL, #CI113SB_P_16_RL, #CI113SB_P_17_RL").is(":visible")) {
            alert ("Remove delivery from the basket");
        }
    }

            
});

/*
    $(".Phuse_AddToBasketButton").click(function() {
        opener.location.href=("http://staging.ph-creative.com/Sites/CarpetUK/BasketDetail.phuse"); self.close();
    });*/