$j(document).ready(function() {
	load_scrollbar();
	
	var FullscreenrOptions = { width: 1280, height: 1024, bgID: '.bg img' };
	jQuery.fn.fullscreenr(FullscreenrOptions);
	
	$j("body").prepend('<div class="bb t"></div>');
	$j("body").prepend('<div class="bb b"></div>');
	$j("body").prepend('<div class="bb l"></div>');
	$j("body").prepend('<div class="bb r"></div>');
	
	$j('input[title!=""]').hint();

	if ( $j("#article_gal a img").length > 0 ) { 
			$j('#article_gal a:has(img)').lightBox();
		}
	
	// external links	
	$j('a[rel*=external]').click( function() {
        window.open(this.href);
        return false;
    });
	
	$j("#checkin").datepicker({ dateFormat: 'dd/mm/yy' });

	/* for future usage in contact form - show / hide the extra fields 
	$j('#ShowHideBooking').click( function() {
       $j('#booking_fieldset').toggle();
	   $j(this).toggleClass("block2");
    });
	*/


});

$j(window).resize(function() { load_scrollbar(); });
$j(window).load(function() { $j(".bg").fadeIn("slow"); });

function load_scrollbar() {
	fix_container_height();
	if (($j.browser.msie) && (parseInt($j.browser.version, 10) == "7")) {  }	else { $j('.main').jScrollPane({autoReinitialise: true}); }
}

function fix_container_height() {
	footer_height = $j("#footer").height() + 50;
	top_middle = $j("#middle").position().top;
	top_footer = $j("#footer").position().top;
	result = (top_footer - top_middle) - footer_height;
	$j("#middle").height(result);
}

(function($){	
	$.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
		if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
		if(options.bgID === undefined) alert('Please supply the background image ID, default #bgimg will now be used.');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options.bgID).fullscreenrResizer(options);	});
		$(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		}
		// Center the image
		$(this).css('left', (browserwidth - $(this).width())/2);
		$(this).css('top', (browserheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);



jQuery.fn.hint = function (blurClass) {
	if (!blurClass) { 
		blurClass = 'blur';
	}
	
	return this.each(function () {
	// get jQuery version of 'this'
		var $input = jQuery(this),
		
		// capture the rest of the variable to allow for reuse
		title = $input.attr('title'),
		$form = jQuery(this.form),
		$win = jQuery(window);
		
		function remove() {
		  if ($input.val() === title && $input.hasClass(blurClass)) {
			$input.val('').removeClass(blurClass);
		  }
		}
		
		// only apply logic if the element has the attribute
		if (title) { 
		  // on blur, set value to title attr if text is blank
		  $input.blur(function () {
			if (this.value === '') {
			  $input.val(title).addClass(blurClass);
			}
		  }).focus(remove).blur(); // now change all inputs to title
		
		  // clear the pre-defined text when form is submitted
		  $form.submit(remove);
		  $win.unload(remove); // handles Firefox's autocomplete
	}
	});
};


/* Mouse Wheel */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(a($){d b=[\'z\',\'6\'];$.2.M.6={B:a(){7(4.l){m(d i=b.q;i;){4.l(b[--i],e,v)}}n{4.o=e}},K:a(){7(4.p){m(d i=b.q;i;){4.p(b[--i],e,v)}}n{4.o=P}}};$.9.A({6:a(9){h 9?4.E("6",9):4.F("6")},I:a(9){h 4.J("6",9)}});a e(2){d 5=2||L.2,g=[].O.x(y,1),8=0,C=D,f=0,c=0;2=$.2.G(5);2.H="6";7(2.r){8=2.r/j}7(2.t){8=-2.t/3}c=8;7(5.u!==k&&5.u===5.N){c=0;f=-1*8}7(5.w!==k){c=5.w/j}7(5.s!==k){f=-1*5.s/j}g.Q(2,8,f,c);h $.2.R.S(4,g)}})(T);',56,56,'||event||this|orgEvent|mousewheel|if|delta|fn|function|types|deltaY|var|handler|deltaX|args|return||120|undefined|addEventListener|for|else|onmousewheel|removeEventListener|length|wheelDelta|wheelDeltaX|detail|axis|false|wheelDeltaY|call|arguments|DOMMouseScroll|extend|setup|returnValue|true|bind|trigger|fix|type|unmousewheel|unbind|teardown|window|special|HORIZONTAL_AXIS|slice|null|unshift|handle|apply|jQuery'.split('|'),0,{}))


