$(function()
{	
	$('#offers > ul > li').each(function(i)
	{
		if (i % 3 == 0)
		{
			var $this = $(this);
			
			var $group = $this.add($this.nextAll());
			
			$group.equalizeCols();
		}
	});
	
	// Open external links in a new window
	$('a[href^="http://"]').click(function()
	{
		var href = $(this).attr('href');
		
		if (href.indexOf('globehotel.') == -1)
		{
			window.open(href);
			return false;
		}
	});
	
	Map.init();
	QuickBook.init();
	
	$("a.zoom").fancybox();
	
});

var QuickBook =
{
	init:function()
	{
		$('ul#nav li.book a').click(function()
		{			
			var clicked = true;
			
			var $this = $(this);
			
			var $quick_book = $('body > #book-now.drop-down');
			
			if ($quick_book.size())
			{
				if ($quick_book.is(':visible'))
				{
					$quick_book.slideUp('fast');
				}
				else
				{
					$quick_book.slideDown('fast');
				}
			}
			else
			{
				var link_text = $this.text();
							
				var loading_text = (link_text.toLowerCase() == 'boka nu') ? 'Laddar...' : 'Loading...';
				
				var width = $this.css('width');
				
				$this.css({'width':width}).text('↑ ↑ ↑');
				
				$.get('/snippets/book-now',function(data)
				{
					$('body').prepend(data).find('#book-now.drop-down').hide().slideDown('normal',function()
					{
						$this.text(link_text);
					});
				});
			}
			
			return false;
		});
	}
};

var Map =
{
	init:function()
	{
		if ($('#hitta-hit-section').size())
		{
			Map.init_find_us_page_map();
		}
		
	},
	
	init_find_us_page_map:function()
	{
		if ( ! $('#map').size())
		{
			return false;
		}
		
		if (GBrowserIsCompatible())
		{
			var map = new GMap2(document.getElementById("map"));
						
			var marker_coordinates = new GLatLng(59.29253, 18.08371);
			var center_coordinates = new GLatLng(59.31, 18.15);

			map.setMapType(G_PHYSICAL_MAP);
			
			map.addControl(new GSmallZoomControl3D());
			
			map.setCenter(center_coordinates, 12);
			
			map.addOverlay(new GMarker(marker_coordinates));
		}
	}
};


/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
 
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);