var imageSwitcher;
function initJS() {
	clear_PLZbox();
	clear_naviPLZbox();
	setInputBG();
	imageSwitcher = setInterval( "switchImages()", 7000 );
	//fix_IE_submit_bug(); fixt Absenden im IE, verhindert aber Absenden der PLZ Boxen bei Enter in allen Browsern
}

function toggleDebug() {
	$('#debugMessages').toggle();
}

function hideDiv(div)
{
	Effect.Fade(div, { duration: 1.0 });
}

function redirectConfirm(url, question) {
	var box = window.confirm(question);
	if (box == true) {
		window.location.href = url;
	}	
}

/**
* Registriert die Aktzions-PLZ-Box und das Clear Event
*/
function clear_naviPLZbox() {
	$('#navi_plz_input').click(function() {
		$(this).val("");
		$(this).css("background-position", "0px 21px");
		$(this).css("color", "#338c26");
		$(this).css("text-align", "center");	
		
		$('#navi_plz').css("background-position", "0px 35px");			
		$('#navi_plz').css("color", "#fff");	
	});
	$('#navi_plz_input').blur(function() {
		if($(this).val() == "") {		
			$(this).val("Willst du sparen? PLZ");
			$(this).css("color", "#c1c0c0");
			$(this).css("text-align", "left");

			$('#navi_plz').css("background-position", "0px 0px");			
			$('#navi_plz').css("color", "#000");			
		}
	});		
}

/**
* Registriert die Haupt-PLZ-Box und das Clear Event
*/
function clear_PLZbox() {
	$('#plz_input').click(function() {
		$(this).val("");
		$(this).css("font-size", "41px");
		$(this).css("color", "#338c26");
		$(this).css("letter-spacing", "12px");		
	});	
	$('#plz_input').blur(function() {
		if($(this).val() == "") {		
			$(this).val("Postleitzahl");
			$(this).css("font-size", "32px");
			$(this).css("color", "#cdcccc");
			$(this).css("letter-spacing", "0px");
		}
	});	
}


/**
* Setzt den Hintergrund für Inputs bei Click
*/
function setInputBG() {
    $("#sidebar input[type='text']").focus(function(){
		$(this).css("background", "url('" + rootdir + "res/images/input_act.png') no-repeat");	
    });
    $("#sidebar input[type='text']").blur(function(){
		$(this).css("background", "#fff");	
    });		
    $("#sidebar input[type='password']").focus(function(){
		$(this).css("background", "url('" + rootdir + "res/images/input_act.png') no-repeat");
    });	
    $("#sidebar input[type='password']").blur(function(){
		$(this).css("background", "#fff");	
    });		
}


/**
* wechselt die Bilder im Header
*/
var switchImageCount = 2;
var switchImageMax = 10;

function switchImages() {
  var $alt = $('#headerImage div.obersteebene');

  if($alt.next().length)
    var $neu = $alt.next();
  else
    var $neu = $('#headerImage div:first');

  $alt.addClass('mittlereebene');
  $alt.removeClass('obersteebene');
  $neu.css({opacity: 0.0});
  $neu.addClass('obersteebene');

  $neu.animate({opacity: 1.0}, 3000, function() {
    $alt.removeClass('mittlereebene');
		if (switchImageCount < switchImageMax)
		{
			switchImageCount++;
			$("#headerImage").append('<div class="switch_pics switch_'+switchImageCount+'"></div>');
  	}
	});
		
}


/**
* Zwingt den IE, das Submit Event auf Buttons zu setzen, die nach Laden der Seite noch nicht existieren
*/
function fix_IE_submit_bug() {
	var browserName=navigator.appName; 	
	if (browserName=="Microsoft Internet Explorer") {	
		$('input').keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents('form').submit();
				return false;
			}
		});
	}
}


