// JavaScript Document

//if (!($.browser.msie && $.browser.version < 6)) { 	

	// initialize page
	$(document).ready(function () {
//		$("#contentContainerStart").load("tabPages/tabNews.php"); commented by Vel
		setupDropDown();
		setupCollapsableItems();
		replaceHeaders();
		$("#contentContainerStart").load("/dynamic/pages/home", null, onLoad);
		$("#mainContent").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.7});
		$("#sponsorContainer").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.7});
		$("#bannerTickets").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.7});
		$("#bannerZo").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.7});
				
		/// ie6 detection fix
		if ( document.all && !window.opera && !window.XMLHttpRequest && $.browser.msie ){
			var isIE6 = true;
		} else { 
			var isIE6 = false;
		}
		$.browser.msie6 = isIE6;

		// detect version <= ie6 then apply pngfix
		if($.browser.msie6){
			$(document).pngFix();
			$("#MenuOpened ul li").css("width", 100);
		}

		
	});
	
//}

// setup the dropdown menu functionality
function setupDropDown() {
	$("#secondaryMenuWrapper #secondaryMenu > li").mouseover(function(){
		$(this).find(".subMenu").show();
		$(this).find(" > a").addClass("over");
	}).mouseout(function(){
		$(this).find(".subMenu").hide();
		$(this).find(" > a").removeClass("over");
	})
}


// replaces header text with flash content
function replaceHeaders(){
	$("h1").each(function(i) {
		var txt = this.innerHTML;
		h1 = new SWFObject("/assets/flash/texth1.swf", "h1", "450", "33", "8", "#ffffff");
		h1.addVariable("txt", txt);
		h1.addParam("wmode", "transparent");
		h1.addParam("quality", "best");
		h1.write(this);
	})
	
	$("h2").each(function(i) {
		var txt = this.innerHTML;
		h2 = new SWFObject("/assets/flash/texth2.swf", "h2", "450", "25", "8", "#ffffff");
		h2.addVariable("txt", txt);
		h2.addParam("wmode", "transparent");
		h2.addParam("quality", "best");
		h2.write(this);
	})
	
	$("h3").each(function(i) {
		var txt = this.innerHTML;
		h3 = new SWFObject("/assets/flash/texth3.swf", "h3", "450", "25", "8", "#ffffff");
		h3.addVariable("txt", txt);
		h3.addParam("wmode", "transparent");
		h3.addParam("quality", "best");
		h3.write(this);
	})
}

function replaceHeadersLoaded(){
	$("#contentContainerStart h1").each(function(i) {
		var txt = this.innerHTML;
		h1 = new SWFObject("/assets/flash/texth1.swf", "h1", "450", "33", "8", "#ffffff");
		h1.addVariable("txt", txt);
		h1.addParam("wmode", "transparent");
		h1.addParam("quality", "best");
		h1.write(this);
	})
	
	$("#contentContainerStart h2").each(function(i) {
		var txt = this.innerHTML;
		h2 = new SWFObject("/assets/flash/texth2.swf", "h2", "450", "25", "8", "#ffffff");
		h2.addVariable("txt", txt);
		h2.addParam("wmode", "transparent");
		h2.addParam("quality", "best");
		h2.write(this);
	})
	
	$("#contentContainerStart h3").each(function(i) {
		var txt = this.innerHTML;
		h3 = new SWFObject("/assets/flash/texth3.swf", "h3", "450", "25", "8", "#ffffff");
		h3.addVariable("txt", txt);
		h3.addParam("wmode", "transparent");
		h3.addParam("quality", "best");
		h3.write(this);
	})
}


// setup collapsable items
function setupCollapsableItems(){
	// hide by defaulr
	$(".collapsable").each(function(i) {
		if (!$(this).hasClass("opened")){
			$(this).find(":nth-child(2)").hide();
		} 
	});
	
	$(".collapsable").find(":first").click(function(){ 
    	var content = $(this).parent().find(":nth-child(2)");
		var container = $(this).parent();
		
		if (content.css("display") == "block"){
			container.removeClass("opened");
			container.addClass("closed");
			content.hide();
		} else {
			container.removeClass("closed");
			container.addClass("opened");
			content.show();	
		}
    });
}

// setup function for startpages

function onLoad() {
	replaceHeadersLoaded();
}
	
function onTabClick(imgElement) {
	var tabClass = imgElement.className;
	$("#overStateContainer img").hide();
	$("#overState_" + tabClass).show();	
	if(tabClass == 'tabNews') {
		$("#contentContainerStart").load("/dynamic/pages/home", null, onLoad);
	} else if (tabClass == 'tabYoutube') {
		$("#contentContainerStart").load("/dynamic/pages/youtube", null, onLoad);
	} else if (tabClass == 'tabFlickr') {
		$("#contentContainerStart").load("/dynamic/pages/flickr", null, onLoad);
	} else if (tabClass == 'tabFoto') {
		$("#contentContainerStart").load("/dynamic/pages/foto", null, onLoad);
	} else {
		$("#contentContainerStart").load("tabPages/" + tabClass + ".php", null, onLoad);
	}
}

function onThumbClick(id) {
	$("#contentContainerStart").load("tabPages/tabVideo.php?id=" + id, null, onLoad);
}

function onYoutubeThumbClick(id) {
	$("#contentContainerStart").load("/dynamic/pages/youtube/video:" + id, null, onLoad);
}

function onFlickrThumbClick(id) {
	$("#contentContainerStart").load("/dynamic/pages/flickr/image:" + id, null, onLoad);
}

function onFotoThumbClick(id) {
	$("#contentContainerStart").load("/dynamic/pages/foto/image:" + id, null, onLoad);
}