var actSect = false;
var actPage = false;
var menuVis = false;
var actVis = false;
var workOver = false;
$(function() {
		   
// ==== onload: ==== //
   $('a').click(function() { this.blur(); });

	if(actSectID<10) {
		// === "static" sections: 
		//hide indexhibit menue
		hideMenu(0,1);	
		
		switch(actPageID) {
			case 3: //work
				actPage='work'; setStyle('work'); break;
			case 2: //about
				actPage='about'; setStyle('home'); break;
			case 5: //contact
				actPage='contact'; setStyle('home'); break;
			default:
			case 1: //home / news
			case 10: //news-archive
				actPage='news'; setStyle('home'); break;
		}
		
		//mark section active:
		$("a#"+actPage).addClass("active");
	} else {
		// === "work" sections: 
		//need to hide menue for ":hidden" becomes true:
		hideMenu(0,1);	
		
		// hide all exhibitions
		hideAll();
		
		// show indexhibit menue
		showMenu(1);	 
		
		if(actSectID) {
			//open actSection & mark active:
			actSect = "section_"+actSectID;
			actVis = false;
	
			// show act
			showAct(1);
			
			// change bg
			setStyle('work');
			
			// show/hide overlay
			//$("#content").mouseover(function(){showOverlay()});
			//$("#work_button").mouseover(function(){showOverlay()});
			//$("#work_overlay").mouseover(function(){hideOverlay()});
		}
	}
		
	//place actions on setion titles:
	$("li.section-title").click(function(){
		//$(this).siblings().slideDown("normal");
		actSect=$(this).parents().attr("id");
		actVis = false;
		
		// make sections text default;
		$("#wrap_menu > ul").find("li.section-title_active").removeClass("section-title_active");
		$("#wrap_menu > ul").removeClass("active");
		
		// close all open sections:
		//$("#wrap_menu > ul > li:not(.section-title)").slideUp("normal",showAct);
		//$("#wrap_menu > ul > li:not(.section-title) + :visible").slideUp("normal",showAct);
		//$("#wrap_menu > ul > li:not(.section-title)").slideUp("normal",showAct);
		$("#wrap_menu > ul").find("li:not(.section-title)").not(":hidden").slideUp("normal",showAct);
		
		if(!actVis)
			showAct();
	});
	
	// WORK
	$("a#work").click(function(){
		// hide all exhibitions:
		$("#wrap_menu > ul").find("li.section-title_active").removeClass("section-title_active");
		$("#wrap_menu > ul").removeClass("active");
		hideAll();
		
		// show indexhibit menue
		showMenu(); 
	});
	
	// NEWS
	$("a#news").click(function(event){
		event.preventDefault();
		var href=$(this).attr("href");
		if(menuVis) {
			//hide indexhibit menue
			hideMenu(href);
		} else {
			goHref(href);
		}
	});
	
	// ABOUT
	$("a#about").click(function(event){
		event.preventDefault();
		var href=$(this).attr("href");
		if(menuVis) {
			//hide indexhibit menue
			hideMenu(href);
		} else {
			goHref(href);
		}
	});
	
	// CONTACT
	$("a#contact").click(function(event){
		event.preventDefault();
		var href=$(this).attr("href");
		if(menuVis) {
			//hide indexhibit menue
			hideMenu(href);
		} else {
			goHref(href);
		}
	});
// ==== onload EOF ==== //
	
// ==== menue slider: ==== //
	//hide indexhibit menue:
	function hideMenu(href,flag) { 
		//$("#wrap_menu").hide();
		if(flag==1) {
			$("#wrap_menu").hide();
		} else if(menuVis) {
			if(href)
				$("#wrap_menu").slideUp("normal",function(){ goHref(href); });
			else
				$("#wrap_menu").slideUp("normal");
		}
		menuVis = false;	
		$("a#work").removeClass("active");
	}
		
	// show indexhibit menue:
	function showMenu(flag) { 
		// $("#wrap_menu").show();
		if(flag==1)
			$("#wrap_menu").show();
		else
			$("#wrap_menu").slideDown("normal");
		$("#menu").find("a.active").removeClass("active");
		$("a#work").addClass("active")
		menuVis = true;
	}
		
	// hide all exhibitions:
	function hideAll() { 
		// hide all exhibitions:
		$("#wrap_menu > ul > li:not(.section-title)").hide();
					
		// make sections text default;
		$("#wrap_menu > ul").find("li.section-titles_open").removeClass("section-titles_open");
	}
		
	// open act section:
	function showAct(flag) { 
		if(!actVis) {
			// show act
			//$("#wrap_menu > ul").find("li:not(.section-title)").slideDown("normal");
			if(flag==1)
				$("ul#"+actSect).find("li:not(.section-title)").show();
			else
				$("ul#"+actSect).find("li:not(.section-title)").slideDown("normal");
			
			// make sections text black;
			$("#wrap_menu > ul").find("li.section-title").addClass("section-titles_open");
			
			// mark actSect active:
			$("ul#"+actSect).find("li.section-title").addClass("section-title_active");
			$("ul#"+actSect).addClass("active");
		}
		actVis = actSect;
	}
	
	function setStyle(className) {
		//alert('setStyle('+className+')');
		//remove all styles:
		//$("body").removeClass('');
		
		// set new style id not empty
		if(className) {
			//$("body:not(."+className+")").addClass(className);
			$("body").addClass(className);
			$("#menu").addClass(className);
			$("div .container").addClass(className);
		}
	}
	
	function goHref(href) { self.location.href=href; }	
// ==== menue slider EOF ==== //

// ==== menue overlay: ==== //
	function showOverlay() {
		if(!workOver) {
			$("#work_button").show();	
			$("#work_overlay").show();	
		}
		workOver = true;
	}	
	function hideOverlay() {
		if(workOver) {
			$("#work_overlay").hide();	
			$("#work_button").hide();	
		}
		workOver = false;
	}	
// ==== menue overlay EOF ==== //
	
   /* toggle indexhibit menue
   $("a#work").toggle(function(){
     $("#wrap_menu").slideDown("normal");
   },function(){
     $("#wrap_menu").slideUp("normal");
	 menuVis = false;
   });
	*/

});


