/* Hier darf Lutz spielen */

jQuery(document).ready(function () {
    jQuery(".BlogListItem .PublishInfo").each(function () {
		var t = jQuery(this);
		t.html(t.html().replace(/Ver[^ ]*ffentlicht am ([^ ]*) [^ ]* von .*/,'$1'));
	});
	jQuery(".BlogListItem > h2 > a").css("font-weight", "bold");
	if(jQuery(".ContentAreaWrapper > .CategoryImage").length == 0) {
		jQuery(".ContentAreaWrapper").prepend("<div class='CategoryImage'><img src='/WebRoot/Store/Shops/Hanusch/4E78/818A/F566/E512/8CCE/D911/C0AC/D406/balken_m.jpg'/></div>");
	}
	jQuery(".ContentAreaWrapper > h3").has(".BreadcrumbItem").insertAfter(".ContentAreaWrapper > .CategoryImage");
	
	jQuery("div > h1").parent().siblings("h1").hide();
	
	jQuery(".NavBarTop").css("margin-bottom", "5px");
	jQuery("ul.HorizontalDisplay").css({
		display: "block",
		paddingTop: jQuery(".NavBarTop").height() - jQuery("ul.HorizontalDisplay").height()
	}).find("li:first").css({
		paddingLeft: '3px'
	});
	
	var currentcollector;
	var	harmonika;
	jQuery(".Article > div").has("h5").children().each(function () {
		var t = jQuery(this);
		if(this.tagName.toLowerCase() == "h5") {
			if(!harmonika) {
				harmonika = jQuery("<div class='harmonika'/>");
				t.before(harmonika);
			}
			currentcollector = jQuery("<div/>");
			harmonika.append(t).append(currentcollector);
		} else if(currentcollector) {
			t.appendTo(currentcollector);
		}
	});
	jQuery(".harmonika > h5").css({
		cursor: 'pointer'
	}).click(function () {
		var t = jQuery(this);
		t.siblings("div").slideUp('fast');
		t.next().slideDown('slow');
	}).first().click();
	
	jQuery("#SelectVariationForm").insertBefore(".FullSize > .Price");
	jQuery(".FullSize > div:contains('Lieferzeitraum')").insertAfter(".FullSize > .Price");
	jQuery(".FullSize .Icon").each(function() {
		var t = jQuery(this).parent();
		t.text(t.text().replace(/ist sofort/,'ist'));
		t.insertAfter(".FullSize > .Price");
	});
	jQuery(".FullSize > .Price").css({
	   textAlign: "left",
	   marginTop: "1em"
	});
	jQuery(".FullSize > .Links").css({
	   float: 'right',
	   borderLeft: '1px solid #ddd',
	   paddingLeft: '10px',
	   marginLeft: '30px',
	   width: '160px'
	}).insertAfter(".FullSize > .ClearBoth:first")
	.append(jQuery(".SocialBookmarks"))
	.append(jQuery("#ShowTwitterButtons"))
	.append(jQuery("#ShowFacebookButtons"))
	.find("br").remove();
	jQuery(".FullSize > .Links > a").wrap("<div/>");
	jQuery("#ViewProductPrint").parent().css("padding-top", "1em");
	jQuery("#ShowTwitterButtons").removeClass("FloatLeft").addClass("FloatRight");
	jQuery("#ShowFacebookButtons").removeClass("FloatLeft").css("width", "75px");
	jQuery(".SocialWeb").css({
		margin: '10px auto 0 auto',
		display: 'block',
		float: 'none'
	});
	jQuery(".SocialWeb > iframe").css({
		margin: '0 auto 0 auto',
		display: 'block',
		float: 'none'
	});
	jQuery(".SocialBookmarks").css("margin-top", "1em");
	if(gapi.plusone.go) {
		jQuery("#ShowFacebookButtons").before("<div class='SocialWeb FloatRight' id='ShowGooglePlus'><g:plusone count='false' size='small'/></div>");
		gapi.plusone.go();
	}
	var tabs = jQuery("<div><div id='tabheading'/><div id='tabcontent'/></div>").appendTo(".FullSize");
	var currenttab = 0;
	jQuery(".FullSize > div").has("h6").children().each(function () {
		var t = jQuery(this);
		if(this.tagName.toLowerCase() == "h6") {
			currenttab = currenttab + 1;
			t.attr("for", "tab_"+currenttab).appendTo("#tabheading");
			jQuery("#tabcontent").append("<div id='tab_"+currenttab+"'/>");
		} else if(currenttab > 0) {
			t.appendTo("#tab_"+currenttab);
		}
	});
	jQuery(".UserAttributes").each(function() {
		var t = jQuery(this).parent("div");
		var h = t.prev("h2");
		if(t.length > 0 && h.length > 0) {
			currenttab = currenttab + 1;
			jQuery("<h6 for='tab_"+currenttab+"'/>").text(h.text()).appendTo("#tabheading");
			t.attr("id","tab_"+currenttab).appendTo("#tabcontent");
			h.remove();
		}
	});
	jQuery(".VariationsTable").each(function() {
		var t = jQuery(this);
		var h = t.prev("h2");
		if(t.length > 0 && h.length > 0) {
			currenttab = currenttab + 1;
			jQuery("<h6 for='tab_"+currenttab+"'/>").text(h.text()).appendTo("#tabheading");
			t.wrap("<div id='tab_"+currenttab+"'/>").parent().appendTo("#tabcontent");
			h.remove();
			t.find("tr").has("th").remove();
			t.children().children().each(function () {
				jQuery(this).children().each(function (i) {
					switch(i) {
						case 1: case 2: case 4:
							jQuery(this).remove();
					}
				});
			});
		}
	});
	jQuery("#tabcontent").css({
		border: '1px solid #eee',
		borderTop: 'none',
		padding: '.5em .2em .2em .2em'
	}).children().hide();
	jQuery("#tabcontent ul").css("padding", ".2em 0 .2em 2em");
	jQuery("#tabheading").css({
	    clear: "both",
		borderBottom: '1px solid #eee',
		paddingBottom: '4px',
		marginTop: '3em'
	}).children().css({
		border: '1px solid #eee',
		borderBottom: 'none',
		display: 'inline',
		padding: '4px',
		marginRight: '.2em',
		fontSize: '14px',
		cursor: 'pointer'
	}).click(function() {
		var t = jQuery(this);
		jQuery("#tabheading > h6").css('background', 'transparent');
		t.css('background', '#eee');
		jQuery("#tabcontent > div").hide();
		jQuery("#"+t.attr('for')).show();
	}).first().click();
	jQuery(".CrossellingInfoArea .AddToBasketForm").remove();
	jQuery(".CrossellingInfoArea .TaxAndShippingInfo").remove();
	
	jQuery("h6:contains('Weitere Produktinformationen')").text('Details');
	
	jQuery("#basketForm_standalone").insertBefore(".TaxAndShippingInfo");
	
	var newnavi = jQuery("<div id='navbartab'>" +
			"<div class='BoxContainer'>" +
				"<div class='ContextBoxHead' />" +
				"<div class='ContextBoxBody' />" +
			"</div>"+
		"</div>").insertBefore(".NavBarLeft .NavBarElement0");
	var currenttab = 0;
	jQuery(".NavBarLeft .ContextBox").has(".ContextBoxHead").each(function() {
		var t = jQuery(this);
		currenttab = currenttab + 1;
		t.find(".ContextBoxHead > span").attr('for', 'navbartab-'+currenttab)
		 .appendTo("#navbartab .ContextBoxHead")
		 .css({
			display: 'inline-block',
			width: '50%',
			textAlign: 'center',
			cursor: 'pointer',
			paddingBottom: '5px'
		});
		t.find(".BoxContainer > .ContextBoxBody").removeClass('ContextBoxBody').attr('navid', 'navbartab-'+currenttab)
		 .appendTo("#navbartab .ContextBoxBody");
		t.remove();
	});
	jQuery("#navbartab").addClass('ContextBox').addClass('NavBarElement0').css({
		border: '1px solid #ddd',
		minHeight: jQuery("#navbartab *[navid=navbartab-1]").css("height")
	});
	jQuery("#navbartab .ContextBoxHead").css({
		background: "none",
		padding: '0'
	});
	jQuery("#navbartab .ContextBoxHead > span").click(function () {
		jQuery("#navbartab .ContextBoxBody > *[navid]").hide();
		jQuery("#navbartab *[navid="+jQuery(this).attr('for')+"]").show();
		jQuery(this).css("background", "none").siblings().css("background", "#ddd");
	}).first().click();
	jQuery(".ContextBoxHead > span:contains('Warenkorb')").html('<img src="/WebRoot/Store/Shops/Hanusch/MediaGallery/Pictogramme/warenkorb.png"/>');
	jQuery(".ContextBoxHead > span:contains('Kontakt')").html('<img src="/WebRoot/Store/Shops/Hanusch/MediaGallery/Pictogramme/kontakt.png"/>');
	
	var search = jQuery(".SearchElement").first();
	search.parent().css("padding-left", search.css("width"));
	search.prependTo(".NavBarLeft");
	search.css({
		paddingTop: '3px',
		borderTop: '1px solid #ddd',
		borderBottom: '1px solid #ddd',
		paddingLeft: '0',
		height: jQuery(".CategoryImage img").height() - 2
	});
	var referenz = jQuery("#slider, .ImgComplete img").first();
	if(referenz.length > 0) {
		jQuery(".CategoryImage").hide();
	} else {
		referenz = jQuery(".CategoryImage img").first();
	}
	jQuery(".NavBarLeft").css({
		marginTop: referenz.offset().top - jQuery(".SearchElement").offset().top,
		width: '140px'
	});
	jQuery(".PropertyContainer").css("padding", "0");
	var tab = jQuery("#navbartab");
	tab.css("min-height", referenz.height() - (tab.offset().top - referenz.offset().top) - 2);
	
	if(document.URL.match(/\/Shops\/Hanusch\/Categories\/Shop$/i)) {
		jQuery(".CategoryBase").siblings().insertBefore(".CategoryBaseTable table:last");
	}
	if(document.URL.match(/\/Shops\/Hanusch\/Categories$/i)) {
		jQuery(".CategoryImage").hide();
	}
	
	
});
