$(document).ready(function(){
  //Supersize
  jQuery.fn.supersized.options = {  
  	startwidth: 1024,  
  	startheight: 768,
  	minsize: .50,
  	slideshow: 1,
  	slideinterval: 5000  
  };
  $('#supersize').supersized(); 
       
  //Inhaltsbereich vergroessern, damit man das Hintergrundbild betrachten kann
  var insertScreenHeight = $(window).height();
  $('#containerContent').css({'margin-bottom' : insertScreenHeight});
  $('#containerHeute').css({'margin-bottom' : insertScreenHeight});

  if(BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6"){
    $('#accordion').accordion({ header: 'h3', collapsible: true}); 
    $('#accordionA').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionD').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionE').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionF').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionG').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionH').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionI').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionJ').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionK').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionL').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionM').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionN').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionO').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionP').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionQ').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionR').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionS').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionT').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionU').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionV').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionW').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionX').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionY').accordion({ header: 'h3', active: false, collapsible: true});
    $('#accordionZ').accordion({ header: 'h3', active: false, collapsible: true});
  } else {
    $('#accordion').accordion({ header: 'h3', autoHeight: false, collapsible: true }); 
    $('#accordionA').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionB').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionC').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionD').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionE').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionF').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionG').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionH').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionI').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionJ').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionK').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionL').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionM').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionN').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionO').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionP').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionQ').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionR').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionS').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionT').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionU').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionV').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionW').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionX').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionY').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
    $('#accordionZ').accordion({ header: 'h3', active: false, autoHeight: false, collapsible: true });
  }
	
	$("#containerHeute").draggable({ stack: '#holdMeTogether div', distance: 3, containment: [200,40,1000,1000] });
	$("#containerMeldungen_1").draggable({ stack: '#holdMeTogether div', distance: 3, containment: [220,110,1000,1000] });
	$("#containerMeldungen_2").draggable({ stack: '#holdMeTogether div', distance: 3, containment: [220,110,1000,1000] });
	$(".containerEinzelmeldungen").draggable({ stack: '#holdMeTogether div', distance: 3, containment: [220,110,1000,1000] });
  // entfernt den Streifen beim letzten H3
  $('#accordion h3:last').addClass('noBorder');
  $('#accordionB h3:last').addClass('noBorder');
  $('#accordion h3:first').addClass('topBorder');
  $('#accordionB h3:first').addClass('topBorder');
  // Solte eigentlich die die letzte Border beim Speilplan entfernen
  //$('table#termine tr th:last').addClass('noBorder');
  //$('table#termine tr td:last').addClass('noBorder');
  //$("th:odd").addClass('noBorder');
  //$('#forTabs tr td:last').addClass('noBorder');
  //$("th:gt(4)").addClass('noBorder');
  //$("table tbody td:even").addClass('noBorder');

  //ersetzt die Headlines in den Boxen
  $("#containerMeldungen_2 h2.news").replaceWith("<h2 class='news'>&nbsp;<span class='hideMe'> Meldungen </span></h2>");
  $("#containerHeute h2.news").replaceWith("<h2 class='news'>&nbsp;<span class='hideMe'> AKTUELL </span></h2>");
  //Termine in Streifen
  $("#termine tr:odd").addClass('stripe');
  $("#forTabs ul").addClass('showMe');
});

//Funktion fuer Scrollwerte (Array mit x,y- werten)
//Corecode - quirksmode.org
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 
		//Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		//alle anderen Internet Explorer
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
//Funktion fuer Seitengroesse (Array mit page width, height und window width, height)
//Corecode - quirksmode.org
function getPageSize(){
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		//Explorer Mac...wuerde auch in Explorer 6 Strict, Mozilla und Safari funktionieren
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		//alle Browser ausser Internet Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		//Internet Explorer 6  im Strict Modus
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		//andere Internet Explorer
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}		
	//fuer kleine Seiten mit einer kleineren Hoehe als der sichtbare Bereich
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	//fuer kleine Seiten mit einer totalen Breite kleiner als der sichtbare Bereich
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
//Funktionen fuer Flashvideos auf einer Extraebene
function openVideo(){
	breite = 570;
	hoehe = 450;
  initVideo(breite,hoehe);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	document.getElementById("abdeckung").style.height = (arrayPageSize[1] + 'px');
	document.getElementById("abdeckung").style.width = ((arrayPageSize[0]) + 'px');
	document.getElementById("abdeckung").style.display = "block";	
	document.getElementById("video").style.display = "block";
  document.getElementById("video").style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - hoehe) / 2) + 'px');
	document.getElementById("video").style.left = (((arrayPageSize[0] - breite) / 2) + 'px');
}
function closeVideo(){
	document.getElementById("video").style.display = "none";
	document.getElementById("abdeckung").style.display = "none";
}


//Browser Detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
