﻿/*
 * runOnLoad.js: portable registration for onload event handlers.
 * 
 * This module defines a single runOnLoad() function for portably registering
 * functions that can be safely invoked only when the document is fully loaded
 * and the DOM is available.
 *
 * Functions registered with runOnLoad() will not be passed any arguments when
 * invoked. They will not be invoked as a method of any meaningful object, and
 * the this keyword should not be used.  Functions registered with runOnLoad()
 * will be invoked in the order in which they were registered.  There is no
 * way to deregister a function once it has been passed to runOnLoad().
 *
 * In old browsers that do not support addEventListener() or attachEvent(),
 * this function relies on the DOM Level 0 window.onload property and will not
 * work correctly when used in documents that set the onload attribute
 * of their <body> or <frameset> tags.
 */
function runOnLoad(f) {
    if (runOnLoad.loaded) f();    // If already loaded, just invoke f() now.
    else runOnLoad.funcs.push(f); // Otherwise, store it for later
}

runOnLoad.funcs = []; // The array of functions to call when the document loads
runOnLoad.loaded = false; // The functions have not been run yet.

// Run all registered functions in the order in which they were registered.
// It is safe to call runOnLoad.run() more than once: invocations after the
// first do nothing. It is safe for an initialization function to call
// runOnLoad() to register another function.
runOnLoad.run = function() {
    if (runOnLoad.loaded) return;  // If we've already run, do nothing

    for(var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch(e) { /* An exception in one function shouldn't stop the rest */ }
    }
    
    runOnLoad.loaded = true; // Remember that we've already run once.
    delete runOnLoad.funcs;  // But don't remember the functions themselves.
    delete runOnLoad.run;    // And forget about this function too!
};

// Register runOnLoad.run() as the onload event handler for the window
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;


jQuery(document).ready(function() {	
	runOnLoad(function(){
		var login_height = $('#login').height();
		var user_height = $('#user').height();
		if (login_height == null) {
			$('#main_navigation').css("margin-top", user_height + 29);
			var mainnavigation_height = $('#main_navigation').height() + user_height + 36;				
		}
		else {
			$('#main_navigation').css("margin-top", login_height + 29);		
			var mainnavigation_height = $('#main_navigation').height() + login_height + 36;
		}
		
		var subnavigation_height = $('#sub_navigation').height();	
		
		var content_height = $('#content').height();	
		if (mainnavigation_height > content_height)
		{

			if ($.browser.msie) {
				$('#footer').css('margin-top', mainnavigation_height - content_height + 14);
			}
			else {		 
				$('#footer').css('margin-top', mainnavigation_height - content_height);
			}
		}
		if (subnavigation_height > mainnavigation_height && subnavigation_height > content_height ) {
			$('#footer').css('margin-top', subnavigation_height - content_height + 68);
		}
		
		$('#footer').css('display', 'block');
				
		var quicknavigation_width = $('#quick_navigation').width();
		$('#quick_navigation').css('margin-left', (990 - quicknavigation_width) / 2);	
		
		if ($('body').hasClass("shop_2237") == true) {
			$('#subsets').addClass("b1");	
		}	
		if ($('body').hasClass("shop_2211") == true) {
			$('#subsets').addClass("b2");		
		}	
		if ($('body').hasClass("shop_2239") == true) {
			$('#subsets').addClass("b3");		
		}	
		if ($('body').hasClass("shop_2430") == true) {
			$('#subsets').addClass("b4");		
		}
	});
	/*document.createElement($("tr".attr("class","hersteller")));
	$($("#main_navigation td.categories td").get(0)).after($("tr.hersteller"));
	$("#main_navigation tr.manuf").append($("#main_navigation td.manufacturers"));*/
	$($("#main_navigation li.categories li").get(0)).after($("#main_navigation li.manufacturers"));
	
	if ($('#ctl00_ltlCompanyHotline').text() != '') {
		$('#content_bar').css("display", "block");
	}

	$('#ctl00_txtSearch').val("Wonach suchen Sie?");
	$('#ctl00_txtSearch').css('color', '#6699CC');
	$('#ctl00_txtSearch').css('font-style', 'italic');
	
	$('#ctl00_txtSearch').focus(function() {
		if ($('#ctl00_txtSearch').val() == "Wonach suchen Sie?") { 
		$('#ctl00_txtSearch').val("");
		$('#ctl00_txtSearch').css('color', '#000');
		$('#ctl00_txtSearch').css('font-style', 'normal');
	}
	});
	$('#ctl00_txtSearch').blur(function() {
		if ($('#ctl00_txtSearch').val() == "") {
			$('#ctl00_txtSearch').val("Wonach suchen Sie?");
			$('#ctl00_txtSearch').css('color', '#6699CC');
			$('#ctl00_txtSearch').css('font-style', 'italic');
		}
	});
	
		
	$('.login_user').val('Benutzername');
	$('.login_user').css('color', '#999');

	
	$('.login_user').focus(function() {	
		$(this).css('color', '#000');	
		if ($(this).val() == 'Benutzername') {
			$(this).val('');
		}					
	});	
	$('.login_user').blur(function() {
		if ($(this).val() == '') {
			$(this).css('color', '#999');
			$(this).val('Benutzername');
		}	
	});
	
	$('.login_password').focus(function() {	
		if ($(this).val() == 'Passwort') {			
			$(this).css('color', '#000');		
			$(this).val('');
			}
	});
	$('.login_password').blur(function() {
		if ($(this).val() == '') {
			$(this).css('color', '#999');
			$(this).val('Passwort');
		}	
	});
	var login = document.createElement('input');
	$(login).attr('type', 'text');
	$(login).attr('id', $('.login_password').attr('id'));
	$(login).attr('class', $('.login_password').attr('class'));
	$(login).attr('name', $('.login_password').attr('name'));
	$(login).css('color', '#999');
	$(login).val('Passwort');
	$(login).focus(function() {
		var login = document.createElement('input');
		$(login).attr('type', 'password');
		$(login).attr('id', $('.login_password').attr('id'));
		$(login).attr('class', $('.login_password').attr('class'));
		$(login).attr('name', $('.login_password').attr('name'));
		$(login).css('color', '#000');
		$(login).val('');

		$(this).remove();

		$('.login_user').after(login);
		window.setTimeout("$('.login_password').focus();", 100);
	});
	$('.login_password').remove();
	$('.login_user').after(login);
	

});
