/*

 from file: iPhoneOrientation.js

 Abstract: Defines JavaScript functionality for the iPhoneOrientation sample.
           Detects iPhone or iPod touch orientation events, determines the devices' orientation,
           sets the html body's class attribute according to the current orientation, and
           displays a descriptive message on the "Handling iPhone or iPod touch Orientation Events" page.

 will call the function orientationChangeHandler if exists.

  */

/* updateOrientation checks the current orientation, sets the body's class attribute to portrait, landscapeLeft, or landscapeRight,
   and displays a descriptive message on "Handling iPhone or iPod touch Orientation Events".  */
function updateOrientation()
{
	var className;
	/*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
	  left, or landscape mode with the screen turned to the right. */
	var orientation=window.orientation;
	switch(orientation)
	{

		case 0:
				className = "portrait";
				break;
		case 90:
				className = "paysage";
				break;
		case -90:
				className = "paysage";
				break;
		case 180:
				className = "portrait";
				break;
		default:
	         	className = "portrait";
         		break;
	}

	//changement du viewport
	setTimeout( function() {

		document.body.setAttribute("class", className);

		var metaTagViewport = document.getElementsByName('viewport')[0];
		if (metaTagViewport !=null)
		{
		   if (className=="portrait")
		   {
				metaTagViewport.setAttribute("content", "width = device-width, minimum-scale=1.0, maximum-scale=1.0", false);
		   }
		   else if (className=="paysage")
		   {
	    	  metaTagViewport.setAttribute("content", "width = device-height, minimum-scale=1.0, maximum-scale=1.0", false);
		   }
		}
		else
		{
			alert('NO VIEW PORT!!!');
		}
		if( 'undefined' == typeof orientationChangeHandler )
		{
			//alert('unknown error please reload the page...');
		}
		else
		{
			orientationChangeHandler();
		}
		centreContenu();
		setTimeout( function() {
			window.scrollTo(0, 1);
		}, 400);
	}, 400);
}

if( isAndroid() ){
	//window.onorientationchange = updateOrientation; Toujours appelé...
}else{
	// Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
	window.onorientationchange = updateOrientation;
}
function isAndroid(){
	var sUA = (navigator.userAgent.toLowerCase());
	return  sUA.indexOf("android") > -1 ;
}
function AndroidMonitor()
{
	this.w=screen.width;
	this.h=screen.height;
	this.width=screen.width;
	this.height=screen.height;
	this.update=(function()
	{
		this.width=screen.width;
		this.height=screen.height;
		if(this.width>this.height)
		{
			this.orientation="landscape";
		}
		else{
			this.orientation="portrait";
		}
		if(this.w!=this.width && this.h!=this.height)
		{
			updateOrientation();
			this.w=this.width;
			this.h=this.height;
		}
	});
	this.update();
}
AndroidMonitor=new AndroidMonitor();
function AndroidMonitoring()
{
	AndroidMonitor.update();
	setTimeout("AndroidMonitoring()",0);
}

