// Beim Start wird die HomeSeite geladen
$(document).ready( function() {		
	mainmenu();						
	$(document).pngFix();
	$('#content').load('content/home.html');
	$('#footerRefLogout').hide();
	
	// Dialog Link
	$('#loginLink').click(function(){
		$('#dialog').dialog('open');
		return false;
	});
	
	$('#logoutLink').click( function(){
		 $.ajax({
			type: "POST",
			url: "cms/logout.php",
			success: function(msg){
				if(msg="success"){
					$('#footerRefLogin').show();
					$('#footerRefLogout').hide();
					$('#nav').show();
					$('#content').load('content/home.html');
				}
			}
		 });
	}); 
});

var monate = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");

// Fügt entsprechende Styles für Buttons hinzu
function styleButtons() {
	$(".fg-button:not(.ui-state-disabled)")
	.hover(
		function(){ $(this).addClass("ui-state-hover"); },
		function(){ $(this).removeClass("ui-state-hover"); }
	)
	.mousedown(function(){
		$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
		if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
		else { $(this).addClass("ui-state-active"); }	
	})
	.mouseup(function(){
		if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
			$(this).removeClass("ui-state-active");
		}
	});
}

function convertDate(dateString) {
	return dateString.substring(8,10)+"."+dateString.substring(5,7)+"."+dateString.substring(2,4);
}

function convert2Date(dateString, dateString2) {
	return dateString.substring(8,10)+".-"+dateString2.substring(8,10)+"."+dateString.substring(5,7)+"."+dateString.substring(2,4);
}

function getTermine(monatInt){
	var htmlText = "";
	$.ajax({
		type: "POST",
		url: "cms/getTermineNachMonat.php",
		data: "monat="+(monatInt),
		success: function(msg){
			alert(msg);
			if(msg.length!=0){
				var eintraege=msg.split("|");
				for(var i=0;i<=(eintraege.length-2);i++){
					var col_array = eintraege[i].split("&");
					if(col_array[6]=="0000-00-00"){
						htmlText = htmlText + "<b>"+convertDate(col_array[1])+" - "+col_array[2]+"</b> ";
					} else {
						htmlText = htmlText + "<b>"+convert2Date(col_array[1], col_array[6])+" - "+col_array[2]+"</b> ";
					}
					if(col_array[5].length==0){
						htmlText = htmlText + col_array[3]+" / "+col_array[4]+"<br />";
					} else {
						htmlText = htmlText + col_array[3]+" / "+col_array[4]+" / Datei: "+col_array[5]+"<br />";
					}
				}
			}
		}
	});
	return htmlText;
}

// Dropdown Menu
function mainmenu(){
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(
			function(){
				$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
			},function(){
				$(this).find('ul:first').css({visibility: "hidden"});
			}
	);
}

// Popup mit Parameterübergabe
function openMessage(text, title, path) {
	$('<div title='+title+'>'+text+'</div>').dialog({
				title: title, 
				buttons: {
					Ok: function() {$(this).dialog("destroy"); 
						$('#content').load('content/home.html');
					}
				},
				close: function () { $(this).dialog("destroy"); }
	});
	$("button").removeClass('ui-state-focus');
}