/*
 * gui_global.js
 *  
 */

var pngFixMode = 2;
var resizeDebug = false;
var menuHeight = 0;
var frameContentMinHeight = 0;	// sans bandeau
var frameContextMinHeight = 0;	// sans bandeau
var bandeauHeight = 0;
var usableHeight = 0;			// available height
var minUsableHeight = 0;

var frameContentHeight = 0;			// final computed frame height, sans bandeau

var frameLoaded = false;

var pngToFix = '#quicklinks-edge, .gui_legend, .gui_picto, .gui_submit, #gui_booking, #gui_event, h3';

function loadCompleted()
{
	$('#gui_footer').css('visibility', 'visible');
}

function onAllLoaded()
{
	try {
		$('.contextual_elements .gui_grouped_box').accordion({
	        header: '.gui_title',
	        event: 'mousemove'
	    });
	} catch (ex) {}
	
	if ($.browser.msie && $.browser.version == 6) {
		
		if (pngFixMode==1) {
	        $('a.gui_legend').pngFix();
		} else {
	    	if ($.browser.msie && $.browser.version == 6 && typeof DD_belatedPNG == 'object') {	    		
	    		DD_belatedPNG.fix(pngToFix);	    		
	    	}	
		}
    }
}

window.onload = function(e) {
	onAllLoaded();	
}

//called on the parent
function setInitialHeight() {	

	if (self==parent)
	{	
		
		if (frames['buffer'] && !frameLoaded) return;	//ensure the frame part is run before the parent part				
							
		menuHeight = $('#gui_nav_menu').outerHeight();
		
		var cssProperty = 'height';
		if ($.browser.msie && $.browser.version == 6) {
			cssProperty = 'height';
		}
		
		usableHeight = 	$(window).height() -
						$('#top_header').outerHeight() -
						$('#gui_path').outerHeight() - 
						//$('#gui_header').outerHeight() - 
						$('#footer').outerHeight()-1;
		
		var contentHeight = 0;
		if (frames['buffer'])
		{
			contentHeight = Math.max(frameContentMinHeight, frameContextMinHeight) + bandeauHeight;
			if (resizeDebug)
			{
				//document.title="frameContentMinHeight=" + frameContentMinHeight + "\nframeContextMinHeight=" + frameContextMinHeight);
			}
		}
		else
		{
			contentHeight = Math.max(
					$('#gui_content').outerHeight(), 
					$('#gui_contextual').outerHeight(),
					$('#master .contextual_elements').outerHeight(),
					$('#master .content_area').outerHeight(), 
					$('#master .content_area_large').outerHeight()	
				);			
		}						
		
		var maxHeight = Math.max(
				contentHeight,
				menuHeight,
				usableHeight,
				minUsableHeight
			);
		
		if (resizeDebug) document.title='  contentHeight = ' + contentHeight + ' ' +
								'  menuHeight = ' + menuHeight + ' ' +
								'  usableHeight = ' + usableHeight + ' ' +
								'  --> maxHeight = ' + maxHeight;
		
		$('#gui_navigation').css('height', maxHeight + 'px');
		
		if (frames['buffer'])
		{
			$('#buffer').css('height', maxHeight + 'px');
			frames['buffer'].adjustFrameHeight(maxHeight);
		}
		
		$('#master .content_area, #master .content_area_large, #gui_navigation, #master .contextual_elements').css('height', maxHeight + 'px');
		$('#master').css('height', maxHeight + 'px');

		$('#gui_navigation, #gui_content, #gui_contextual').css(cssProperty, maxHeight + 'px');	
		
		
		loadCompleted();
						
	}
	else
	{	
	
		/*
		try
		{
		  if (parent.location.href.indexOf('33654/4/F/ContentExterne.asp?DomID=61837&Version=4&debug=1')>-1)	{parent.resizeDebug = true;}
		} catch (ex) {}
		*/
		
		
		$('#page_1').css('height', 'auto');
		$('#page_2').css('height', 'auto');
		$('#master').css('height', 'auto');
		
		frameContentMinHeight = 0;	// sans bandeau
		frameContextMinHeight = 0;	// sans bandeau
		
		
		if (parent.resizeDebug) {
			//parent.alert('Inside FRAME !');	
			//alert('page_1 outerHeight=' + $('#page_1').outerHeight() + " : webkit=" + $.browser.webkit);
			/*
			try
			{
				var elt = document.getElementById('page_1');
				if ($.browser.webkit) alert("webKit! " + elt.clientHeight);
			}
			catch (ex) {alert("ex:" + ex);}
			*/
			
		}
		//we are inside a frame...		
		
		try {
		   parent.bandeauHeight = $('.intHPBandeau').outerHeight();
		}
		catch (ex) {
			parent.bandeauHeight = 0;
		}
		
		try {
		parent.frameContentMinHeight = Math.max(
					$('#master .content_area').outerHeight(), 
					$('#master .content_area_large').outerHeight(),
					$('#page_1').outerHeight()
				);
		}
		catch (ex) {}
		
		try {
		parent.frameContextMinHeight = Math.max(
					$('#master .contextual_elements').outerHeight(), 
					$('#page_2').outerHeight()
				);
		}
		catch (ex) {}
		
		
		try {
			bandeauHeight = $('.intHPBandeau').outerHeight();
		} catch(ex) {}
					
		
		parent.frameLoaded=true;
		parent.setInitialHeight();	
	}
}


function toto()
{
	if ($.browser.msie && $.browser.version == 6) {
		if (parent.pngFixMode==1) {
	        $('a.gui_legend').pngFix();
		} else {
	    	if ($.browser.msie && $.browser.version == 6 && typeof DD_belatedPNG == 'object') {	    		
	    		DD_belatedPNG.fix(parent.pngToFix);
	    	}	
		}
    }
}

//called on the frame
function adjustFrameHeight(h)
{
	finalH = h - parent.bandeauHeight;
	
	$('#page_1').css('height', finalH + 'px');
	$('#page_2').css('height', finalH + 'px');
	$('#master').css('height', finalH + 'px');
	$('#master .content_area').css('height', finalH + 'px');
	$('#master .contextual_elements').css('height', finalH + 'px');
}


//!== called on the parent
function boxAdjustSize(dh)
{			
	frameContextMinHeight += dh;
	
	adjustSize();
	
}

function adjustSize()
{
	if (parent == self)
	{
		resetParentHeights();
	}
	else
	{
		resetFrameHeights();
	}
	setInitialHeight();	
}

function resetParentHeights()
{
	$('#master').css('height', 'auto');
	$('#master .content_area, #master .content_area_large, #master .contextual_elements, #master').css('height', 'auto');
}

function resetFrameHeights()
{
	$('#master .content_area, #master .content_area_large, #master .contextual_elements, #master, #page_1, #page_2').css('height', 'auto');
}

function quithttps()
{	
	$("a").each(function()
	{				
		var h=$(this).attr("href") + '';					
		if (h.length>0) {
			if (h.indexOf('https')==0)
			{
				$(this).attr("href", h);
			}
			else if (h.indexOf('http')==-1 && h.toLowerCase().indexOf('javascript')!=0 && h.toLowerCase().indexOf('mailto:')!=0) {
				
				$(this).attr("href", "http://" + document.location.hostname + "/" + h);
			}
		}	
	});
}

$(document).ready(function(){
		
	try
	{
		//$('.contextual_elements .gui_grouped_box').css('visibility','visible');
		//$('.contextual_elements .gui_grouped_box').css('display','block');
		
	    $('.contextual_elements .gui_grouped_box').accordion({
	        header: '.gui_title',
	        event: 'mousemove'
	    });
	    
	    
	    $('.extbox .extbox_content').hide();
		/*
		 * zones poutre+contenu
		 */
		$('.extbox .extbox_title').click(function() {
			
			if ($(this).parent().hasClass("extbox_open"))
			{
				$(this).parent().removeClass("extbox_open");
				$(this).next().slideUp();
			}
			else
			{
				$(this).parent().addClass("extbox_open");
				$(this).next().slideDown();			
			}
			
		});
		
	    	   
	}
	catch (e) {}	
	
	
	//quit https if needed
	if (document.location.href.indexOf('https://')!=-1)
	{
		setTimeout("quithttps()", 200);	
	}

}); 

$(window).load(
	    function() {
	    	
	    	setInitialHeight();

	    	if (parent==self) {	
	    		$(window).resize(adjustSize);		
	    	}
	    	toto();
	    }
	);


//=========== ancien styleswitcher.js ===============================================


var cookie;
var title;
var testFrom;

testFrom = 0;


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) {
	return a.getAttribute("title");
    }
  }
  return 'normal';
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires=+10h";
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/*
window.onload = function(e) {
  var test = readCookie("style");
  var style = test ? test : 'normal';
  setActiveStyleSheet(style);
//    cookie = readCookie("style");
//    title = cookie ? cookie : getPreferredStyleSheet();
//    setActiveStyleSheet(getPreferredStyleSheet());
//    createCookie("style", getPreferredStyleSheet(), 365);
//    cookie = readCookie("style");
}
*/
//----- PARTIE IMAGE ZOOM -----

var img_zoom;
var div_zoom = null;
var img_1_zoom = null;
var img_2_zoom = null;
var isNS_zoom = null;

function getZoom(image) {
	if (img_zoom==null) {
		img_zoom = new Image();
		div_zoom = document.getElementById? document.getElementById('zoom_image'): document.all? document.all['zoom_image']: null;
		img_1_zoom = document.getElementById? document.getElementById('big_image_1_zoom'): document.all? document.all['big_image_1_zoom']: null;
		img_2_zoom = document.getElementById? document.getElementById('big_image_2_zoom'): document.all? document.all['big_image_2_zoom']: null;
		isNS_zoom = navigator.userAgent.toLowerCase().indexOf('netscape') + 1;
	}

	if (img_1_zoom.src!=image) {
		img_1_zoom.src = '';
		img_2_zoom.src = '';
		img_1_zoom.style.width = 'auto';
		img_1_zoom.style.height = 'auto';
		img_2_zoom.style.width = 'auto';
		img_2_zoom.style.height = 'auto';

		img_zoom.src = image;

		img_1_zoom.src = image;
		img_2_zoom.src = image;

		if (isNS_zoom) {
			div_zoom.style.display = 'block';
		}
	} else {
		div_zoom.style.display = 'block';
	}
}

function checkSize() {
	if (img_zoom.width>img_zoom.height) {
		if (img_zoom.width>640) {
			img_1_zoom.style.width = 640;
			img_2_zoom.style.width = 640;
		}
	} else {
		if (img_zoom.height>480) {
			img_1_zoom.style.height = 480;
			img_2_zoom.style.height = 480;
		}
	}

	if (isNS_zoom) {
		document.getElementById('div_fond_zoom').style.width = '100%';
		document.getElementById('div_image_zoom').style.width = '100%';
	}

	div_zoom.style.display = 'block';
}


//----- PARTIE FLASH -----


/**
 * Display a flash element with an image in case no flash installed
 */
function displayFlash(flash,image,width,height) {
	document.write('         <div id="objFlash">');
	document.write('			<!-- Image Map --><!-- map id="AK" name="AK"></map-->');
	var UseFlash = 0; 
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) { 
		var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; 
		if (plugin && parseInt(plugin.description.substr(plugin.description.indexOf(".")-2,2))>=3 ) UseFlash = 1; 
	} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
		UseFlash = 1; 
	}
	if (!flash) {UseFlash=0;}
	if ( UseFlash ) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+flash+'" /><param name="quality" value="high" /><embed src="'+flash+'" width="'+width+'" height="'+height+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>');
	} else if (!(navigator.appName && navigator.appName.indexOf("Netscape")>=0 && navigator.appVersion.indexOf("2.")>=0)) {
		document.write('<img src="'+image+'" alt="'+title+'" title="'+title+'" border="0"> '); }
	document.write('			<NOEMBED><img alt="Image" src="'+image+'" usemap="#AK" border="0" /></NOEMBED>');
	document.write('			<noscript><img alt="Image" src="'+image+'" usemap="#AK" border="0" /></noscript>');
	document.write('		</div>');
}

function displayFlash(flash,image,width,height,title,style) {
	title = title || 'image';
	document.write('         <div id="objFlash" '+style+'>');
	document.write('			<!-- Image Map --><!-- map id="AK" name="AK"></map-->');
	var UseFlash = 0; 
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) { 
		var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin; 
		if (plugin && parseInt(plugin.description.substr(plugin.description.indexOf(".")-2,2))>=3 ) UseFlash = 1; 
	} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
		UseFlash = 1; 
	}
	if (!flash) {UseFlash=0;}
	if ( UseFlash ) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+flash+'" /><param name="quality" value="high" /><param name="allowFullScreen" value="true"><param name="WMODE" value="Transparent" /><embed src="'+flash+'" width="'+width+'" height="'+height+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" wmode="transparent"></embed></object>');
	} else if (!(navigator.appName && navigator.appName.indexOf("Netscape")>=0 && navigator.appVersion.indexOf("2.")>=0)) {
		document.write('<img src="'+image+'" alt="'+title+'" title="'+title+'" border="0"> '); }
	document.write('			<NOEMBED><img alt="'+title+'" src="'+image+'" usemap="#AK" border="0" /></NOEMBED>');
	document.write('			<noscript><img alt="'+title+'" src="'+image+'" usemap="#AK" border="0" /></noscript>');
	document.write('		</div>');
}



//----- PARTIE AVIATION -----

function slideAviation() {
	if (document.getElementById('aviation')) {
		if (document.getElementById('objFlash').style.display=='block') {
			document.getElementById('objFlash').style.display = 'none';
		} else {
			document.getElementById('objFlash').style.display = 'block';
		}
	}
}



