var xmas = true;

$(document).ready
(
	
	function()
	{
		$('a[href^="http://"]').attr("target", "_blank");
		$('a[href$=".pdf"]').attr("target", "_blank");//open pdfs in a new window
		menuSelector();
		alignBlockHeights($('div.announcement_block'),'p:last');
		$('p.button  a').hover(
			function()
			{
				$(this).css('background','url(/z_images/structure/book_now_on.gif) no-repeat bottom left');
			},
			function()
			{
				$(this).css('background','url(/z_images/structure/book_now.gif) no-repeat bottom left');
			}
		);
		$('.menu_select  a').click(
			function()
			{
				menuSelector(this);
				return false;
			}
		);
		
		if(xmas)
		{
			xmasDecorations();
		}
		
		$('div.abs div.special_offer a').each(
			function(index)
			{
			var link_obj = $(this);
			var a_link = link_obj.attr('href');
			//var a_title = $(this).attr('title');
			var arrow_str = '&nbsp;<a href="'+a_link+'"><img src="/z_images/structure/offer_arrow.jpg" /></a>';	
			link_obj.after(arrow_str);
			}//function
		);
		
		$(window).bind('resize', function() {
		
		if(xmas)
		{
			xmasDecorations();
		}
		
		});
		
		var testimonials_count = $('p.quote').length;
		if(testimonials_count > 0)
		{
			//alert(testimonials_count);
			var padding_left = 20;
			var margin_top = 5;
			$('p.quote').each(
			function(index)
			{
				//$(this).find('span').after(' <span class="jq_close">&nbsp;</span>');
				if($(this).find('span').length==0)
				{
					$(this).wrapInner('<span></span>');
				}
				$(this).find('span').after(' <span class="jq_close"><img src="/z_images/structure/close_quote.gif" style="display:inline;" /></span>');
				var p_left = $(this).position().left;
				var p_width = $(this).width();
				var el = $(this).find('span.jq_close');
				var height = el.height();
				var width=el.width();
				var pos = el.position();
				if(typeof(pos) != 'undefined')
				{
				var x = pos.left;
				
				var y = pos.top;
				
				if(x==padding_left)//then carriage return forced
				{
					x= p_width+5+width;
					y = y-height;
				}
				
				y = y + margin_top;
				
				el.css({'position' : 'absolute', 'left' : x,'top' : y});
				}
				
				//alert(' span x: '+pos.left,)
			}//function
			);//each
		}
		
	}
	
);


function alignBlockHeights(blocks) 
{
	/*
		Must be supplied one parameter at least - relatively or absolutely positioned blocks whose height must be equal where content produces different height
		If the second parameter is supplied it must be a jquery selector for the last element in each block to be horzontally aligned with one another
		
	*/
	var last_el_top = 0;
	var max_height = 0;
	var max_block = null;//the block with greatest height
	arguments.length == 2?align_last_els = arguments[1]:align_last_els = 0;
	count=0;
	$(blocks).each(
		function(i)
		{
			count++;
			var el = $(this);
			var height = el.height();
			max_height = Math.max(max_height,height);
			if(max_height==height)
			{
				//max_block = $(this);
				//alert(count);
				max_block = el;
				if(align_last_els != 0)//find the bottom pos of last link if it exists and parent el is the tallest found so far
				{
					last_el = $(el).find(align_last_els);
					
					var coords = $(last_el).position();
					last_el_top = coords.top;
					
				}
			}
		}//function
	);//each
	//alert(count)
	if(max_block != null)
	{
		
		//$(blocks+':not('+max_block+')').css('height',max_height);
		
		$(blocks).not(max_block).css('height',max_height);
		if(align_last_els != 0)
		{
			$(blocks).not(max_block).each(
				function(i)
				{
					var el = $(this).find(align_last_els);
					var coords = $(el).position();
					var x = coords.lft;
					$(el).css({'position' : 'absolute', 'left' : x,'top' : last_el_top});
				}
			);//each
		}
	}
	
}//function

function xmasDecorations()
{
	var padding = 16;
	var x1 = $('div.outer_container').position().left;
	var w1 = $('div.trees_left').width();
	
	x1 = (x1-w1)+padding;
	var x2 = $('div.outer_container').position().left + $('div.outer_container').width();
	x2 = x2+padding;
	
	$('div.trees_left').css('left',x1);
	$('div.trees_right').css('left',x2);
	$('div.trees_left:hidden').show();
	$('div.trees_right:hidden').show();
}

function menuSelector()
{
	$('.menu_group:visible').hide();
	$('table.menu:visible caption').hide();
	$('.menu_select  a').removeClass('on');
	if(arguments.length == 1 && typeof arguments[0]=='object')
	{
		var obj = arguments[0];
		var thisID = $(obj).attr('href');
		 $(obj).addClass('on');
		$(thisID).show();
		
	}
	else
	{
		var showFirstID = $('.menu_select > li:first > a').attr('href');
		if(typeof showFirstID!='undefined')
		{
			$('.menu_select > li:first > a').addClass('on');
			$(showFirstID).show();	
		}
	}

	
}

if(!Array.indexOf){//index of breaks ie
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

try {//ie6 image swap cache problem
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


function isset( variable )

{

	return( typeof( variable ) != 'undefined' );

}
if(isset(window.preload_obj))
{
	
	for(var i=0; i<preload.length; i++){preload_obj.src =preload[i];}
	
}

function eml_snd(part2,part1)
{
	mail_str = 'mailto: '+part1+'@'+part2;
	return mail_str;
}

