/*
 *	Intraversal 09 Javascript GENERAL Stuff
 *	www.intraversal.de
 *	
 *	10.09.2009 by bfx@intraversal.de
 */


//
//	F U N C T I O N   D E C L A R A T I O N S
//

function resolveURL(href){

	if (href.match("-")){ // the URL contains goto-element anchor (-)
		var elemGoto = href.split('-')[1];
		var href = href.split('-')[0];
		$("#contentCont > div").fadeOut(300);
		// set navigation buttons' graphics
		$("#navCont > ul > li > a").removeClass("active");
		$("#navCont > ul > li > a[href='" + href + "']").addClass("active");
		// fade in content after fadeOut took some time already
		setTimeout(function(){
			$(href + "Cont").fadeIn(300);
		}, 200);
		// open goto-element when fadeIn took place
		setTimeout(function(){
			$("#" + elemGoto).prev(".toggleTrigger").click();
		}, 300);
		// scroll window view to goto-element after some more time
		setTimeout(function(){
			var position = $("#" + elemGoto).offset()
			$(window).scrollTop(position.top);
		}, 1000);
	}else{ // resolve URL anchor without goto-element
		// set navigation buttons' graphics
		$("#navCont > ul > li > a").removeClass("active");
		$("#navCont > ul > li > a[href='" + href + "']").addClass("active");
		// fade content			
		var href = href  + "Cont";
   		$("#contentCont > div").fadeOut(300);
  		$(href).animate({foo:3}, 200).fadeIn(300);
	}
}


//
//	S H A D O W   B O X   i n i t
//

Shadowbox.init({
	skipSetup: true,
    players: ["qt", "wmp", "img", "html", "iframe"],
    language: "en",
	autoDimensions: true
});


//
//	j Q u e r y   &   o t h e r   M E T H O D S
//

$(document).ready(function(){

	//
	//	H I S T O R Y   P L U G I N   I N I T
	//



	//
	//	J A V A S C R I P T   A C T I V A T I O N   m e s s a g e   r e m o v a l
	//

   	$("#jsTester").slideUp("fast");
   	$("#mainCont").removeClass("hidden");

	if (!($("#mainCont").hasClass("hidden"))){
		setTimeout(function(){
			if(!FlashDetect.versionAtLeast(8)){
				alert(unescape("Diese Seite ben%F6tigt Adobe Flash Player 8 oder h%F6her%2C um korrekt dargestellt zu werden%3A www.adobe.com/flashplayer"));
			}
		}, 200);
	}
	

	//
	//  S H A D O W   B O X   s e t u p
	//

	Shadowbox.setup("a.image", {
		gallery:            "Intraversal images",
	});

	Shadowbox.setup("a.image_noborder", {
		gallery:            "Intraversal images",
	});	
	
	Shadowbox.setup("a.showreel", {
		gallery:            "Intraversal Showreel",
		autoplayMovies:     true
	});

	Shadowbox.setup("a.showreel2", {
		gallery:            "Intraversal Showreel",
		autoplayMovies:     true
	});

	Shadowbox.setup("a.html", {
		autoDimensions: true
	});
	
	//
	//	S O U N D   M A N A G E R   2   s e t u p
	//
	
	soundManager.debugMode = false;
	soundManager.url = "../swf/";
	soundManager.altURL = "../swf/";
	soundManager.useAltURL = true;
	
	//
	//	U R L   A N C H O R   r e s o l v i n g
	//	

	// handle adress bar input (external)
	var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
		var href = "#" + myFile.split('#')[1];
		resolveURL(href);
	}else{
		// set navigation home button graphic
		$("#navCont > ul > li > a[href='#home']").addClass("active");
	}

	// handle links (internal)
	$("a[href*='#']").click(function(){
		
		// leave current content division cleaned up
		$(".toggleContainer").slideUp("slow");
		$(".toggleTrigger").removeClass("active").removeClass("nonActiveHover");
		
		// check URL for division anchor (#)
		var href = "#" + $(this).attr("href").split('#')[1];
		resolveURL(href);
	});

   	
   	//
   	//	C O N T E N T   s e t u p
   	//
   	
 	// Hide content
	$("#soundDesignCont").hide();
	$("#musicCont").hide();
	$("#codingCont").hide();

   	//
   	//	H O V E R   L I N K   E F F E C T    (only navigation menu)
   	//
   	
	$("#navCont > ul > li > a").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);
	
 	//
 	//	P O P U P   E F F E C T S
 	//
 	
 	// Hide popups at startup
 	$("#navPopupCont > div").hide()
	
	// show popups when hovering navigation buttons
   	$("#navCont > ul > li > a").hover(function(){	// show this popup
   		var thisNav = $(this).attr("href");
   		if (thisNav.match(".html")){
   			thisNav = "#" + thisNav.split(".html")[0];
   		}
   		thisNav = thisNav + "Popup";
   		// definitely hide all visible popups
   		$("#navPopupCont > div").hide();
   		// fade in this popup
   		$(thisNav).fadeIn(300);
   	},
   	function(){	// hide this popup
   		var thisNav = $(this).attr("href");
   		if (thisNav.match(".html")){
   			thisNav = "#" + thisNav.split(".html")[0];
   		}
   		thisNav = thisNav + "Popup";
   		$(thisNav).hide();
   	});


   	//
   	//	P A R A G R A P H   S L I D E S
   	//
   	
	// hide all toggle containers
	$(".toggleContainer").hide();

	// slide toggle containers up or down
	$("h5.toggleTrigger").click(function(){
		if ($(this).hasClass("active")){ // slide up, make inactive
			$(this).removeClass("active");
			if ($(this).hasClass("activeHover")){
				$(this).removeClass("activeHover");
			}
			$(this).next(".toggleContainer").slideUp("slow,");		
		}
		else{ // slide down, make active
			$(".toggleContainer").slideUp("slow");
			$(".toggleTrigger").removeClass("active").removeClass("nonActiveHover");
			
			$(this).addClass("active");
			if ($(this).hasClass("nonActiveHover")){
				$(this).addClass("activeHover");
			}
			$(this).next(".toggleContainer").slideDown("slow,");
		}
	});
	
	// toggle trigger hover effects
	$("h5.toggleTrigger").hover(function(){
		if ($(this).hasClass("active")){
			$(this).addClass("activeHover");
		}else{
			$(this).addClass("nonActiveHover");
		}
	},
	function(){
		if ($(this).hasClass("active")){
			$(this).removeClass("activeHover");
		}else{
			$(this).removeClass("nonActiveHover");
		}
	});


   	
});