$(document).ready(function() {
	// jQuery-Accordion (#1: oberes)
	//$("#loginbox li.drawer div:not(:first)").hide();
	//$("#loginbox li.drawer h4 a:first").addClass("open");
	$("#loginbox h4.drawer-handle a").click(function() {
		var btn = $("#loginbox li.drawer div:visible a.WhiteButton");
		if (btn.length) {
			btn.css('visibility', 'hidden');
		}
		$("#loginbox li.drawer input").css('visibility', 'hidden');
		$("#loginbox li.drawer div:visible").slideUp();
		$("#loginbox h4.drawer-handle a.open").removeClass("open");		
		$(this).parent().next().slideDown(function() {
			var btn = $("#loginbox li.drawer div:visible a.WhiteButton");
		if (btn.length) {
			btn.css('visibility', 'visible');
		}
		$("#loginbox li.drawer input").css('visibility', 'visible');
		});
		$(this).addClass("open");
		return false;
	});

$("#loginbox li.drawer a.WhiteButton").css('visibility', 'hidden');
//$("#loginbox li.drawer input").css('visibility', 'hidden');

	// jQuery-Accordion (#2: unteres)
	//wird im baustein festgelegt welches als standard aufgeklappt ist
	//$("#teaserbox li.drawer div:not(:first)").hide();
	//$("#teaserbox li.drawer h4 a:first").addClass("open");
	$("#teaserbox h4.drawer-handle a").click(function() {
		$("#teaserbox li.drawer div:visible").slideUp();
		$("#teaserbox h4.drawer-handle a.open").removeClass("open");		
		$(this).parent().next().slideDown();
		$(this).addClass("open");
		return false;
	});
	
	/*
	var intRandomStartIndex = parseInt(Math.random()* ($("#logoswitcher li").children().length-1));
	$("#logoswitcher li").hide();
	el = $("#logoswitcher li:eq(" + intRandomStartIndex + ")");
	el.show();
	*/
	
	logoswitcher.currentElementIndex = parseInt(Math.random()* (logoswitcher.elements.length-1));
	logoswitcher.firstElement = $("#logoswitcher li:eq(0)");
	logoswitcher.firstImage = $("#logoswitcher li:eq(0) img");
	logoswitcher.secondElement = $("#logoswitcher li:eq(1)");
	logoswitcher.secondImage = $("#logoswitcher li:eq(1) img");
	$("#logoswitcher li").hide();
	logoswitcher.firstElement.show();
	
	logoswitcher.run();
	
	// Textfeld-Inputwerte zuruecksetzen
	//Reset Fields:
	var fields = [document.getElementById('login_user_email'), document.getElementById('login_user_pwd')];
	for(i in fields) {
		if(fields[i]) {
			fields[i].onfocus = function() {
				if (this.value == this.defaultValue) {
					this.value = "";
				}
			};
			fields[i].onblur = function() {
				if (this.value == "") {
					this.value = this.defaultValue;
				}
			};
		}
	}
});

var logoswitcher = {
 	run : function(){
		//el.fadeOut("slow");
		/*
		el.slideUp("normal");

		var nex = el.next();
		if(!nex.is("li")) {
			nex = $("#logoswitcher li:first");
		}
		
		//nex.slideDown("slow", function() {
		nex.fadeIn("slow", function() {
			setTimeout(function() {
				logoswitcher.run(nex);
			}, 2000);
		});
		
		*/
		if(logoswitcher.flgFirst) {
			logoswitcher.firstElement.slideUp("normal");
			logoswitcher.secondElement.fadeIn("slow", function() {
				setTimeout(function() {
				  logoswitcher.firstImage.attr('src', logoswitcher.getNextImageUrl());
					logoswitcher.run();
				}, 2000);
			});
		} else {
			logoswitcher.secondElement.slideUp("normal");
			logoswitcher.firstElement.fadeIn("slow", function() {
				setTimeout(function() {
				  logoswitcher.secondImage.attr('src', logoswitcher.getNextImageUrl());
					logoswitcher.run();
				}, 2000);
			});
		}
		logoswitcher.flgFirst = !logoswitcher.flgFirst;
	},
	
	flgFirst : true,
	
	elements : [],
	
	getNextImageUrl : function() {
	  image = logoswitcher.elements[logoswitcher.currentElementIndex];
		if(logoswitcher.elements.length > logoswitcher.currentElementIndex) {
		  logoswitcher.currentElementIndex++;
		} else {
			logoswitcher.currentElementIndex = 0;
		}
		if(!image) return logoswitcher.firstImage.attr('src');
		return(image);
	}
};
