var swbi_bibi = {
	init : function() {
		swbi_bibi.initFontSize();
		swbi_bibi.initEventCalendar();
		swbi_bibi.initLastChanged();
		
		$('.jsShow').show();
		$('.jsHide').hide();

		$(".moduleSearchresult a.link").hover( function() {
			$(this).parents().filter('li').addClass('hover');
		}, function() {
			$(this).parents().filter('li').removeClass('hover');
		});

		$("#header .small").click( function() {
			swbi_bibi.setFontSize("75", true);
		});
		$("#header .medium").click( function() {
			swbi_bibi.setFontSize("85", true);
		});
		$("#header .big").click( function() {
			swbi_bibi.setFontSize("95", true);
		});
		$("#eventform").submit( function() {
			var value = $("#eventsearch").val();
			if (typeof value != null && value != "") {
				location.href = value;
			}
		});
		$("input.filter_user_unlocked").click(function(){
			$('.users .user_locked').show()
			$('.users .user_unlocked').hide()
		});
		
		$("input.filter_user_locked").click(function(){
			$('.users .user_unlocked').show()
			$('.users .user_locked').hide()
		});
		
		$("input.filter_user_all").click(function(){
			$('.users .user_unlocked').show()
			$('.users .user_locked').show()
		});
		
		$("input.filter_recension_unlocked").click(function(){
			$('.recensions .recension_locked').show()
			$('.recensions .recension_unlocked').hide()
		});
		
		$("input.filter_recension_locked").click(function(){
			$('.recensions .recension_unlocked').show()
			$('.recensions .recension_locked').hide()
		});
		
		$("input.filter_recension_all").click(function(){
			$('.recensions .recension_unlocked').show()
			$('.recensions .recension_locked').show()
		});
	},
	initLastChanged : function(){
		var lastChanged = document.lastModified;
		if (lastChanged.indexOf('/') > -1) {
			lastChanged = lastChanged.split(" ")[0];
			var splitted = lastChanged.split("/");
			lastChanged = splitted[1] + "." + splitted[0] + "." + splitted[2];
		}
		$("#lastchanged").html("Letzte &Auml;nderung: " + lastChanged);
	},
	initFontSize : function(){
		var cook = swbi_bibi.getCookie('swbiBibiFontSize');
		if (cook) {
			swbi_bibi.setFontSize(cook, false);
		} else {
			swbi_bibi.setFontSize('75', false);
		}
	},
	setFontSize : function(size, animate) {
		var currentSize = $("body").css("font-size");
		if ( size + "%" == currentSize ) return;
		if (animate) {
			$("body").animate( {
				fontSize :size + "%"
			}, 1000);
		} else {
			$("body").css("font-size", size + "%");
		}
		swbi_bibi.scaleHeaderImage( size, animate );
		document.cookie = "swbiBibiFontSize=" + size;
	},
	scaleHeaderImage : function( size, animate ) {
		
		var theImage = $(".logo img")[1];
		var iwidth = 0;
		var iheight = 0;
		if ( size == "75" ) {
			 iwidth = 760;
			 iheight = 138;
		} else if ( size == "85" ) {
			 iwidth = parseInt( 760 * 1.13333 );
			 if ( !$.browser.msie ) iwidth = iwidth - 3;
			 iheight = parseInt( 138 * 1.13333 );
		} else if ( size == "95" ) {
			 iwidth = parseInt( 760 * 1.26667 );
			 if ( !$.browser.msie ) iwidth = iwidth - 4;
			 iheight = parseInt( 138 * 1.26667 );
		}
		//alert( iwidth + ", " + iheight );		
		if ( iwidth == 0 || isNaN( iwidth ) || iheight == 0 || isNaN( iheight ) ) return;
		if ( animate ) {
			 $( theImage ).animate( { width: iwidth + "px", height: iheight + "px" }, 1000 );
		} else {
			 $( theImage ).css( "width", iwidth + "px" );
			 $( theImage ).css( "height", iheight + "px" );
		}
		
	},
	initEventCalendar : function() {
		var opts = "";
		$("#eventcalender li a").each( function(index) {
			var elem = $(this);
			var href = elem.attr("href");
			var text = elem.text();
			opts += "<option value=\"" + href + "\">" + text + "</option>\n";
		});
		$("#eventsearch").html(opts);
	},
	getCookie : function(name) {
		var allCookies = document.cookie;
		var cookieArr = allCookies.split(';');
		for ( var i = 0; i < cookieArr.length; i++) {
			if (cookieArr[i].split('=')[0] == name) {
				var cookieValue = cookieArr[i].split('=');
				cookieValue = unescape(cookieValue[1]);
				return cookieValue;
			}
		}
		return false;
	}
}

function submitEventCalendar() {
	location.href = $("#eventsearch").val();
	return false;
}

$(swbi_bibi.init);