var pathN = location.href;
var countryISO = "GB";
if($.cookie('country_iso').length > 0){
	countryISO = $.cookie('country_iso'); 
}
if(pathN.search('basketType=c_and_c') != -1){
	window.location="/pws/ShippingOptions.ice?viewBasket=true";
}
if(pathN.search('fcp-category') != -1){
	if ($.cookie("view_format") == null && pathN.search('sale') == -1) {
		set_4view();
	}
}
function set_4view() {
	var c = $("#viewing_format a#view_4");
	var d = $("#productsCont");
	$("#viewing_format a").removeClass("current");
	$.cookie("view_format", "view_4", {
		expires: 31,
		path: "/"
	});
	c.addClass("current");
	window.location.reload();
}

var timer = null;
var counter = 0;
function banner() {
	timer=setTimeout("banner()", 5000);
	counter++;
	if (counter >= 3)
	counter = 0;
	document.bannerad.src = ads[counter];
}
function gothere() {
	counter2 = counter;
	window.location.href = newplace[counter2];
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

BTFRESCA.switchOnHover = function () {
    $("#alternativeViews").live("click", function (d) {
        var b = $(d.target),
            a, c;
        if (b.is("img")) {
            $altImageParentLi = b.parents("li:first");
            $altImagesLi = $(this).find(".altImg");
            $altImagesLi.removeClass("hover");
            $altImageParentLi.addClass("hover");
            moveScroller(false, $altImageParentLi)
        }
    })
};

	// $(document).ready(function(){
	$('#productTitle').after('<div id="prodReview"></div>');
	$('#bv').appendTo('#prodReview');

// });
function checkSearch(){
		oSForm = document.forms[2];
		if (oSForm.elements["sli_search_1"].value == "Search"){
			oSForm.elements["sli_search_1"].value = "";
			oSForm.elements["sli_search_1"].focus();
		}
		else {
			oSForm.submit();
		}
	}
	
$(document).ready(function(){
	$('span.onePrice').addClass('cufon');
	$('span.wasPrice').addClass('cufon');
	$('span.nowPrice').addClass('cufon');
	
	$('.newest,.high_to_low,.low_to_high').click(function () {
		if (!$(this).is('selectSort')) {
			$.each($('.newest,.high_to_low,.low_to_high'), function () {
				$(this).removeClass('selectSort')
			});
			$(this).addClass('selectSort');
		}
	});
	
	$('ul#js_country_drop_down, #country_holder').hover(
		function(){
			$('div#rightActionsCont').css({'position':'relative','height':'718px'});
		},		
		function(){
			$('div#rightActionsCont').css({'position':'relative','height':'17px'});
		}
	);

$("li#topNavCategories_dept_newin a.level_1").attr("href","#");	
$("li#topNavCategories_dept_topaccessories a.level_1").attr("href","#");
$("li#topNavCategories_dept_saleall a.level_1").attr("href","#");
$("li#topNavCategories_dept_clothing a.level_1").attr("href","#");
$("li#topNavCategories_dept_clothing a.level_2").attr("href","#");
$('#topNavCategories_dept_tights_and_socks').removeClass('last');

$('input[name*="customerMarketing"]').attr('checked', true);

//$('#fCATEGORY').remove();

//$('#filterCont li').addClass('filterGroupClosed');
//$('#filterCont li ul').css('display','none');

/*	Was breaking Baynote and SLI
$('.productImg').mouseOver(
		function(){
		$(this).parent().children('.product_links').animate({
		height: 'toggle'
	  }, 50, function() {
		// Animation complete.
	});
	
});
*/


/*
if($('body').hasClass('ProductDetails')){

$('<ul class="recentlyV"></ul>').insertAfter('#bv');
	
}
*/

//SLI
$("#searchForm").css("display","none");$("#topNavForm").append('<form action="http://fashion.warehouse.co.uk/search" method="get" id="searchFormSLI" onSubmit="checkSearch();" name="searchform"><label class="hide" for="w">Enter keywords or product code to search</label><input type="hidden" id="country" name="country" value="'+countryISO+'" /><input name="w" type="text" id="sli_search_1" value="Search" class="clearValue topFormItem" autocomplete="off" onblur="if (this.value == \'\') {this.value = \'Search\';}" onfocus="if (this.value == \'Search\') {this.value = \'\';}"/><input type="hidden" name="asug"><input type="button" id="search_button" alt="" onClick="checkSearch();" class="sli_button" /></form>');function checkSearch(){oSForm=document.forms[2];if((oSForm.elements["sli_search_1"].value=="Search")||(oSForm.elements["sli_search_1"].value=="")){oSForm.elements["sli_search_1"].value="";oSForm.elements["sli_search_1"].focus()}else{oSForm.submit()}}
});


BTFRESCA.toggleAlternativeImages = function () {
    $("#productsCont").mouseover(function (e) {
        var b = $(e.target),
            a, c, g = b.find("img").length ? b.find("img") : b,
            d = g.parents(".alternative_images:first"),
            h = d.attr("data-alt-images-count") || "",
            f;
									
			if(b.is('img') || b.is('h3') || b.is('p')){

				var headV = b.parents('.productCont').children('h3');
				var priceV = b.parents('.productCont').children('.productPrice');
				var buttonV = b.parents('.productCont').children('.product_links');
											
				var headH = headV.height();
				var priceH = priceV.height();
				var buttonH = buttonV.height();
				
				headV.animate({
					bottom:priceH+buttonH+'px'
				});
				priceV.animate({
					bottom:buttonH+'px'
				});
				buttonV.animate({
					bottom:'0px'
				});
				
				b.parents('.productCont').mouseleave(function(){
					headV.animate({
						bottom:priceH+'px'
					});
					priceV.animate({
						bottom:'0px'
					});
					buttonV.animate({
						bottom:'-'+buttonH+'px'
					});
					return false;
				});
					
			}
			
        if (b.hasClass("productImg") && d.length && h != "") {
            f = parseInt(h.replace("count_", ""), 10);
            if (f > 0) {
                a = g.attr("src").replace("_1.jpg", ".jpg");				
                if (a) {
                    c = a.replace(".jpg", "_1.jpg");
                    d.addClass("loading");																					
					g.attr("src", c);
                    if (typeof g.imagesLoaded == "function") {
                        g.imagesLoaded(function () {
                            d.removeClass("loading");
                        })
                    } else {
                        d.removeClass("loading");
                    }
					
                    g.mouseout(function () {
                        $(this).attr("src", a);
                        d.removeClass("loading");
					});		
			   }

            }
        }
    })
};

/*
function load_recently_viewed() {
    product_id = $("#productDetailsCont").attr("class").split("prod_")[1];
    $.ajax({
        url: "/pws/RecentlyViewed.ice?ProductID=" + product_id,
        beforeSend: function (a) {},
        success: function (e, g) {
            var d = $(".recentlyV"),
                a = $("li#recently_viewed"),
                f, b;
            a.append(e);
            d.infiniteCarousel({
                direction: "horizontal",
                width: 140
            });
            b = d.find(".list");
            f = b.length;
            d.addClass("total_items_" + f);
            for (var c = 0; c < f; c++) {
                b.eq(c).addClass("item_" + (c + 1))
            }
            d.find("ul:first").before('<span class="instructions">Use arrows to scroll</span>')
        },
        error: function (a, c, b) {}
    })
}

*/
