function styleSharBtn(){
    if ($(".FBConnectButton_Small .FBConnectButton_Text").length > 0) {
        if ($.browser.msie) {
            $(".FBConnectButton_Small .FBConnectButton_Text").css({
                "margin-left": "17px",
                "padding": "0px 6px 5px 6px"
            })
        }
        else {
            $(".FBConnectButton_Small .FBConnectButton_Text").css({
                "margin-left": "17px",
                "padding": "3px 6px 2px 6px"
            })
        }
        $(".FBConnectButton_Text").text("Del");
    }
    else {
        setTimeout("styleSharBtn()", "150");
    }
}

$(function() {
	$("#ShopMainLayOutTable .FrontPage_TD .product").each(function(){
		var $product = $(this);
		var link = $product.find(".name a").attr("href");
		link = link + "?rawxml=1";
		$.ajax({
			url:link,
			dataType:"xml",
			success:function(data){
				var $xml = $(data);
				stock = $xml.find("ProductInfo > StockCount").text();
				stock = parseInt(stock,10);
				if(stock > 1000){
					$product.find(".stock").remove();
					$("#ShopMainLayOutTable .deliveryInfo").remove();
				} else if (stock >= 10) {
					$product.find(".stock span").text("10+");
				} else {
					$product.find(".stock span").text(stock);
				}
				if(stock < 1){
					$("#ShopMainLayOutTable .deliveryInfo").remove();
				}
			}
		})
	});

	//Styrer lagerstatus og leveringstekst på vareliste og varekort
	$("#ShopMainLayOutTable #ProductList_TD .stock span, .stock span").each(function () {
		var $stockNum = $(this);
		var stock = parseInt($stockNum.text(),10);
		
		if(stock > 1000){
			if(location.href.indexOf("p.html") != -1){// Fjerner lagerstatus og bestil inden tekst på varekortet
				$(this).parent().remove(); // Fjerner lager status
				$(this).parent().next().css("margin-top", "20px");
				$("#ShopMainLayOutTable .deliveryInfo").css('visibility','hidden');//Fjerner bestil inden tekst
			} else {// Fjerner lagerstatus og bestil inden på varelisten
				$(this).parent().next().remove();
				$(this).parent().remove(); // Fjerner lager status
				$(this).parent().next().css("margin-top", "10px");
				$(this).parent().next().css('visibility','hidden');//Fjerner bestil inden tekst
			}
		} 
		
		//Ændre lagerstatus til 10+ hvis der er mere en 10 på lager
		if (stock > 10) {
			$stockNum.text("10+");
		} 
		
		if(stock < 1){
			if(location.href.indexOf("p.html") != -1){// Fjerner lagerstatus og bestil inden tekst på varekortet
				$(this).parent().remove(); // Fjerner lager status
				$(this).parent().next().css("margin-top", "20px");
				$("#ShopMainLayOutTable .deliveryInfo").css('visibility','hidden');//Fjerner bestil inden tekst
			} else {// Fjerner lagerstatus og bestil inden på varelisten
				$(this).parent().next().remove();
				$(this).parent().remove(); // Fjerner lager status
				$(this).parent().next().css("margin-top", "10px");
				$(this).parent().next().css('visibility','hidden');//Fjerner bestil inden tekst
			}
		}
	});
	
	$(".relatedProduct .Related_BuyButton_IMG").each(function(){
		$(this).attr("src","/images/design/da/productCard/addToBasket.gif");
	});
	
	if($(".socialMedia").length > 0){
        time = new Date();
        $(".socialMedia").load("/includes/like.asp?relid="+escape(location.href)+"&_="+time.getTime(), function(){
            setTimeout("styleSharBtn()", "300");
        });
    }
});

