//jQuery.noConflict();
try 
{
	jQuery(document).ready(function(){
		
		// add underscores
		jQuery('span.underscore').before('_');	

		jQuery("#date-in").datepicker({dateFormat: 'dd/mm/yy', minDate: 0, maxDate: "+5Y", altField: '#date-out', altFormat: 'dd/mm/yy'});
        jQuery("#date-out").datepicker({dateFormat: 'dd/mm/yy', minDate: 0, maxDate: "+5Y", altField: '#us-date-out', altFormat: 'mm/dd/yy'});
        
		jQuery(".flexInputDate").datepicker({ dateFormat: 'dd-mm-yy' });
		
		// Make booking links/forms open in new window
		var bookingLinks = getElementsByClass('target-blank');
		for (var i=0; i<bookingLinks.length; ++i) {
			if (bookingLinks[i].tagName.toLowerCase()=='a') {
			 bookingLinks[i].target = bookingLinks[i].target || '_blank';
			} else if ( ( bookingLinks[i].tagName.toLowerCase()=='input' ||
			            bookingLinks[i].tagName.toLowerCase()=='button' ) &&
			                          bookingLinks[i].type.toLowerCase()=='submit') {
				var currentEl = bookingLinks[i];
				do {
				currentEl = currentEl.parentNode;
				if (currentEl.tagName.toLowerCase()=='form') {
					currentEl.target = currentEl.target || '_blank';
					break;
				}
			} while (currentEl.parentNode);
			}
		}
		
		// fancybox
		jQuery("a[rel^='lightbox']").fancybox({
			padding: 10,
			zoomSpeedChange: 700,
			frameWidth: 500,
			frameHeight: 360,
			zoomSpeedIn   : 0,
			zoomSpeedOut  : 0,
			overlayOpacity: 0.7
		});
		
		jQuery("a#video1").click(function() {
			jQuery.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'overlayOpacity': 0.7,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
                'wmode'		       : 'transparent',
				'allowfullscreen'	: 'true'
				}
			});
			return false;
		})
		
		
		// add padding if we have news content
		var newsTicker = jQuery("span.news-content");
		if (newsTicker.html()) {
			newsTicker.parent().css({"padding-left" : "8px", "padding-right" : "8px"});
		}
		
		
		// packages module item accordion content selector
		var subnavItem = jQuery('body#page_offers div#submenu li, body#page_location_museums div#submenu li');
		subnavItem.click(function() {
			var index = subnavItem.index(this);
			jQuery('div#mod_pukkaPackages div.moduleBody, div#mod_pukkaActivities div.moduleBody').accordion( 'activate', index );
			return false;
		})
		
		// gallery accordion content selector
		var galleryItem = jQuery('body#page_photos div#submenu li');
		galleryItem.click(function() {
			var gidx = galleryItem.index(this);
			jQuery('div#mod_pukkaPictures div.moduleBody').accordion( 'activate', gidx );
			return false;
		})
		
		// meetings accordion content selector
		var meetingsItem = jQuery("body.area_meetings ul.extra-links li:not(':last')");
		meetingsItem.click(function() {
			var midx = meetingsItem.index(this);
			jQuery('body#page_meetings_capacity div#main-content-body').accordion( 'activate', midx );
			return false;
		})

		
		// carousel for photos page
		jQuery('body#page_photos ul.pictures-list').jcarousel();
	   
		
		// accordion should be intitialized after carousel
		
		// if we don't pass a url hash value active item is first item
		var activeItem = window.location.hash;
		if (activeItem.length == 0) {
			activeItem = 0;
		}
		
		jQuery('div#mod_pukkaPackages div.moduleBody, div#mod_pukkaActivities div.moduleBody').accordion({
			header: 'h3',
			autoHeight: false,
			active: activeItem 
		});
																	
		jQuery( "div#mod_pukkaPictures div.moduleBody").accordion({ header: 'h3',
																	autoHeight : false,
																	active : activeItem
		});
				
		jQuery( "body#page_meetings_capacity div#main-content-body").accordion({header: 'h3', 
																				autoHeight : false, 
																				navigation : true,
																				active : activeItem
		});
		
		// hover flash number interaction
		jQuery('h3.nav-item-heading').hover(
			function() {
				var currentItem = jQuery(this).parent().index();
				var currentFloor = 8 - currentItem * 2;
				flashCallback(currentFloor);
			},
			function() {
				return false;
			}
		)
		
		// hover side nav in/out
		var sideNav = jQuery('#side-nav-inner');
		sideNav.animate({'margin-right' : '-260px'});
		jQuery('#main-visual-container, .ie-6-bugwrapper-main-visual').hover(
			function() {
				sideNav.stop().animate({
					'margin-right': '0px'
				}, 650, 'easeOutQuad');
			},
			function() {
				sideNav.stop().animate({
					'margin-right': '-260px'
				}, 850, 'easeInCubic');
			}
		)
		
		jQuery('form#booking-form input[type="text"]').addClass("idle-field");
		jQuery('form#booking-form input[type="text"]').focus(function() {
			jQuery(this).removeClass("idle-field").addClass("focus-field");
		    if (this.value == this.defaultValue){ 
		    	this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		jQuery('form#booking-form input[type="text"]').blur(function() {
			jQuery(this).removeClass("focus-field").addClass("idle-field");
		    if (jQuery.trim(this.value) == ''){
		    	this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});
		
	});	// End Document Ready
} 
catch(error) 
{
  txt="There was a js error on this page.\n\n";
  txt+="Error description: " + error.description + "\n\n";
  console.log(txt);
}
