/* Javascript - Voyages Auchan */

/***** Sommaire *****/
// 10 - Write Flash
// 20 - Field cleaner
// 30 - Tabs
// 40 - rescueFrame
// 50 - autoRoll
// 60 - Help
// 70 - send to friend
// 99 - onLoad
/******************/

/***** 10 - Write Flash *****/
function writeFlash(url,id,w,h,o){
	document.write('\n<object id="'+id+'" type="application/x-shockwave-flash" data="'+url+'" width="'+w+'" height="'+h+'">\n');
	document.write('\t<param name="movie" value="'+url+'" />\n');
	if(o != ''){
		var flashOptionsTab = new Array();
		flashOptionsTab = o.split('|');
		for(i=0; i<flashOptionsTab.length; i++){
			var tempParam = flashOptionsTab[i].split('#')[0];
			var tempValue = flashOptionsTab[i].split('#')[1];
			document.write('\t<param name="'+tempParam+'" value="'+tempValue+'" />\n');
		}
	}
	document.write('</object>\n');
}

/***** 20 - Field cleaner *****/
function fieldCleaner(field){
	if(field.value == field.title){
		field.value = '';
	}
}
function fieldFiller(field){
	if(field.value === ''){
		field.value = field.title;
	}
}

/***** 30 - Tabs *****/
var tabGroups = new Array();
function tabGroup(elem,current){
	this.elem = elem;
	this.current = current;
	tabGroups[tabGroups.length] = this;
}

function changeTab(index,tab){
	if(tabGroups[index].current != null && tabGroups[index].current != tab){
		_('tabs'+index+'_'+tabGroups[index].current).style.display = 'none';
		_('tabs'+index,'ul',0,'li',tabGroups[index].current,'a',0).className = '';
	}
	_('tabs'+index+'_'+tab).style.display = 'block';
	_('tabs'+index,'ul',0,'li',tab,'a',0).className = 'on';
	tabGroups[index].current = tab;
}

/***** 40 - rescueFrame *****/
function rescueFrame(){
	if(isIE && !isIE7){		
		if(!_('rescueFrame')){
			var rescueObj = document.createElement('iframe');
			var rescueElement = document.body.appendChild(rescueObj);
			rescueElement.id = 'rescueFrame';
			rescueElement.style.position = 'absolute';
			rescueElement.style.visibility = 'hidden';
			rescueElement.style.border = '0';
			rescueElement.style.filter = 'alpha(opacity=0);';
		}
		_('rescueFrame').style.zIndex = arguments[1];
		_('rescueFrame').style.top = _C('y',arguments[0])+'px'; 
		_('rescueFrame').style.left = _C('x',arguments[0])+'px'; 
		_('rescueFrame').style.width = arguments[0].offsetWidth+'px'; 
		_('rescueFrame').style.height = arguments[0].offsetHeight+'px'; 
		_('rescueFrame').style.visibility = 'visible';
	}
}
function endRescueFrame(){
	if(isIE && !isIE7){
		_('rescueFrame').style.visibility = 'hidden';
	}
}

/***** 50 - autoRoll *****/
var onAdd="-on";
function autoRoll(Img,Event){
	if(!Img.onmouseout && Event == true) Img.onmouseout = function(){ autoRoll(Img) };
	imgExt = Img.src.substring(Img.src.lastIndexOf("."));
	imgName = Img.src.substring(0,Img.src.lastIndexOf("."));
	imgOn = imgName+onAdd+imgExt;
	if(imgName.indexOf(onAdd) != -1) imgName = imgName.substring(0,imgName.length-onAdd.length);
	imgOff = imgName+imgExt;
	if(Img.src.indexOf(onAdd) != -1) Img.src = imgOff;
	else Img.src = imgOn;
}

function autoRollEvents(){
	var imgTable = arguments[0].getElementsByTagName('img');
	for(var i=0; i<imgTable.length; i++){
		if(imgTable[i].src.indexOf(onAdd) == -1) imgTable[i].onmouseover = function(){autoRoll(this,true)};
	}
}

/***** 60 - Help *****/
var helpTimer;
var lastHelp = -1;

function showHelp(index,caller){
	if(lastHelp != -1){
		hideHelp(lastHelp);
	}
	_('help'+index).style.left = (_C('x',_('help'+index+'Caller'))-6)+'px';
	_('help'+index).style.top = (_C('y',_('help'+index+'Caller'))-6)+'px';
	_('help'+index).style.display = 'block';
	_('help'+index).style.visibility = 'visible';
	rescueFrame(_('help'+index),5);
	lastHelp = index;
}
function hideHelp(index){
	_('help'+index).style.display = 'none';
	_('help'+index).style.visibility = 'hidden';
	endRescueFrame();
	lastHelp = -1;
}

/***** 70 - send to friend *****/
function sendToFriend(){

}

/***** onLoad *****/
window.onload = function(){
	
	// 30 - Tabs
	var tabsTab = __('div','tabs');
	for(var i=0; i<tabsTab.length; i++){
		new tabGroup(tabsTab[i],0);
		tabsTab[i].id = 'tabs'+i;
		var tabLinks = _('tabs'+i,'ul',0,'li',-1);
		for(var j=0; j<tabLinks.length; j++){
			_('tabs'+i,'ul',0,'li',j,'a',0).href = 'javascript:changeTab('+i+','+j+');';
		}
		var subTabs = __('div','tab',_('tabs'+i));
		for(var j=0; j<subTabs.length; j++){
			subTabs[j].id = 'tabs'+i+'_'+j;
		}
	}
	
	// 50 - autoRoll
	var rollTab = __('img|input','roll');
	for(var i=0; i<rollTab.length; i++){
		rollTab[i].onmouseover = function(){autoRoll(this,true)};
	}
	
	// 60 - Help
	var helpTab = __('div','help');
	for(var i=0; i<helpTab.length; i++){
		helpTab[i].id = 'help'+i+'Caller';
		_('help'+i+'Caller').index = i;
		_('help'+i+'Caller','img',0).alt = '';
		var layer = document.createElement('div');
		document.body.appendChild(layer);
		layer.id = 'help'+i;
		layer.index = i;
		layer.className = 'helpLayer';
		layer.innerHTML = _('help'+i+'Caller').innerHTML;
		_('help'+i+'Caller').removeChild(_('help'+i+'Caller','span',0));
		
		_('help'+i+'Caller').onmouseover = function(){ clearTimeout(helpTimer); helpTimer = setTimeout('showHelp('+this.index+');',1000); }
		_('help'+i+'Caller').onmouseout = function(){ clearTimeout(helpTimer); }
		_('help'+i).onmousemove = function(){ showHelp(this.index); }
		_('help'+i).onmouseout = function(){ hideHelp(this.index); }
	}
	
	//calendarEvents();
	
}