
ua = navigator.userAgent.toLowerCase(); 
isIE = ((ua.indexOf("msie") != -1) );
isIE5 = ((ua.indexOf("msie 5") != -1) );
isIE6 = ((ua.indexOf("msie 6.0") != -1) );
isIE7 = ((ua.indexOf("msie 7.0") != -1) );
isOPERA = ((ua.indexOf("opera") != -1) );
isFF = ((ua.indexOf("firefox") != -1) );
isSafari = ((ua.indexOf("safari") != -1) );

if(isIE5 || isIE6) {
	alert("Your browser is outdated!\nPlease update your browser.");
}

function clearDefault(defVal,e) {
		if(e.value == defVal) {
			e.value='';
		}
}

function restoreDefault(defVal,e) {
		if(e.value == '') {
			e.value=defVal;
		}
}

function myDialog(selector,permitClose) {

	winW = $('body').width();
	winH = $('body').height();

	var layoutCss={
		height: winH,
		width: winW,
		display: 'block'
	};
	$(selector).css(layoutCss);
	$(selector+' .dialog-layout').css(layoutCss);
	$(selector+' .dialog-opacity').fadeTo(0,0);
	$(selector+' .dialog-opacity').fadeTo(800,0.7);
	$(selector+' .dialog-content').show();
	if(!permitClose) {
		$(selector+' .dialog-close').click(function() {$(selector).css('display','none');});
		$(selector+' .dialog-opacity').click(function() {$(selector).css('display','none');});
	}
	$(selector+' .dialog-wrapper').css({
//		top: ((window.innerHeight-$(selector+' .dialog-content').height())/2),
		top: 100,
		left: ((winW - $(selector+' .dialog-wrapper').width())/2)
	});

}

function genTabs(a,e,callback) {
	
	var debug 					= 		document.getElementById("debugdiv");
	
	$(a).unbind('click');
	$(a).click(function() {
		$(a).removeClass('active');
		$(this).addClass('active');
		$(e+' .tabcontent').hide();
		var curr=$(this).attr('rel');
		$(e+' .'+curr).show();
		if(typeof(callback) != "undefined") {
			callback(curr);
		}
		return false;
	});
}

function selectTab(tabname, groupClass,set) {
	
		var currentGroup 	= 		document.getElementById(groupClass);
		var listItems			=		currentGroup.getElementsByTagName("li");
		
		var selectedTab;
		
	for (var i = 0; i < listItems.length; i++) {
			
			if(listItems[i].getElementsByTagName("a")[0].rel ==  tabname) {
				
				selectedTab				=		 listItems[i].getElementsByTagName("a")[0];
				
			$('.'+set+' .'+tabname).show();
				
			}else{
				
				var deselectItems		=		 listItems[i].getElementsByTagName("a")[0];
			
				$(deselectItems).removeClass('active');
				
				$('.'+set+' .'+ listItems[i].getElementsByTagName("a")[0].rel).hide();
				
			}
			
		$(selectedTab)	.addClass('active');
		
}
		
}

var carouselSpeed=200;

$(document).ready(function(){
	$(".accordion .header").click(function () {
		var text = $(this).parent().children('.content').stop();

		if (text.is(':hidden')) {
			if(false) {text.toggle('blind',{},300);} else {text.slideDown(300);};
			$(this).parent().addClass('open');
		} else {
			if(false) {text.toggle('blind',{},300);} else {text.slideUp(300);};
			$(this).parent().removeClass('open');
		}
	});

	$("..accordion .header").first().click();

	genTabs('.tabset1 > .tabs > li > a','.tabset1');
	genTabs('.tabset2 > .tabs > li > a','.tabset2');
	

	$('#checkform .button1').click(function() {myDialog('#loading',true);$('#checkform').submit();});
	$('#dialog-checkform .button1').click(function() {$('#search').css('display','none');myDialog('#loading',true);$('#dialog-checkform').submit();return false;});
	$('.opensearch').click(function() {myDialog('#search'); return false;});
	$('.availability').click(function() {myDialog('#search');return false;});

	var today = new Date();
	var first = new Date(2011,02,11);
	if(today<first) {
		today=first;
	}
	$('input[name=in]').each(function(i,element) {
		$(element).DatePicker({
			date: today,
			current: today,
			format: 'd B Y',
			position: 'bottom',
			onChange: function(formated) {
				$('input[name=in]').val(formated);
				var inDate = new Date(formated);
				var outDate = new Date(Number(inDate.getTime())+86400000);
				$('input[name=out]').DatePickerSetDate(outDate,true);
				$('input[name=out]').val($('input[name=out]').DatePickerGetDate(true));
				$(element).DatePickerHide();
			}
		});
		$(element).val($(element).DatePickerGetDate(true));
	});
	$('input[name=out]').each(function(i,element) {
		$(element).DatePicker({
			date: new Date(Number(today.getTime())+86400000),
			current: new Date(Number(today.getTime())+86400000),
			format: 'd B Y',
			position: 'bottom',
			onChange: function(formated) {
				$(element).val(formated);
				$(element).DatePickerHide();
			}
		});
		$(element).val($(element).DatePickerGetDate(true));
	});
	$('.calendar').click(function() {$(this).parent().children('input').first().click(); return false;});

	if(isOPERA || isSafari) {
		$('select').addClass('opera');
	}

	


});

//-----------------------------------------------
function debug(txt)
{
try {
	console.debug(txt);
	}
catch(e){}
}
