// JavaScript Document
var open_menu = null;
var displayed_section = null;
// Price Ranges
var criteria = false;
var range1 = new Array();
var range2 = new Array();
var range3 = new Array();
var range4 = new Array();
var range5 = new Array();
//Video vars
var fichier = null;
var nom = null;
var video_active = false;

//Show/hide Look Around panel
function showhideLookAround()
{
	Spry.Effect.DoSlide('look_around', {duration: 500, from:  '0%', to:  '100%', toggle: true});
}

//Display Submenu
function showSubMenu(name)
{
	if(open_menu != null && open_menu != document.getElementById(name + "_submenu"))
		outSubMenu(open_menu);
	if(open_menu == null)
	{
		open_menu = document.getElementById(name + "_submenu");
		if(open_menu != null)
		{
			//Spry.Effect.DoBlind(open_menu.id, {duration: 1000, from:  '0%', to:  '100%', toggle: false});
			open_menu.style.display = 'block';
			document.getElementById(name).style.backgroundColor = '#3f102c';
		}
	}
}

//Set active menu
function hoverSubMenu(elt)
{
	elt.style.display='block';
	document.getElementById(elt.id.slice(0, elt.id.indexOf("_"))).style.backgroundColor = '#3f102c';
}

//Close submenu
function outSubMenu(elt)
{
	elt.style.display='none';
	document.getElementById(elt.id.slice(0, elt.id.indexOf("_"))).style.backgroundColor = '';
	open_menu = null;
}

//Define selected item in submenu
function setSelected(elt)
{
	document.getElementById(elt).style.backgroundColor = '#572e46';
}

//******************************
// Display item (slide)
//******************************

function show(elt)
{
	if(criteria == true && document.getElementById(elt.id).style.backgroundImage == "url(images/h3_arrow_up_bg.gif)")
		hide(elt.id.slice(0, elt.id.indexOf("_")));
	else
	{
		if(displayed_section == elt.id.slice(0, elt.id.indexOf("_")))
			hide(displayed_section);
		else 
		{
			if(displayed_section != null)
			{
				hide(displayed_section);
			}
			displayed_section = elt.id.slice(0, elt.id.indexOf("_"));
			Spry.Effect.DoBlind(displayed_section, {duration: 1000, from: '0%', to: '100%', toggle: false});
			document.getElementById(elt.id).style.backgroundImage = "url(images/h3_arrow_up_bg.gif)";
		}
	}
}

function hide(elt)
{
	if(document.getElementById(elt) != null)
	{
		if(document.getElementById(elt).style.height != 0)
		{
			Spry.Effect.DoBlind(elt, {duration: 500, from:  '100%', to:  '0%', toggle: false});
			document.getElementById(elt + "_title").style.backgroundImage = "url(images/h3_arrow_down_bg.gif)";
			displayed_section = null;
		}
	}
}


function hideall()
{
	var j=1;
	var lng = range1.length + range2.length + range3.length + range4.length + range5.length;
	//Cacher tout
	for(j=1; j<=lng; j++)
	{
		hide("p" + j);
	}
}

function choose(elt)
{
	Spry.Effect.DoBlind(elt, {duration: 1000, from:  '0%', to:  '100%', toggle: false});
	document.getElementById(elt + "_title").style.backgroundImage = "url(images/h3_arrow_up_bg.gif)";
}

//Sort item by price range
function showprice(range)
{
	var i = 0;
	var lg = 0;
	
	if(criteria == true)
	{
		hideall();
	}
	if(displayed_section != null)
	{
		hide(displayed_section);
	}
	
	lg = range.length;
	if(lg > 0)
	{
		for(i=0; i<lg; i++)
		{
			choose(range[i]);
		}
		criteria = true;
	}
	else
		criteria = false;
}

//******************************
// Play Video
//******************************
function getFlashMovie(movieName)
{
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

function showVideo(file, name)
{
	fichier = file;
	nom = name;
	if(navigator.appName != "Microsoft Internet Explorer")
		Spry.Effect.DoFade('player_container', {duration: 1000, from:  '0%', to:  '100%', toggle: false, setup:displaycontainer()});
	else
	{
		displaycontainer();
		if(video_active == true)
			run();
	}
}

function displaycontainer()
{
	document.getElementById('player_container').style.display = "block";
}

function run()
{
	if(fichier != null && nom != null)
		getFlashMovie("video_player").playVideo(fichier, nom);
	if(navigator.appName == "Microsoft Internet Explorer")
		video_active = true;
}

function erreur(val)
{
	alert(val);
}

function hidecontainer() {document.getElementById('player_container').style.display = "none";}

function hideVideo()
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		getFlashMovie('video_player').stopVideo();
		Spry.Effect.DoFade('player_container', {duration: 1000, from:  '100%', to:  '0%', toggle: false, finish:hidecontainer});
	}
	else
		hidecontainer();
}

function hidePhotoContainer() {document.getElementById('photo_player_container').style.display = "none";}

function hidePhotos()
{
	if(navigator.appName != "Microsoft Internet Explorer")
		Spry.Effect.DoFade('photo_player_container', {duration: 1000, from:  '100%', to:  '0%', toggle: false, finish:hidePhotoContainer});
	else
		hidePhotoContainer();
}

function showPhotos()
{
	if(navigator.appName != "Microsoft Internet Explorer")
		Spry.Effect.DoFade('photo_player_container', {duration: 1000, from:  '0%', to:  '100%', toggle: false, setup:displayphotoscontainer()});
	else
		displayphotoscontainer();
}

function displayphotoscontainer()
{
	document.getElementById('photo_player_container').style.display = "block";
}