jQuery.noConflict();

var tools = {
	is_array : function(input){
		return typeof(input)=='object'&&(input instanceof Array);
	}
};

var wizard = {
	getOverriders : function(){
		var overriders = [];
		$$('input.overrider').each(function(item){
			if(item.checked == true)	overriders.push(item.get('value'));
		});
		
		var el = new Element('input', {
			'type' : 'hidden',
			'name' : 'overriders',
			'value': JSON.encode(overriders)
		});
	//	alert(JSON.encode(overriders));
		$('wizard').adopt(el);
	}
};

var guideNav = {
	accordion : function(){
		
		$$('div.guideNavigation').each(function(item){
			var slider = item.getElement('ul');;
			var toggler = item.getElement('h3');;
			var slide = new Fx.Slide(slider);
			
			var loc = toggler.get('id').replace(/ /g,'_').toLowerCase();
			if(location.href.toLowerCase().indexOf(loc) == -1)	slide.hide();
			if(location.href.toLowerCase().indexOf('extra') != -1 && loc == 'overview')	slide.show();
			if(location.href.toLowerCase().indexOf(loc) != -1)	toggler.addClass('expand');
			toggler.addEvents({
				'click' : function(e){
					slide.toggle();
						this.className = (this.hasClass('expand'))? '' : 'expand';
					e.stop();
				},
				'mouseover' : function(){
					this.setStyle('cursor', 'pointer');
				}
				
			});
		});
	}
};

window.addEvent('domready', function(){

	guideNav.accordion(); 
/**
 * Alternative way for the accordion
 *	/ 
	jQuery('#left').tabs("#left ul", {
		tabs: 'h3', 
		effect: 'fade', 
		current: 'expand'
	});
/ *	
 */
	
	if($('destinations'))
	{
		$('destinations').addEvent('change', function(e){
			window.location = '/Guide/' + $('destinations').get('value') + '/Overview/Introduction';
			e.stop();
		})
	}
	
	if($('wizard'))
	{
		$('wizard').addEvent('submit', function(e){
			wizard.getOverriders();
		//	e.stop();
		});
	}

	if(location.href.match(/\.com\/$|\.net\/$/))
	{
		homeMap.initializeHomeMap();
	}

});

/*
*	Multiple submit buttons on top10 pages form
*/	

    jQuery(document).ready(function(){

	    jQuery(".jQbookingForm").change(function () {
		    if(jQuery(jQuery(this).val() != ''))
	    	{
				jQuery('#selectedDestination').attr('value', jQuery(this).val());        
			}   
		})


	    jQuery(".top20BookingButton").click(function(){

		//	if(jQuery('#AllDestinations').val() == '' && jQuery('#Top20Destinations').val() == '')
			if(jQuery('#selectedDestination').val() == '')
			{
				window.alert("Please select a destination")
				return false;
	    	} else {
				var dest = jQuery('#selectedDestination').val();
			/*	var dest = jQuery('#AllDestinations').val();
				if(jQuery('#Top20Destinations').val() != '')
				{
					var dest = jQuery('#Top20Destinations').val();
				}
			*/

				url = '/' + jQuery(this).val() + '/' + dest;
			//	url = '/' + jQuery(this).attr('title') + '/' + dest;
			//	currentButton = '#' + jQuery(this).attr('id');
				
			//	jQuery(this).attr('href', url);
			//	jQuery(currentButton).attr('href', url);
				

				/* IE8 blocks the popup and submit the form anyway   */
				jQuery('form#top10Form').attr({action: url});
				
				openDeals(url);
				
			//  location.href = '/' + jQuery(this).val() + '/' + dest;

				return false;
				
			}
    	});


		jQuery("#btn_search_deals").click(function(){

				url = '/' + jQuery('#Deal_Holidays').val();
				
				/* IE8 blocks the popup and submit the form anyway   */
				jQuery('form#top10typesForm').attr({action: url});
				
	    		jQuery(this).popupBookingWindow({ 
		    	height:700, 
	    		width:980,
			    top:30, 
	    		left:30,
				windowURL:url 
			    });   
				
				return false;
    	});

	});  


		
	function openDeals(url) 
	{
	    jQuery('.top20BookingButton').popupBookingWindow({ 
    	height:700, 
	    width:980,
	    top:30, 
	    left:30,
		windowURL:url 
	    }); 
	}

/*
*  A very basic pop up window function
*/

	function openPage(url) {
		newWin = window.open(url, "newPage", "toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,width=980,height=700,left=30,top=30")
		setTimeout('newWin.focus();',250);
	}

	function openHtmlPage(url) {
		newHtmlWin = window.open(url, url, "toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,width=980,height=700,left=30,top=30")
		setTimeout('newHtmlWin.focus();',250);
	}
	
