/* IE6 flicker fix

-------------------------------------------------- */

try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}

jQuery.fn.hasClass = function(c) { return this.is('.'+c) };

function g(r){ return document.getElementById(r); }



/* Init */



$(document).ready(function() {

	$('INPUT.onfocusclear').bind('focus',function () {

		if(!this.oldvalue){

			this.oldvalue = this.value;

		}

		if(this.value == this.oldvalue){

			this.value = '';

			$(this).removeClass('defaultvalue');

		}

	}).bind('blur',function () {

		if(this.value == ''){

			this.value = this.oldvalue;

			$(this).addClass('defaultvalue');

		}

	});

	$('.ihasahover').hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover'); });



	// Add calendar functionality to input fields



	Date.format = 'dd/mm/yyyy';

	$('INPUT.wdate').each(function() {

		$(this).datePicker({ startDate : '01/01/2008'}).dpSetOffset(0,24);

	});

	$('DIV.quickbook INPUT.wdate').each(function() {

		$(this).dpSetPosition($.dpConst.POS_TOP,$.dpConst.POS_RIGHT).dpSetOffset($(this)[0].offsetHeight+2,-4);

	});



	// Make input elements look cool

	if(jQuery.fn.makenice){ $('SELECT.makenice, INPUT.makenice, TABLE.bookform SELECT, TABLE.bookform INPUT[type="text"], TABLE.smallform SELECT, TABLE.smallform INPUT[type="text"], TABLE.smallform INPUT[type="password"]').makenice(); };

});



/* Language dropdown */



function toggleLang(ref){

	$('#languages').toggleClass('hidden');

	if(!$('#languages').hasClass('hidden')){

		$(document).bind('mouseup', toggleLang);

		$('#currentlang').bind('mouseup',function() { return false; });

		$('#languages')[0].style.left = $(ref).offset().left + 'px';

		$('#languages')[0].style.top = $(ref).offset().top + ref.offsetHeight + 'px';

	} else {

		$(document).unbind('mouseup', toggleLang);

	}

}



/* Tabs switcher */



function showTab(ref,set){

	$('#'+set+' > LI > A').each(function(i,a){

		$(a).removeClass('active');

		$($(a).attr('href')).addClass('hidden');

	});

	$(ref).addClass('active');

	$($(ref).attr('href')).fadeIn(500).removeClass('hidden').css({display: ''});

	return false;

}



/* Tooltip actions. */

function showTooltip(ref,txt,opt){

	$('body').append('<div id="tooltip"><div id="tooltip-inner">' + txt + '</div><div id="tooltip-ending"></div></div>');

	if(opt){ helper = opt; } else { helper = ref; }

	fit = $(document).width() - $(helper).offset().left - $('#tooltip').width();

	$('#tooltip')[0].style.top = $(helper).offset().top - $('#tooltip').outerHeight() + 'px';

	if( fit < 0 ){

		$('#tooltip')[0].style.left = $(helper).offset().left + fit + 'px';	

		$('#tooltip-ending')[0].style.backgroundPosition = fit - fit - ($(document).width() - $(ref).offset().left) + 'px 0';

	} else {

		$('#tooltip')[0].style.left = $(helper).offset().left + 'px';

	}

	$(ref).bind('mouseout',function() {

		$('#tooltip').unbind('mouseout');

		$('#tooltip').remove();

		$('IFRAME.bgiframe').remove();

	});

	$('#tooltip').bgiframe();

}



(function($){

	/**

	 * @name bgiframe

	 * @type jQuery

	 * @cat Plugins/bgiframe

	 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)

	 */

	$.fn.bgIframe = $.fn.bgiframe = function(s) {

		// This is only for IE6

		if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {

			s = $.extend({

				top     : 'auto', // auto == .currentStyle.borderTopWidth

				left    : 'auto', // auto == .currentStyle.borderLeftWidth

				width   : 'auto', // auto == offsetWidth

				height  : 'auto', // auto == offsetHeight

				opacity : true,

				src     : 'javascript:false;'

			}, s || {});

			var prop = function(n){return n&&n.constructor==Number?n+'px':n;},

				html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+

						   'style="display:block;position:absolute;z-index:-1;'+

							   (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+

							   'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+

							   'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+

							   'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+

							   'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+

						'"/>';

			return this.each(function() {

				if ( $('> iframe.bgiframe', this).length == 0 )

					this.insertBefore( document.createElement(html), this.firstChild );

			});

		}

		return this;

	};

})(jQuery);

/* Loginbox functions */

$(document).ready(function() {
	$('#loginbox-opener').bind('mousedown',showBox);
});

var iamfirst = false;
function showBox() {
	if(iamfirst == true){
		iamfirst = false;
		return true;
	}
	ref = $('#loginbox-opener');
	if($('#loginbox:visible').length == 0){
		$('#loginbox')
			.show()
			.css({ left: $(ref).offset().left - $('#box01').offset().left })
			.bind('mousedown',setFirst)
		;
		$(document).bind('mousedown',showBox);
		$(ref).unbind('mousedown',showBox);
		$('DIV',ref).addClass('kana');
		return false;
	} else {
		$('#loginbox').hide().unbind('mousedown',setFirst);
		$(document).unbind('mousedown',showBox);
		$(ref).bind('mousedown',showBox);
		$('DIV',ref).removeClass('kana');
		return false;
	}
}
function setFirst(){ iamfirst = true; }

/* Tabs switcher */

function showTab(ref,set){
	$('.'+set+' > LI > A').each(function(i,a){
		$(a).removeClass('active');
		$($(a).attr('href')).addClass('hidden');
	});
	$(ref).addClass('active');
	$($(ref).attr('href')).fadeIn(10).removeClass('hidden').css({display: ''});
	return false;
}
$(document).ready(function() {
	$('H2.expandable, H2.expandable01').each(function(i,a){
		$('A', a).click(function(){
			if($(this).hasClass('open')){
				$(this).removeClass('open');
				$($('A', a).attr('href')).addClass('hidden');
			} else {
				$(this).addClass('open');
				$($('A', a).attr('href')).removeClass('hidden');
			}
			return false;
		});
		if(!$('A', a).hasClass('open')){
			$($('A', a).attr('href')).addClass('hidden');
		}
	});
});