//
//
Effect.XYChange = Class.create(Effect.Base, {
  initialize: function(element) {
    this.element = $(element);
    if (!this.element) throw(Effect._elementDoesNotExistError);
    var options = arguments[1] || { };
    this.start(options);
  },
  setup: function() {
    this.originalHeight = parseFloat(this.element.getStyle('height') || '0');
		this.originalWidth = parseFloat(this.element.getStyle('width') || '0');
  },
  update: function(position) {
    if(this.options.y){
			this.element.setStyle({
        height: ((this.options.y  * position) + this.originalHeight).round() + 'px'
      });
		}
		if(this.options.x){
		  this.element.setStyle({
        width: ((this.options.x  * position) + this.originalWidth).round() + 'px'
      });
		}
  }
});


//<![CDATA[
var Content = [];
function isIE(){
  return navigator.userAgent.indexOf('MSIE') != -1;
}
if(navigator.userAgent.indexOf('MSIE')!=-1 || typeof document.observe != 'function') {
	Event.observe(window, "load", jsLaunch);
} else {
	document.observe("dom:loaded", jsLaunch);
}
function jsLaunch(){
  var onloadTime = new Date();
	//var t = new Tracker();
  //var startTime = new Date();
  if(typeof $!='function') return;
	
  if(window.location.toString().indexOf('home.htm') != -1 
	 || window.location.toString().indexOf('late-availability') != -1){
    showLA();
  }
  var s,q={};
    window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"),
		                           function( $0, $1, $2, $3 ){
									   q[ $1 ] = $3;
								   }
			);
	for(var i in q)if(i=='tab')s=true;
	if(s)SwitchTabs(q.tab.charAt(0),5,q.tab.charAt(2));
    
	
	setJumpTo();
	
	$('SiteWrapper').title = '';
	//stripTitles();
	
	setTabPointer();
	
	
	if($('enquiry_form')&& window.location.toString().indexOf('fpa')==-1 && window.location.toString().indexOf('property')==-1){
		if(document.all){
			FormFactory = new FF();
		    setTimeout("FormFactory.Launch($('enquiry_form'));",1000);
		} else {
		    FormFactory.Launch($('enquiry_form'));	
		}
	}
	
	/*if($('SiteWrapper').className.indexOf('withPageBanner')!=-1){
		setTimeout("fadeIn($('PageBanner'));",400);
		setInterval( 'updatePageBanner()', 3 );
    }*/
	if(document.all){
		var h = document.body.clientHeight, ch = $('container').getHeight();
	    if(h>ch) $('container').style.height = h-20+'px';
	}
	setMailto();
	if(typeof CalInfo != 'undefined'){
		if(CalInfo.length>0){
	        CalInfo.each(function(info,i){
			        Cals.list.push(new Calendar($('calendar_'+info.ru_id),info.rates,info.bookings,i,info.month,false,info.year));
			    });
			Cals.list[0].AJAX(0);
	    }
		
	}
	
	
	// NEW JS FROM HERE
	//if($('ContentList')) setTimeout("new Effect.Appear($('ContentList'), {duration: .3});", 400);
	setTimeout("new Effect.Appear($('logo'), {duration: .5});", 700);
	setTimeout("new Effect.Appear($('language'), {duration: .5});", 1000);
	if(navigator.userAgent.indexOf('MSIE') != -1){
		$('header-back').style.height = '240px';
	} else {
		new Effect.YChange($('header-back'), {duration: .7, y: 240});
	}
	
	
	if($('PageBanner')){
		var el = $('PageBanner').remove();
		var container = $('wrapper').select('.page-banner-content');
				
		if(container[0]){
			if(!$('page-banner-wrapper')){
			  container[0].wrap(new Element('div', { id:'page-banner-wrapper', className:'page-banner-wrapper'}));
				Element.insert($('page-banner-wrapper'), {top: new Element('div', {className:'page-banner-title'}).update('Advertisement:')});
			}
			container[0].replace(el);
		} else if($('ContentList')) {
			Element.insert($('Content'), {top: el});
			var text = (window.location.href.indexOf('francais') != -1)? 'PUB' : 'ADVERT';
			el.wrap(new Element('div', {className:'page-banner-wrapper'}).update('<div class="page-banner-title">'+text+'</div>'));
		}
		
	}
	
	
	
	var tHeight = $('wrapper').getHeight();
	
	var clHeight = $('ContentList')? $('ContentList').getHeight() : 0;
	var cHeight = clHeight > tHeight? clHeight : tHeight;

	
	if($('PageBanner')){
		//cHeight += $('PageBanner').getHeight() +20;
	}
	$('Content').style.height = cHeight + 'px';
	var ch = $('ContentList')? $('ContentList').getHeight() : $('Content').getHeight();

	$('leftCol').style.height = $('plugin-content')? ($('plugin-content').getHeight() + 40) + 'px' : ch + 'px';
	$('nav-back').style.height = $('leftCol').getHeight() + 'px';

  if(navigator.userAgent.indexOf('MSIE') != -1){
		if($('ContentList')) $('ContentList').show();
		if($('plugin-content')) $('plugin-content').show();
	} else {
		setTimeout("if($('ContentList')) new Effect.Appear($('ContentList'), {duration: .3});", 700);
	  setTimeout("if($('plugin-content')) new Effect.Appear($('plugin-content'), {duration: .3});", 700);
  }
	setTimeout("$('minimax-back').style.height = $('minimax-column').getHeight() + 'px';", 1000);
	
  var onloadFinish = new Date();
	
	var pageLoad = (onloadTime.getTime() - loadStart.getTime())/1000;
	var jsRuntime = (onloadFinish.getTime() - onloadTime.getTime())/1000;
	if(window.location.href.indexOf('m.dev')!=-1){
		//alert('page load time: '+pageLoad+', js run time: '+jsRuntime);
	}
	if($('FPASpiel')) setTimeout("setFPAHeights();",1000);



};



Effect.YChange = Class.create(Effect.Base, {
  initialize: function(element) {
    this.element = $(element);
    if (!this.element) throw(Effect._elementDoesNotExistError);
    var options = arguments[1] || { };
    this.start(options);
  },
  setup: function() {
    this.originalHeight = parseFloat(this.element.getStyle('height') || '0');
  },
  update: function(position) {
    this.element.setStyle({
      height: ((this.options.y  * position) + this.originalHeight).round() + 'px'
    });
  }
});





function showLA(){
	var LA = $('LateAvailabilityContainer');
	if(!LA) return;
	if(window.location.toString().indexOf('home.htm') != -1){
	  var texts = $A($('Content').getElementsByClassName('Text'));
	  var el = texts.find(function(span){ return span.innerHTML.indexOf('LATE AVAILABILITY LOADING') != -1 ||
												 span.innerHTML.indexOf('attendez s.v.p') != -1; });
	} else { // in the LA listings page
	  var el = $('la-listing');
	}
	if(el) el.innerHTML = LA.innerHTML;
	//$('la-listing').innerHTML = LA.innerHTML;
	//LA.innerHTML = '';
}

function setMailto(){
  var links = $A($('container').getElementsByTagName('A'));
	links.each(function(el){
	    if(el.href.indexOf('mailto')!=-1&&el.className.indexOf('changeme')!=-1){
			  el.href = el.href+'chamonix-networks.com';
			}
		});
}
function clearField(e){
	var el = e.target;
	el.$value = el.value;
	el.value = "";
}
function resetField(e){
	var el = e.target;
    if(el.value=="") el.value = el.$value;
}
function setFPAHeights(){
    if(window.location.href.indexOf('property') != -1){
			if($('FPASpiel')){
			  var maxHeight = $('FPASpiel').getHeight() + $('FPAFacilities').getHeight();
		//alert($('FPAFacilities').getHeight());
		//if(maxHeight > $('FPAImageContainer').getHeight()){
		    $('FPAImageContainer').style.height = maxHeight + 'px';
		//}
		  }
		
		  if($('FPACalendar')){
			  maxHeight = $('FPACalendar').getHeight();
		    $('FPAPricing').style.height = maxHeight + 'px';
		  }
		  return;
		} else {
			var spielHeight = $('FPASpiel').getHeight();
			var imagesHeight = $('FPAImageContainer').getHeight();
			if(spielHeight > imagesHeight){
			  $('FPAImageContainer').style.height = spielHeight + 'px';
			} else {
			  $('FPASpiel').style.height = imagesHeight + 'px';
			}
			return;
		}
		
		/*var spiel = $('FPASpiel'),
	    features = $('FPAFacilities'),
		s = spiel.getHeight(),
		sy = Position.cumulativeOffset(spiel)[1],
		f = features.getHeight(),
		fy = Position.cumulativeOffset(features)[1];
    spiel.style.height = (s+sy>f+fy)? "" : f+fy-sy+"px";
	features.style.height = (s+sy<f+fy)? "" : s+sy-fy-11+"px";

	if($('FPAPricing')){
	    var pricing = $('FPAPricing'),
		    calendar = $('FPACalendar'),
		    p = pricing.getHeight(),
		    c = calendar.getHeight();
		pricing.style.height = p>c? "" : c-12+"px";
	    calendar.style.height = p<c? "" : p-10+"px";
	}	*/
}


function fadeIn(el,speed){
	speed = speed || 10;
	var bool = getBrowserLevel(); // only run it in IE7 and FF
	if(bool&&el){
	  el.style.opacity = 0;
	  el.style.filter = "alpha(opacity:0)";
	  el.style.display = 'block';
	  for(var i=0;i<101;i++){
	    setTimeout("var el=$('"+el.id+"');el.style.opacity="+i/100+";el.style.filter='alpha(opacity:"+i+")'; ",250+(i*speed));
	  }
	} else {
	  el.style.opacity = 1;
	  el.style.filter = "alpha(opacity:100)";
	  el.style.display = 'block';	  
	}
};

function fadeOut(el,speed){
	speed = speed || 10;
	var bool = getBrowserLevel(); // only run it in IE7 and FF
	if(bool){
	  for(var i=100;i>-1;i--){
	    setTimeout("var el=$('"+el.id+"');el.style.opacity="+i/100+";el.style.filter='alpha(opacity:"+i+")'; ",(100-i)*speed);
	  }
	} else {
	  el.style.display = 'none';
	}
};

function slideUp(el,num,r,speed){
	speed = speed || 10;
	var bool = getBrowserLevel(); // only run it in IE7 and FF
	el.$height = el.getHeight();
	el.$padding = el.style.padding;
	el.$margin = el.style.margin;
	if(bool){
	  el = $(el);
	  var h = el.getHeight();
	  for(var i=1;i<100;i++){
		var height = Math.round(h/i); //i<50? Math.round(h/i) : 0;
		height = (num>1&&height<num)? num : height;
		height = (height<5)? 0 : height;
	    setTimeout("var el=$('"+el.id+"');el.style.height='"+height+"px';el.style.padding='0';el.style.margin='0';",100+i*speed);
	  }
	  if(r) setTimeout("$('"+el.id+"').parentNode.removeChild($('"+el.id+"'));",400+100*speed);
	} else {
	  if(r) {
		$(el.id).parentNode.removeChild($(el.id));
	  } else {
	    el.style.height = num? num+'px' : 0+'px';
		el.style.padding = '0';
		el.style.margin = '0';
	  }
	}
	
}
function squishUp(el,num,r,speed){
	speed = speed || 10;
	var bool = getBrowserLevel(); // only run it in IE7 and FF
	el.$height = el.getWidth();
	el.$padding = el.style.padding;
	el.$margin = el.style.margin;
	if(bool){
	  el = $(el);
	  var h = el.getWidth();
	  for(var i=1;i<100;i++){
		var height = Math.round(h/i); //i<50? Math.round(h/i) : 0;
		height = (num>1&&height<num)? num : height;
		height = (height<5)? 0 : height;
	    setTimeout("var el=$('"+el.id+"');el.style.width='"+height+"px';el.style.padding='0';el.style.margin='0';",100+i*speed);
	  }
	  if(r) setTimeout("$('"+el.id+"').parentNode.removeChild($('"+el.id+"'));",400+100*speed);
	} else {
	  if(r) {
		$(el.id).parentNode.removeChild($(el.id));
	  } else {
	    el.style.height = num? num+'px' : 0+'px';
		el.style.padding = '0';
		el.style.margin = '0';
	  }
	}
	
}
function slideDown(el,num){
	if(!el.$height) return; // it hasn't been slid up
	var bool = getBrowserLevel(); // only run it in IE7 and FF
	var currentHeight = el.getHeight();
	var h = el.$height;
	var p = el.$padding;
	var m = el.$margin;
	if(bool){
	  el = $(el);
	  for(var i=0;i<=h;i++){
		currentHeight++;
		currentHeight = (currentHeight<=h)? currentHeight : h;
		setTimeout("var el=$('"+el.id+"');el.style.height='"+currentHeight+"px';el.style.padding='"+p+"';el.style.margin='"+m+"';",100+i*3);
	  }
	} else {
	  el.style.height = h+'px';
	  el.style.padding = p;
      el.style.margin = m;
	}
}


function getBrowserLevel(){
   return window.XMLHttpRequest;
}

function setTabPointer(){
	$A($('Content').getElementsByClassName('TabbedContentHeader')).each(function(el){
			  Event.observe(el,'mouseover',el.onclick);
			  el.observe('mouseover',function(){ $(el.id).style.cursor='pointer'; });
		});
	/*
	var els = $('Content').descendants();
	var tabs = els.findAll(function(el){
								    return el.className.indexOf('Tab')!=-1&&el.className.indexOf('Header')!=-1;
								});
	tabs.each(function(el){
		    Event.observe(el,'mouseover',el.onclick);
			el.observe('mouseover',function(){ $(el.id).style.cursor='pointer'; });
		});
	*/
};

function setJumpTo(){
    var els = $A(document.getElementsByClassName('JumpTo'));
	if(els){
		els.each(function(el){
		    el.cleanWhitespace();
			var icon = el.down(), ancr = el.down().next().down();
			if(ancr){
				if(icon.className=='JumpToIcon'&&ancr.href){
			    icon.onmouseover = function(){this.style.cursor='pointer';}
				icon.onclick = function(){window.location=ancr.href;}	
			}
			}
		});
	}
};

function stripTitles(){
    var els = $('SiteWrapper').descendants();
	$('SiteWrapper').title="";
	els = els.findAll(function(el){ return el.title; });
	els.each(function(el){ if(el.className != 'withTitle') { el.title=""; } });
};

function updatePageBanner( ){
	if(typeof $!='function') return;
	if( !$( 'PageBanner' ) ) return;
	if(navigator.userAgent.indexOf( "MSIE" ) == -1){
	  $( 'PageBanner' ).style.left = 9+Position.cumulativeOffset($('leftCol'))[0]+$('leftCol').getWidth()+'px';
	  return;
	}
	$( 'PageBanner' ).style.left = 2+$('leftCol').getWidth()+'px';

	  $( 'PageBanner' ).style.position = 'absolute';       
	  var ch = document.body.clientHeight;
      var st = document.body.scrollTop;
      var pbh = $('PageBanner').getDimensions().height;
      $( 'PageBanner' ).style.top = (ch+st-pbh-20)+'px';
};

function SwitchTabs(id,total,num){
    if(parseInt(id)>0){
	    id=parseInt(id)-1;
	    var element, els = $('Content').getElementsByTagName('li');
        if(els[id]){
		    $(els[id].id).cleanWhitespace();
		    id=els[id].firstChild.id;
		}
	}
	for( var i = 0; i < total; i++ ) {
		var pos = i + 1;
		var currentId = id.slice(0,id.length-1)+(pos);
		var tabId = "tabHeader_"+id.slice(0,(id.length-4))+ "_" + pos;
		var oldTabId = "tabHeader_"+id.slice(0,(id.length-7))+ "_" + pos; // for backwards compatability
		if( num == pos ){
			if($(tabId)){
				$(tabId).addClassName( 'Selected' );
			} else if($(oldTabId)) {
				$(oldTabId).addClassName( 'Selected' );
			}
			if($(currentId)){
			  $(currentId).style.display='block';
			}
		} else {
			if($(tabId)){
				$(tabId).removeClassName( 'Selected' );
			} else if($(oldTabId)) {
    			$(oldTabId).removeClassName( 'Selected' );	
			}
			if($(currentId)){
			  $(currentId).style.display = 'none';
			}
		}
	}
};

function showCalendars(){
        var cons = document.getElementsByClassName('calendar');
        cons.each(function(el,i){
                Cals.push(new Calendar(el,[],[],i));
            });
}
//]]>