// Variables
//------------

gNumberOfImages = 10;
gImages = new Array(gNumberOfImages);
gImages[0] = "url(../css/DecorationInterne01.jpg)";
gImages[1] = "url(../css/DecorationInterne02.jpg)";
gImages[2] = "url(../css/DecorationInterne03.jpg)";
gImages[3] = "url(../css/DecorationInterne04.jpg)";
gImages[4] = "url(../css/DecorationInterne05.jpg)";
gImages[5] = "url(../css/DecorationInterne06.jpg)";
gImages[6] = "url(../css/DecorationInterne07.jpg)";
gImages[7] = "url(../css/DecorationInterne08.jpg)";
gImages[8] = "url(../css/DecorationInterne09.jpg)";
gImages[9] = "url(../css/DecorationInterne10.jpg)";
gEffectName = "BlendTrans";
gEffectFunction = "BlendTrans(Duration="+transDuration+")";
crossFadeDuration = 1;
gImageCapableBrowser = canManipulateImages();
preInitMap();

// Functions
//-----------

function preInitMap()
{
	if( usemap )
	{
		// Load the Google maps JavaScript API !
		document.write(
			'<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='+ 
			{ 
				'www.gay-maurice.com': 	'ABQIAAAABRX0zzJGYlm03hnmHoYvMBRBcqoHyLtuncQ1HtXv16j560-bqRTLBS9PdO7ohTnPLl-7Ne8NrwUyHQ', 
				'www.gay-maurice.fr': 	'ABQIAAAABRX0zzJGYlm03hnmHoYvMBRrV1II4fdwJLYYivLLUS0qTLhlBhQteaufiowvPFi8JOHj9BuwvlucdA' 
      		}[location.host] + '" type="text/javascript"><\/script>' ); 
	}
}

function initOnLoad()
{
	initDeco();
	initSwapImage();
	initMenu();
	initThumb();
	if( usemap )
	{
		initMap();
	}
}

function initOnUnLoad()
{
	if( usemap )
	{
		// Unload Google maps Javascript API !
		GUnload();
	}
}

function canManipulateImages()
{
	if( document.images ) return true;
		else return false;
}

function getHostName()
{
	return location.location;
}

function loadDeco( imageURL )
{
	if (gImageCapableBrowser)
	{
		if( document.all )
		{
			document.getElementById("deco").style.filter="blendTrans(duration=1)";
			document.getElementById("deco").filters.blendTrans.Apply();
		}
		document.getElementById("deco").style.backgroundImage = imageURL;
		if( document.all )
		{
			document.getElementById("deco").filters.blendTrans.Play();
		}
		return false;
	}
	else
	{
		return true;
	}
}

function initDeco()
{
	document.getElementById("deco").style.backgroundImage = gImages[gCurrentImage];
	setInterval( "nextDeco()", gSlideshowInterval * 1000 );
}

function nextDeco()
{
	while(true)
	{
		gNextImage = pickRandom( gNumberOfImages );
		if( gNextImage != gCurrentImage )
			break;
	}
	gCurrentImage = gNextImage;
	loadDeco( gImages[gCurrentImage] );
}

function pickRandom( range )
{
	if (Math.random)
		return Math.round(Math.random() * (range-1));
	else
	{
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

function swapImage( el, which )
{
	if( document.all )
	{
		el.style.filter="blendTrans(duration=0.2)";
		el.filters.blendTrans.Apply();
		el.src=el.getAttribute(which||"origsrc");
		el.filters.blendTrans.Play();
	}
	else
	{
		el.src=el.getAttribute(which||"origsrc");
	}
}

function initSwapImage()
{
	var x = document.getElementsByTagName( "img" );
	for( var i=0; i<x.length; i++ )
	{
		var oversrc = x[i].getAttribute( "oversrc" );
		if( !oversrc ) continue;
		// preload image
		x[i].oversrc_img = new Image();
		x[i].oversrc_img.src=oversrc;
		// set event handlers
		x[i].onmouseover = new Function( "swapImage(this,'oversrc');" );
		x[i].onmouseout = new Function( "swapImage(this);" );
		// save original src
		x[i].setAttribute("origsrc",x[i].src);
	}
}

function applyMenuStyle( el )
{
	el.className = "TextNavigationSelected";
}

function unApplyMenuStyle( el )
{
	el.className = "TextNavigationNormal";
}

function initMenu()
{
	var x = document.getElementsByTagName( "a" );
	for( var i=0; i<x.length; i++ )
	{
		var id = x[i].getAttribute( "id" );
		if( !id ) continue;
		if( id == identification )
		{
			x[i].className = "TextNavigationSelected";
		}
		else
		{
			x[i].onmouseover = new Function( "applyMenuStyle(this);" );
			x[i].onmouseout = new Function( "unApplyMenuStyle(this);" );
		}
	}
}

function applyFullImage( el )
{
	var x = document.getElementById( "fullimage" );
	var image = el.getAttribute( "fullsrc" );
	var tip = el.getAttribute( "tip" );
	var caption = document.getElementById( "caption" );
	if( x != null )
	{
		if( (tip != null) && (caption != null) )
		{
			caption.firstChild.nodeValue = tip;
			caption.style.visibility = "visible";
		}
		if( document.all )
		{
			x.style.filter="blendTrans(duration=0.5)";
			x.filters.blendTrans.Apply();
			x.src=image;
			x.filters.blendTrans.Play();
		}
		else
		{
			x.src=image;
		}
	}
}

function unApplyFullImage()
{
	var x = document.getElementById( "fullimage" );
	var caption = document.getElementById( "caption" );
	if( x != null );
	{
		if( caption != null )
		{
			caption.style.visibility = "hidden";
		}
		if( document.all )
		{
			x.style.filter="blendTrans(duration=0.2)";
			x.filters.blendTrans.Apply();
			x.src="../gfx/EmptyPhoto.gif";
			x.filters.blendTrans.Play();			
		}
		else
		{
			x.src = "../gfx/EmptyPhoto.gif";
		}
	}
}

function initThumb()
{
	var x = document.getElementsByTagName( "img" );
	for( var i=0; i<x.length; i++ )
	{
		var fullsrc = x[i].getAttribute( "fullsrc" );
		if( !fullsrc ) continue;
		x[i].onmouseover = new Function( "applyFullImage(this);" );
		x[i].onmouseout = new Function( "unApplyFullImage();" );
	}
}

function initMap()
{
	if( GBrowserIsCompatible() )
	{
		var map = new GMap2( document.getElementById("map") );
		map.addControl( new GSmallMapControl() );
		map.addControl( new GMapTypeControl() );
		map.setCenter( new GLatLng(46.052535, 6.573858), 4 );
		map.setMapType( G_HYBRID_MAP );
		map.enableScrollWheelZoom();
				
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5,1);
		
		var location = new GLatLng( 46.052535, 6.573858 );
		var marker = new GMarker( location, icon );
//		GEvent.addListener( marker, "click", function()
//		{
//			marker.openInfoWindowHtml("<b> GAY Maurice SAS </b>");
//		});
		map.addOverlay( marker );
	}
}