//
//

//<![CDATA[
var Content = [];
//if(navigator.userAgent.indexOf('MSIE')!=-1) {
	Event.observe(window, "load", jsLaunch);
//} else {
	//document.observe("contentloaded", jsLaunch);
//}
function jsLaunch(){
  if(typeof $!='function') return;

	stripTitles();
	setTabPointer();
	
	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);
	    }
		
	}
	
	if($('FPASpiel')) setFPAHeights();

};
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 setTabPointer(){
    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);
		    Event.observe(el,'mouseover',function(){ $(el.id).style.cursor='pointer';});
		});
};

function stripTitles(){
    var els = $('SiteWrapper').descendants();
	$('SiteWrapper').title="";
	els.each(function(el){ if(el.title.length) el.title="";});
};

function SwitchTabs(id,total,num){
    if(parseInt(id)>0){
	    id=parseInt(id)-1;
	    var element, els = $('Content').getElementsByTagName('li');
        if(els[id]){
		    els[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 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;
}
