$(document).ready(function(){
	
	// PNG FIX:
	//$(document).pngFix();
	
	/*
	console.log(currentView);
	console.log(currentPage);
	console.log(currentLang);
	console.log(currentItem);
	console.log(currentType);
	*/
		
	//
	// ------------------------------
	// ----- SET INITIAL VALUES -----
	// ------------------------------
	//
	
	/* set active nav (lang) */
	var activeNav;
	var inactiveNav;
	var activeContentLang;
	var inactiveContentLang;
	
	if(currentLang=="en"){
		/*console.log("active language is English");*/
		activeNav 			= $("#projectNavEN");
		inactiveNav 		= $("#projectNavPT");
		activeContentLang	= $(".langEN");
		inactiveContentLang = $(".langPT");
	} else if(currentLang=="pt"){
		/*console.log("active language is Portuguese");*/
		activeNav 			= $("#projectNavPT");
		inactiveNav 		= $("#projectNavEN");
		activeContentLang	= $(".langPT");
		inactiveContentLang = $(".langEN");		
	} else {
		/*console.log("active language is undefined");*/
		activeNav 			= $("#projectNavEN");
		inactiveNav 		= $("#projectNavPT");
		activeContentLang	= $(".langEN");
		inactiveContentLang = $(".langPT");		
	}
		
	//
	// ------------------------------
	// ----- PROJECT NAVIGATION -----
	// ------------------------------
	//
	
	/* highlight active tab */
	var currentTab = $("[tabId=" + currentPage + "]");
	currentTab.css({
		backgroundColor:"#FFFFFF"			   
	});
	
	/* set initial depths */
	activeNav.css({
		zIndex:'5'					   
	});	
	inactiveNav.css({
		zIndex:'3'					   
	});	
	
	/* set nav hover animation */
	$("#projectNavs").hover(
		function () {
			inactiveNav.dequeue().animate({ 
				top: 20
			}, 500 );
		}, 
		function () {
			inactiveNav.dequeue().animate({ 
				top: 0
			}, 500 );
		}
	);
		
	//
	// -------------------------
	// ----- PORTAL IMAGES -----
	// -------------------------
	//
	
	$(".portalImage").hover(
		function(){
			$(this).children().toggle();
		},
		function(){
			$(this).children().toggle();
		}
	);
		
	//
	// -------------------------
	// ----- FLASH PORTALS -----
	// -------------------------
	//
	
	$("#pre_portal").flash({
	 	swf: 'includes/preportal/portal_pre.swf',
 		height: 390,
 		width: 1024
	});

		
	//
	// -----------------------------------
	// ----- TOGGLE CONTENT LANGUAGE -----
	// -----------------------------------
	//
	
	inactiveContentLang.css({display:'none'});
	activeContentLang.css({display:'block'});
		
	//
	// -----------------------
	// ----- TOGGLE LIST -----
	// -----------------------
	//
	
	// initial settings:
	$(".foldableList").css({ 
		display:"none"
	});
	$(".foldableListOpen").css({
		display:"block"						   
	});
	
	$(".listPlus").click(function(){
		$(this).children().toggle();
		$(this).siblings().filter(".foldableList").slideToggle("normal");
	});	
	
	$(".listTitle").click(function(){
		$(this).siblings().filter(".listPlus").toggle();
		$(this).siblings().filter(".foldableList").slideToggle("normal");
	});
	
	
	//
	// -------------------
	// ----- CLOSE X -----
	// -------------------
	//	
	
	$(".closeX").click(function() {
		$(this).parent().fadeOut();					   
	});
	
	
	//
	// -----------------------------------
	// ----- LOAD CONTENT MAIN PANEL -----
	// -----------------------------------
	//	
	
	// set start page:
	if(currentPage == "people"){
		if(currentItem == ""){	
			currentItem = "default";
			currentType = "html";
			$(".tabMainPanel").removeClass("tabMainPanelText").addClass("tabMainPanelSlideshow");
		};
		
		var itemName	= currentItem;
		var itemType	= currentType;
		var itemFolder 	= getFolder();
		
		//$(".tabMainPanel").load("includes/people/default.html");
		var itemUrl		= itemFolder.concat(itemName).concat(".").concat(itemType);
		$(".tabMainPanel").load(itemUrl);
	};
	
	// get selected item:	
	$(".linkToItem").click(function() {
		
		var itemName 	= getItem($(this));
		var itemType	= getType($(this));
		var itemFolder	= getFolder();

		var itemUrl		= itemFolder.concat(itemName).concat(".").concat(itemType);
		//console.log(itemUrl);
		
		$(".tabMainPanel").load(itemUrl);		
		
		$(".tabMainPanel").removeClass("tabMainPanelSlideshow").addClass("tabMainPanelText");	

		return false;		
	});
	
	function getItem(element) {		
		var anchor		= element.attr("href");
		var itemStart	= anchor.indexOf("i=") + 2;
		var itemName	= anchor.substring(itemStart);
		var itemEnd		= itemName.indexOf("&");		
		itemName		= itemName.substring(0, itemEnd);
		return(itemName);
	};
	function getType(element){		
		var anchor		= element.attr("href");
		var typeStart	= anchor.indexOf("t=") + 2;
		var itemType	= anchor.substring(typeStart);
		var typeEnd		= itemType.indexOf("&");		
		itemName		= itemType.substring(0, typeEnd);
		return(itemType);
	};
	function getFolder() {
		var itemFolder	= "includes/";
		itemFolder		= itemFolder.concat(currentPage).concat("/");
		return(itemFolder);
	};
	
	/*
	function loadItem(target, url) {
		target.load(url);
	};
	*/

	
});
