var cur_opened_id = "";
var duration = 700;
var vFirst=true;
var NbStart=0;

function zoom(item_id)
{
	if(cur_opened_id == item_id)
	{
		close_popup();
	}
	else if(cur_opened_id !="")
	{
		close_popup(item_id);
	}
	else
	{
		show(item_id);
	}
}

function show_region(item_id)
{
    var regionElement = document.getElementById(item_id);
    if (regionElement == undefined)
        return;
        
    var defaultElement = document.getElementById("ZoneDefaut");
    if (defaultElement != undefined)
        defaultElement.className = "not-displayed";
    
    if (regionElement.className != "displayed")
        regionElement.className = "displayed";
}

function hide_region(item_id)
{
    var regionElement = document.getElementById(item_id);
    if (regionElement == undefined)
        return;
    
    if (regionElement.className != "not-displayed")
        regionElement.className = "not-displayed";
    
    var defaultElement = document.getElementById("ZoneDefaut");
    if (defaultElement != undefined)
        defaultElement.className = "displayed";
}

function close_popup(item_id)
{

	if(item_id == undefined) item_id = "";
	myEffectdiv = new Fx.Styles(cur_opened_id,{duration:duration, cur_opened_id: cur_opened_id, item_id: item_id,
			onStart: function(){
			},
			onComplete: function(){
				document.getElementById(this.options.cur_opened_id).className = "not-displayed";
				cur_opened_id = "";
				if(this.options.item_id != "")
				{
					show(item_id);
				}
			}										
		});
	myEffectdiv.custom({'opacity': [1, 0]});
	
}
function show(item_id)
{
	myEffectdiv = new Fx.Styles(item_id,{duration:duration});
	myEffectdiv.set({'opacity': 0});
	document.getElementById(item_id).className = "popup";
	myEffectdiv.custom({'opacity': [0, 1]});
	cur_opened_id = item_id;	
}

function updateCount(n,textSup){
    if(vFirst){
        n=NbStart;
        text = "<strong>"+n+" offres</strong> disponibles";
        vFirst=false;
    }else{
	    if(textSup){
		    if(n <= 1){
			    text = "<strong>"+n+" offre</strong> disponible entre "+textSup;
		    }else{
			    text = "<strong>"+n+" offres</strong> disponibles entre "+textSup;
		    }
	    }else{
		    if(n <= 1){
			    text = "<strong>"+n+" offre</strong> disponible";
		    }else{
			    text = "<strong>"+n+" offres</strong> disponibles";
		    }
	    }
    }
	document.getElementById("replaceContent").innerHTML = unescape(text);
}

function initPage()
{
	var accordion_block = document.getElementById('accordion');
	if(accordion_block)
	{
		var accordion = new Accordion('a.toggler', 'div.element', {
			show: 0,
			alwaysHide: true,
			opacity: false,
			onActive: function(toggler, element){
				toggler.className += ' active';
			},
		 
			onBackground: function(toggler, element){
				toggler.className = toggler.className.replace('active','');
			}
		}, accordion_block);
		 
	}

	var leftcol = document.getElementById("leftcol");
	var rightcol = document.getElementById("rightcol");
	var centercol = document.getElementById("center");
	if (leftcol)
	{
		var maxHeight = 0;
		if ( rightcol.offsetHeight < leftcol.offsetHeight ) maxHeight = leftcol.offsetHeight
		else maxHeight = rightcol.offsetHeight;
		if (window.attachEvent && typeof document.body.style.maxHeight == "undefined")
		{
			if ( centercol.offsetHeight < maxHeight ) centercol.style.height = maxHeight + "px";
		}
		else
		{
			if ( centercol.offsetHeight < maxHeight ) centercol.style.minHeight = maxHeight + "px";
		}
		
	}

	var accordion_block = document.getElementById('accordion');
	if(accordion_block)
	{
		var accordion = new Accordion('a.toggler', 'div.element', {
			show: 0,
			opacity: false,
			onActive: function(toggler, element){
				toggler.className += ' active';
			},
		 
			onBackground: function(toggler, element){
				toggler.className = toggler.className.replace('active','');
			}
		}, accordion_block);
		 
	}
}


if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);
	
function switch_more(_id)
{
	elem = document.getElementById(_id);
	if(elem)
	{
		if(elem.className.indexOf('hidden') != -1)
		{
			myEffectdiv = new Fx.Styles(_id,{duration:duration,
					onStart: function(){
					},
					onComplete: function(){
					}										
			});
			myEffectdiv.set({'opacity': 0});
			myEffectdiv.element.className = "";
			myEffectdiv.custom({'opacity': [0, 1]});
		}
		else
		{
			myEffectdiv = new Fx.Styles(_id,{duration:duration,
					onStart: function(){
					},
					onComplete: function(){
						this.element.className += " hidden";
					}										
			});			
			myEffectdiv.custom({'opacity': [1, 0]});
		}
	}
}

function switch_more1(_id,_id1)
{
	elem = document.getElementById(_id);
	elem1 = document.getElementById(_id1);
	if(elem)
	{
		if(elem.className.indexOf('hidden') != -1)
		{
		    elem.style.display="block";
		    elem1.style.display="none";
			myEffectdiv1 = new Fx.Styles(_id1,{duration:duration,
					onStart: function(){
					},
					onComplete: function(){
						this.element.className += " hidden";
					}										
			});			
			myEffectdiv1.custom({'opacity': [1, 0]});
			
			myEffectdiv = new Fx.Styles(_id,{duration:duration,
					onStart: function(){
					},
					onComplete: function(){
					}										
			});
			myEffectdiv.set({'opacity': 0});
			myEffectdiv.element.className = "";
			myEffectdiv.custom({'opacity': [0, 1]});
		}
		else
		{
		    elem.style.display="none";
		    elem1.style.display="block";
			myEffectdiv = new Fx.Styles(_id,{duration:duration,
					onStart: function(){
					},
					onComplete: function(){
						this.element.className += " hidden";
					}										
			});			
			myEffectdiv.custom({'opacity': [1, 0]});
			
			
			myEffectdiv1 = new Fx.Styles(_id1,{duration:duration,
					onStart: function(){
					},
					onComplete: function(){
					}										
			});
			myEffectdiv1.set({'opacity': 0});
			myEffectdiv1.element.className = "";
			myEffectdiv1.custom({'opacity': [0, 1]});
		}
	}
}