var SiteInit = {
	start: function(){
		Panes.start();
		Menu.start();
		Front.start();
		
		if( dev ){
			console.log( "dev mode enabled" );
			My.start();
		}
	},
	
	resize: function(){
		Menu.ResizeNavigationMasks();
		Panes.updatePanes();
	}	
};


location.querystring = (function() {
	// The return is a collection of key/value pairs
	var result = {};

	// Gets the query string with a preceeding '?'
	var querystring = location.search;

	// document.location.search is empty if a query string is absent
	if (!querystring)
		return result;

	// substring(1) to remove the '?'
	var pairs = querystring.substring(1).split("&");
	var splitPair;

	// Load the key/values of the return collection
	for (var i = 0; i < pairs.length; i++) {
		splitPair = pairs[i].split("=");
		result[splitPair[0]] = splitPair[1];
	}

	return result;
})();



var net = {
	
	splitQuery: function(querystring){
		var result = {};
		if (!querystring) return result;
		
		querystring = querystring.split("?")[1];
		//console.log( querystring );
		
		var pairs = querystring.split("&");
		if( !pairs.length ) pairs = array(querystring);
		
		//console.log( pairs );
		
		pairs.each( function(p){
			var pair = p.split("=");
			//console.log( pair );
			result[pair[0]] = pair[1];
		});
		//console.log( result );

		return result;
	},
	
	
	get: function( pageId ){
		//console.log("## net.get.pageId: "+ pageId );

		var targetH = -1;
		switch( pageId ){
			case "home"		: targetH = frontSectionWidth * 0;	break;
			case "news"		: targetH = frontSectionWidth * 1;	break;
			case "persons"	: targetH = frontSectionWidth * 2;	break;
			case "products"	: targetH = frontSectionWidth * 3;	break;
			case "sets"		: targetH = frontSectionWidth * 4;	break;
			
			case "my"		: targetH = frontSectionWidth * 5;	break;
			
			case "about"	: targetH = frontSectionWidth * 6;	break;
			case "links"	: targetH = frontSectionWidth * 7;	break;
		}
		if( targetH != -1)	Panes.showFrontSection( targetH );
		
		/*
		
		pageLevel = 2;
		if( pageId.indexOf("_")>0) {
			var a = pageId.split("_");
			pageId = a[0];
			pageLevel = a[1];
		}
		*/
		/*
		if( pageId == "about" ){
			Panes.showAbout();
		}else{
			//Panes.showPage();
			mySlide_Hfx.start( -aboutWidth );
			mySlide_Vfx.start(112);
		}
		*/
		//$('front').empty(); //page
		
		//net.load('/ajax/section_front.php?page='+ pageId +'&pageLevel='+ pageLevel, pageId);
		/*
		switch( pageId ){
			case "home"		: net.load('/ajax/home.php',  pageId);	break;
			case "about"	: net.load('/ajax/about.php', pageId);	break;
			case "links"	: net.load('/ajax/links.php', pageId);	break;
			
			default			: net.load('/ajax/section_front.php?page='+ pageId +'&pageLevel='+ pageLevel, pageId);
		}
		*/
	},
	
	
	load: function( uri, pageId ){
		//console.log("net.load");
		new Ajax(uri, {
			method: 'get',
			update: $('front'), //page
			onSuccess: function(){
				net.initChapterFront(pageId);
			}		
		});//.request();
	},

	initChapterFront: function( pageId ){
		// Called when the section-frontpage is loaded (net.get)
		// Tween btm color towards the section color
		

		/* reuses L1_LogoColors - but we might need something more subtle...*/
		var col;
		if( L1_LogoColorsHash.hasKey( pageId )){
			col = L1_LogoColorsHash.get( pageId );
		}else{
			col = L1_LogoColorsHash.get( 'home' );
		}
		//console.log("initChapterFront.pageId = "+ pageId +" -> color:"+ col);
		
		var f = $("home_section_1").effects({
			wait: false,
			duration: 2000,
			transition: Fx.Transitions.Quart.easeOut
		}).start({'background-color': col });
	}
}


Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
		
window.addEvent('domready', SiteInit.start);
window.addEvent('load', SiteInit.resize);
window.addEvent('resize', SiteInit.resize);

