/************************************************************************
 *
 *  Caliber
 *  $Id: mobile.js 439 2009-03-18 13:03:33Z tom $
 *  © 2008 upstruct berlin oslo *****************************************************************************/

/*
///////////////////////////////////////////////////////////////////////////////////
//
//  Querysting 
//
///////////////////////////////////////////////////////////////////////////////////
*/
/**
* Returns a object of the vars pased in the querystring
* @param	none
* @return	void
**/
function getUrlParameters() {
	var arg = new Object();
	var href = document.location.href;

	if ( href.indexOf( "?") != -1){
		var params = href.split( "?")[1];
		var param = params.split("&");

		for (var i = 0; i < param.length; ++i){
			var name = param[i].split( "=")[0];
			var value = param[i].split( "=")[1];

			arg[name] = value;
		}
	}
	return arg;
}

/*
///////////////////////////////////////////////////////////////////////////////////
//
//  Cookie function
//
///////////////////////////////////////////////////////////////////////////////////
*/

/**
* Set a new cookie
**/
function setCookie(name, value, expires, path, domain, secure){
		
    var today = new Date();
	today.setTime( today.getTime() );
    if ( expires ){
    	expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name + "=" +escape( value ) +
    	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    	( ( path ) ? ";path=" + path : "" ) + 
    	( ( domain ) ? ";domain=" + domain : "" ) +
    	( ( secure ) ? ";secure" : "" );
			
};

/**
* Get a cookie
* @param	none
* @return	void
**/
function getCookie(name){
		
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
	    return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
		
};

/*
///////////////////////////////////////////////////////////////////////////////////
//
//  Stack controller class
//
///////////////////////////////////////////////////////////////////////////////////
*/
var StackControll = Class.create({
	initialize: function(){
		this.ORIENTATION = 'portrait';
		this.CURRENT = null;
		this.PARENT = null;
		this.LANDSCAPE_WIDTH = 480;
		this.PORTRAIT_WIDTH = 320;
		this.DURATION = 0.4;
		this.FADING = false;
		
		this.peEx();
	},
	
	/**
	 * Periodical Executer to check the layout of the iPhone.
	 **/
	peEx:function(){
		var controller = this;
		
		new PeriodicalExecuter(function(pe) {
			
			var layout = (window.innerWidth <= controller.PORTRAIT_WIDTH) ? "portrait" : "landscape";
			if(layout != controller.ORIENTATION){
				$$('.stack').each(function(element) {
					$(element).removeClassName(controller.ORIENTATION);
				});
				controller.ORIENTATION = layout;
				$$('.stack').each(function(element) {
					$(element).addClassName(controller.ORIENTATION);
				});

			}
		}, 1);
	},
	
	setOrientation:function(string){
		this.ORIENTATION = (string == 'portrait') ? "portrait" : "landscape";
	},
	setCurrent:function(string){
		this.CURRENT = string;
	},
	setParent:function(string){
		this.PARENT = string;
	},
	setDuration:function(string){
		this.PARENT = string;
	},
	setFadign:function(bool){
		this.FADING = (bool == false) ? false : true;
	},
	
	getOrientation:function(){
		return this.ORIENTATION;
	},
	getCurrent:function(){
		return this.CURRENT;
	},
	getParent:function(){
		return this.PARENT;
	},
	getDuration:function(){
		return this.DURATION;
	},
	getFading:function(){
		return this.FADING;
	},
	
	pushStack:function(string){
		this.PARENT = this.CURRENT;
		this.CURRENT = string;
	}
})

/*
///////////////////////////////////////////////////////////////////////////////////
//
//  Stack class
//
///////////////////////////////////////////////////////////////////////////////////
*/
var Stack = Class.create({
	/**
	 * Open a new stack
	 * @param  array of params, required are id, url and direction
	 **/
	initialize: function(params){
		BUSCUIT.pushStack(params.id);
		
		/* This is a ugly hack to get around the 'this scope' in the AJAX */
		var thisStack = this;
		
		new Ajax.Request(params.url,{
			onSuccess: function(transport){
				var content = transport.responseText.gsub(/height=".*?"/, '');
				if(params.direction == 'left'){
					thisStack.openLeft(params.id,content);
				} else {
					thisStack.openRight(params.id,content);
				}
		    },
		    parameters: {}
		});
	},
	
	/**
	 * Open a new stack to the left
	 * @param  id, content
	 **/
	openLeft: function(id,content){
		var xPos = (BUSCUIT.getOrientation() == 'portrait') ? '-312px' : '-472px';
		$('stacks').insert({top:'<div id="'+id+'" class="stack '+BUSCUIT.getOrientation()+'"></div>'});
		$('stacks').setStyle({left:xPos});
		$(id).update(content);
		if(BUSCUIT.getFading())
			new Effect.Opacity(id, { from: 0.0, to: 1.0, duration: BUSCUIT.getDuration() });	

		new Effect.Move($('stacks'), { x: 0, y: 0, duration: BUSCUIT.getDuration(), mode: 'absolute', afterFinish:
			function(){
				$(BUSCUIT.getParent()).remove();
				window.scrollTo(0,1);
			} 
		});
	},
	
	/**
	 * Open a new stack to the right
	 * @param  id, content
	 **/
	openRight: function(id,content){
		var xPos = (BUSCUIT.getOrientation() == 'portrait') ? -312 : -472;
		$('stacks').insert({bottom:'<div id="'+id+'" class="stack '+BUSCUIT.getOrientation()+'"></div>'});
		$(id).update(content);
		if(BUSCUIT.getFading())
			new Effect.Opacity(id, { from: 0.0, to: 1.0, duration: BUSCUIT.getDuration() });
		new Effect.Move($('stacks'), { x: xPos, y: 0, duration: BUSCUIT.getDuration(), mode: 'absolute', afterFinish:
			function(){
				$(BUSCUIT.getParent()).remove();
				$('stacks').setStyle({left:'0px'});
				window.scrollTo(0,1);
			} 
		});
	}

});

/**
 * Called when the window is loaded, any functions that need initialisation
 **/
function windowOnLoad(){
	BUSCUIT.setCurrent('start');
	BUSCUIT.setFadign(false);
	
	var urlParam = getUrlParameters();
	
	if(urlParam.setAsDefault == 'true'){
		setCookie('safariMobile','iphone','','','','');
	}
}

/**
 * Attach a global eventlisteners to the window object
 **/
Event.observe(window, 'load', windowOnLoad);
var BUSCUIT = new StackControll();


addEventListener('load', function(){ 
	setTimeout(hideSafari, 0); 
}, false);

function hideSafari() { 
	window.scrollTo(0, 1); 
}

/*
///////////////////////////////////////////////////////////////////////////////////
//
//  Handlers for the Menu
//
///////////////////////////////////////////////////////////////////////////////////
*/
function toggleMenu(element,id){
	if($(id).getStyle('display') == 'none'){
		$(id).setStyle({height:$('frame').getHeight()+'px'});
		$(element).update('Close');
	} else {
		$(element).update('Menu');
	}	
	Effect.toggle(id, 'blind');
}

function closeMenu(id){
	Effect.BlindUp(id);
}

/*
///////////////////////////////////////////////////////////////////////////////////
//
//  UI calls from the pages
//
///////////////////////////////////////////////////////////////////////////////////
*/
/**
 * Handlers on frontpage
 * @param  
 **/
function display_fr(element){
	if(element)
		$(element).up().className = 'showLoading';

	new Stack({id:'fr',url:'fr.html',direction:'right'});	
	//pageTracker._trackPageview('/m/work');
}
function display_gb(element){
	if(element)
		$(element).up().className = 'showLoading';

	new Stack({id:'gb',url:'gb.html',direction:'right'});	
	//pageTracker._trackPageview('/m/work');
}
function display_es(element){
	if(element)
		$(element).up().className = 'showLoading';

	new Stack({id:'es',url:'es.html',direction:'right'});	
	//pageTracker._trackPageview('/m/work');
}
function display_bienvenue(element){
	if(element)
		$(element).up().className = 'showLoading';

	new Stack({id:'bienvenue',url:'bienvenue.html',direction:'right'});	
	//pageTracker._trackPageview('/m/work');
}

function display_espace_aquatique(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'espace_aquatique',url:'espace_aquatique.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

function display_animations(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'animations',url:'animations.html',direction:'right'});
	//pageTracker._trackPageview('/m/about.html');
}

function display_services(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'services',url:'services.html',direction:'right'});
	//pageTracker._trackPageview('/m/about.html');
}

function display_hebergement(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'hebergement',url:'hebergement.html',direction:'right'});
	//pageTracker._trackPageview('/m/contact');	
}

function display_situation(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'situation',url:'situation.html',direction:'right'});
	//pageTracker._trackPageview('/m/contact');	
}

function display_reservation(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'reservation',url:'reservation.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_contact(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'contact',url:'contact.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

// Hebergement
function display_mobilhome1(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome1',url:'mobilhome1.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome2(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome2',url:'mobilhome2.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome3(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome3',url:'mobilhome3.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome4(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome4',url:'mobilhome4.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome5(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome5',url:'mobilhome5.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_cottage1(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'cottage1',url:'cottage1.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_cottage2(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'cottage2',url:'cottage2.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_bungalow1(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'bungalow1',url:'bungalow1.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet1(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet1',url:'chalet1.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet2(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet2',url:'chalet2.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet3(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet3',url:'chalet3.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet4(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet4',url:'chalet4.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_emplacement(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'emplacement',url:'emplacement.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

// GB

function display_bienvenue_gb(element){
	if(element)
		$(element).up().className = 'showLoading';

	new Stack({id:'bienvenue',url:'bienvenue_gb.html',direction:'right'});	
	//pageTracker._trackPageview('/m/work');
}

function display_espace_aquatique_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'espace_aquatique',url:'espace_aquatique_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

function display_animations_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'animations',url:'animations_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/about_gb.html');
}

function display_services_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'services',url:'services_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/about_gb.html');
}

function display_hebergement_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'hebergement',url:'hebergement_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/contact');	
}

function display_situation_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'situation',url:'situation_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/contact');	
}

function display_reservation_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'reservation',url:'reservation_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_contact_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'contact',url:'contact_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

// Hebergement
function display_mobilhome1_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome1',url:'mobilhome1_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome2_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome2',url:'mobilhome2_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome3_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome3',url:'mobilhome3_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome4_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome4',url:'mobilhome4_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome5_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome5',url:'mobilhome5_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_cottage1_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'cottage1',url:'cottage1_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_cottage2_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'cottage2',url:'cottage2_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_bungalow1_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'bungalow1',url:'bungalow1_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet1_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet1',url:'chalet1_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet2_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet2',url:'chalet2_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet3_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet3',url:'chalet3_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet4_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet4',url:'chalet4_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_emplacement_gb(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'emplacement',url:'emplacement_gb.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

// ES

function display_bienvenue_es(element){
	if(element)
		$(element).up().className = 'showLoading';

	new Stack({id:'bienvenue',url:'bienvenue_es.html',direction:'right'});	
	//pageTracker._trackPageview('/m/work');
}

function display_espace_aquatique_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'espace_aquatique',url:'espace_aquatique_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

function display_animations_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'animations',url:'animations_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/about_es.html');
}

function display_services_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'services',url:'services_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/about_es.html');
}

function display_hebergement_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'hebergement',url:'hebergement_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/contact');	
}

function display_situation_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'situation',url:'situation_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/contact');	
}

function display_reservation_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'reservation',url:'reservation_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_contact_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'contact',url:'contact_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}

// Hebergement
function display_mobilhome1_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome1',url:'mobilhome1_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome2_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome2',url:'mobilhome2_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome3_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome3',url:'mobilhome3_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome4_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome4',url:'mobilhome4_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_mobilhome5_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'mobilhome5',url:'mobilhome5_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_cottage1_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'cottage1',url:'cottage1_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_cottage2_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'cottage2',url:'cottage2_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_bungalow1_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'bungalow1',url:'bungalow1_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet1_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet1',url:'chalet1_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet2_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet2',url:'chalet2_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet3_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet3',url:'chalet3_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_chalet4_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'chalet4',url:'chalet4_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}
function display_emplacement_es(element){
	if(element)
		$(element).up().className = 'showLoading';
	
	new Stack({id:'emplacement',url:'emplacement_es.html',direction:'right'});
	//pageTracker._trackPageview('/m/blog');
}


