//
//

//<![CDATA[
var Content = [];

if(navigator.userAgent.indexOf('MSIE')!=-1 || typeof document.observe != 'function') {
	Event.observe(window, "load", jsLaunch);
} else {
	document.observe("dom:loaded", jsLaunch);
}
function jsLaunch(){

  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($('FPAFacilities')) setFPAHeights();
	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);
	    }
		
	}
	//alert('js runtime: ' + (new Date() - startTime) + 'ms');
  correctLinks();
};

function correctLinks(){
  $('wrapper').select('a').each(function(el){
    if(window.location.href.indexOf('m.dev.cxnx.net/') == -1){
      el.href = el.href.replace('m.dev.cxnx.net/','');
		}
  });
}

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(){
    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 {
				$(oldTabId).addClassName( 'Selected' );
			}
			$(currentId).style.display='block';
		} else {
			if($(tabId)){
				$(tabId).removeClassName( 'Selected' );
			} else {
    			$(oldTabId).removeClassName( 'Selected' );	
			}
			$(currentId).style.display = 'none';
		}
	}
};

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



var para = function(){

  return {
		version: '1.0',
		headerRunning: false,
		pos: 2,
		length: 8,
		
		
		init: function(){
			setTimeout("para.launchHeader();", 5000);
		},
		
		launchHeader: function(pos, dur){
			this.mainSlide = $('main-slide');
			this.backSlide = $('back-slide');
			this.currentSlide = this.mainSlide;
		  this.refreshSlideInterval();
		},
		
		refreshSlideInterval: function(){
		  clearInterval(this.slideInterval);
			this.slideInterval = setInterval("para.nextSlide();", 5000);
			
		},
		
		nextSlide: function(){
			var to;
			if(this.currentSlide == this.mainSlide){
			  this.currentSlide = this.backSlide;
				this.offSlide = this.mainSlide;
				to = 0;
			} else {
			  this.currentSlide = this.mainSlide;
				this.offSlide = this.backSlide;
				to = 1;
			}
			this.pos++;
			if(this.pos > this.length) this.pos = 1;
			new Effect.Opacity($('main-slide'), {duration: 1, to: to, afterFinish: function(){
        var src = '00'+this.pos+'.jpg';
				this.offSlide.src = ROOT+'/images/slides/' + src;
			}.bind(this)});
		}
	}

}();
if(document.all){
Event.observe(window, 'load', para.init.bind(para));
} else {
Event.observe(window, 'dom:loaded', para.init.bind(para));
}

//]]>