var overlabel = {
	applyClass : 'over-apply',
	init : function() {
		jQuery('label.over').each(function (i) {
			var id = jQuery(this).attr('for');
			var field = jQuery('#' + id);
			if (field.length <= 0) {
				return true;
			}
			jQuery(this).attr('class', overlabel.applyClass);
			if (field.attr('value') !== '' && field.attr('value') !== undefined) {
				overlabel.hide(id, true);
			}
			field.bind('focus', function() {
				overlabel.hide(id, true);
			});
			field.bind('blur', function() {
				// Fix for WebKit
				var value = field.get(0).value;
				if (value == '') {
					overlabel.hide(id, false);
				}
			});
		});
	},
	hide : function(id, status) {
		var indent = (status) ? '-9999em' : '0';
		jQuery('label[for=' + id + ']').css('text-indent', indent);
	}
}

var marginal = {
	boxes : ['store', 'weather', 'login', 'account', 'watch-list', 'newsletter'],
	cookieName : 'marginal',
	init : function() {
		var cookieTime = 60 * 24 * 365;
		var length = marginal.boxes.length;
		for (var i = 0; i < length; i++) {			
			jQuery('#cont_marginal .box.'+ marginal.boxes[i] + '.closed h3').bind('click', {box:marginal.boxes[i]}, function(e) {				
				jQuery('#cont_marginal .box.' + e.data.box + '.closed').toggleClass('away');
				jQuery('#cont_marginal .box.' + e.data.box + '.open').toggleClass('away');
				jQuery.Jookie.Initialise(marginal.cookieName, cookieTime);
				jQuery.Jookie.Set(marginal.cookieName, e.data.box, "1");
				return false;
			});
			jQuery('#cont_marginal .box.'+ marginal.boxes[i] + '.open h3').bind('click', {box:marginal.boxes[i]}, function(e) {
				jQuery('#cont_marginal .box.'+ e.data.box + '.closed').toggleClass('away');
				jQuery('#cont_marginal .box.'+ e.data.box + '.open').toggleClass('away');
				jQuery.Jookie.Initialise(marginal.cookieName, cookieTime);
				jQuery.Jookie.Set(marginal.cookieName, e.data.box, "0");
				return false;
			});
		}
	}
}

var zoom = {
	imageAreaSelector : '#inner_cont .copy .image .zoom',
	divClassZoom : 'zoomed',
	minifiyButton : '<a href="#" class="minimize">' + common.lang.minimize + '</a>',
	init : function() {
		jQuery(zoom.imageAreaSelector + ' a.maximize').bind('click', function() {
			var path = jQuery(this).attr('href');
			var currentElement = jQuery(this).closest('.image');
			var theHTML =
				'<div class="' + zoom.divClassZoom + '">'
				+ '<img src="' + path + '" alt="" />'
				+ zoom.minifiyButton
				+ '</div>'
			;
			jQuery(currentElement).prepend(theHTML);
			jQuery(currentElement).find('a.minimize').bind('click', function() {
				jQuery(currentElement).find('.zoomed').remove();
				return false;
			});
			jQuery(this).blur();
			return false;
		});
	}
}

jQuery(document).ready(function() {
	Cufon.replace('#inner_cont .main-teasers .teaser h1, #inner_cont .main-teasers .teaser h2, #inner_cont .main-teasers .teaser h3, #inner_cont .common-teasers .teaser h1, #inner_cont .common-teasers .teaser h2, #inner_cont .common-teasers .teaser h3, #inner_cont .common-teasers-wide .teaser h3, #inner_cont .common-teasers-wide .linkbox h3, #inner_cont .coverflow-intro .linkbox h2, #inner_cont .producttsr_btn a,#specialtsr_content h3.teaser, #quicktsr_content h4.teaser, #cont_marginal .box h3, #map .control h2.highlight, #weather h2.teaser');
	overlabel.init();
	marginal.init();
	zoom.init();
	removeEmptyCatUl.remove();

jQuery(".common-teasers .teaser").each(function() {
    if(jQuery.browser.msie && jQuery.browser.version == "7.0") {
        if(jQuery(this).html().length <= 1) {
            jQuery(this).css("width", "auto");
        }
    }
});


});



function textCounter(field, /*cntfield,*/ maxlimit, errorEl, errorMessage) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
		if (errorEl != null) {
			errorEl.innerHTML = errorMessage;
		}
	} else {
		errorEl.innerHTML = "";
	}
	//else {
		//cntfield.value = maxlimit - field.value.length;
	//}
}

var removeEmptyCatUl = {
	remove : function() {		
		jQuery("#categoryNavigation ul").each(function(i, el) {
			// Remove white space
			var html = jQuery(el).html().replace(/\s+/, "");
	
		    // Check if element is :empty or length of html is zero
		    if (jQuery(el).is(":empty") || html.length == 0)
		    	jQuery(el).remove();
		});
	}
}

function openPopup(url, name, parameter){
	 pop = window.open(url, name, parameter);
     pop.focus();
}

/*
by maik.finsterbusch@arithnea.de
100511
*/
function renameMarketByJobs(){
	if(jQuery('#standorte > b').html() == 'Vorlagelogistikzentrum HB' && document.URL.match(/&market=999/g) !== null){
		jQuery('#standorte > b').html('Konzernzentrale HORNBACH');
	}
}

jQuery(document).ready(function() {
	renameMarketByJobs();
});

