function storeCookie (name, value) 
{
	expire = 24 * 60 * 60 * 360;
	var now = new Date();
	var expiretime = new Date(now.getTime() + expire);
	document.cookie = name+"="+value+"; expires="+expiretime.toGMTString()+";";
}

function reloadPage ()
{
	var curGetParams = window.location.search;
	if (curGetParams == "")
	{
		var url = "?header=false";
		location.href = url;
	}
	else
	{
		location.reload(); 
	}

}

function setLargeText ()
{
	$.cookie ("fontSize", 1);
	reloadPage ();
}

function setSmallText ()
{
	$.cookie ("fontSize", 0);
	reloadPage ();
}

function headerLarge ()
{
	$('#functions-menu').hide ();
	//$('#dynamic-content').hide ();
	$('#header-graphic-container').css("height", 455);
	$.cookie ("homeAnimation", true, { expires: 0.001 });
	
}

function headerSmall ()
{
	$('#functions-menu').show ("normal");
	//$('#dynamic-content').show ("normal");
	$('#header-graphic-container').css("height", 285);
	$.cookie ("homeAnimation", false, { expires: 0.001 });
}

function checkMenuHeight ()
{
	
	var mainContainerHeight = $('#main-container').height(); 
	var sideHeight = $('#menu-container').height ();
	var mainHeight = $('#content-container').height ();
	
	if (sideHeight < mainHeight)
	{
		$('#menu-container').height (mainHeight)
	}
}



function applyShadowBox (elemArr)
{
	for (i in elemArr)
	{
		var elem = elemArr [i];
		
		$("" + elem + " img").each (
			function ()
			{
				
				
				var aTag = $(this).parent ();
				var link = aTag.attr ("href");
				
				var onclickAttr = "" + aTag.attr ("onclick");
				
				aTag.removeAttr ("onclick");
				aTag.removeAttr ("target");
				
				var substr = "" + onclickAttr.match (/[^&]width.*/);
				
				substr = "" + substr.match (/width=.*height=[0-9]*/, "");
				
				if (substr != null)
				{
					var valArr = substr.split (",");
					
					var width = ("" + valArr[0]).split ("=") [1];
					var height = ("" + valArr[1]).split ("=") [1];
					
					if (width > 0 && height > 0)
					{
						if (elem == ".news-single-item")
						{
							width -= 17;
							height -= 20;
						}
						
						var attr = "shadowbox[page_pics];width=" + width + ";height=" + height + ";"
						//alert ('attr ' + attr);
						aTag.attr ("rel", attr);
					}
				}
			}
		);
	}
}

/* 

	Document Ready
	
*/


$(document).ready(
	function ()
	{
	
         // Datepicker
        
        $.datepicker.setDefaults({
        	dateFormat: "d.m.yy",
        	monthNames: new Array (
        		'J&auml;nner',
        		'Februar',
        		'M&auml;rz',
        		'April',
        		'Mai',
        		'Juni',
        		'Juli',
        		'August',
        		'September',
        		'Oktober',
        		'November',
        		'Dezember'
        	),
        	dayNamesMin: new Array (
        		"Mo",
        		"Di",
        		"Mi",
        		"Do",
        		"Fr",
        		"Sa",
        		"So"
        	)
        });
	
	
		$(".spmMailAt").html ("@");
		$("#smallerFont").click (setSmallText);
		$("#largerFont").click (setLargeText);
		
		checkMenuHeight ();

		applyShadowBox (new Array (".csc-textpic", ".news-single-item"));

	}
);

Shadowbox.init({
	displayNav: true,
	continuous: true,
	language: "de-DE",
	players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv'],
	autoDimensions: true
});
