var sendToFriendWindow,subscribeWindow;

// reset the captcha number
function resetSecurityNumber(fieldId,imageId)
{
	 var date = new Date();
	 if (fieldId != null && fieldId != '') $('#' + fieldId).val('');
	 if (imageId != null && imageId != '') $('#' + imageId).attr('src','/includes/captcha/CaptchaSecurityImages.php?width=120&height=40&noCache=' + date.getSeconds());
	 $('#' + fieldId).focus();
	 return false;
}

// show a dd/li dropdown
function showDropdown(field)
{
	$(field).slideDown();
}

// hide a dd/li dropdown
function hideDropdown(field)
{
	$(field).slideUp();
}

// load send to friend lightbox
function sendToFriend(url)
{
	url = url || location.href;
	sendToFriendWindow.load('/lightbox/lightbox_send_to_friend.php',{url:url});
	return false;
}

// load subscribe lightbox
function subscribe()
{
	subscribeWindow.load('/lightbox/lightbox_subscribe.php');
	return false;
}

function _alert(error)
{
	var alertwindow = $.alertWindow({timeout: 2000});

	if(typeof(error) != 'object'){
		alertwindow.alert(error);
	}else{
	 if(error.retryAttempt-1!= error.retries)
	 {
			alertwindow.alert(error.message+'<p>Attempting retry '+error.retryAttempt+'/'+error.retries+' in '+(error.timeout/1000)+' seconds</p>');
		}else{
			alertwindow.alert(error.message);
		}
	}
}

function convertHeaders(scope)
{
	scope = scope || document;
	$('.cms_copy h2:visible,.cms_copy h3_bk:visible',scope).each(function()
								  {
									var header = $(this);
									var headerText = header.html();
									headerText = headerText.replace(/<.*?>/ig,''); // remove any tags
									var getHeader = $(this).loader({insertType: 'after'});
									header.addClass('hide');
									getHeader.load('/includes/get_header.php',
												   {header: headerText,tagname: this.tagName.toLowerCase()},
												   function()
												   {
														header.html(headerText);
													});
								  });
}

function showListToggle(showClass)
{

	var list = $('.lodge_dropdown_list li[class=africa],.lodge_dropdown_list li[class=india]');
	hideDropdown(list);

	if($('.lodge_dropdown_list li[class='+showClass+']:visible').length == 0)
	{
		showDropdown('.lodge_dropdown_list li[class='+showClass+']');
	}
	return false;

}

function disableContextmenu()
{

		$('img').bind('contextmenu',function(e){

										if(e.stopPropagation)
										{
											e.stopPropagation();
										}
										e.preventDefault();

									});
}
function pngfix()
{
	if($.browser.msie && $.browser.version < '7.0')
	{
		$('img[@src$=.png],.pricetag .inner, .png_frame').css('behavior','url(/images/iepngfix.php)');
	}
}
var lodgeDropdown;

$(document).ready(function()
				{
					disableContextmenu();
					//create send to a friend lightbox
					sendToFriendWindow = $('#sendToFriendWindow').window({
																	width: 600,
																	height: 420,
																	zindex:4,
																	titlebar: false,
																	softshadow: false,
																	popup: true,
																	autoload: false,
																	align:'center',
																	valign:'center'
																});

					subscribeWindow = $('#subscribeWindow').window({
																	width: 600,
																	height: 420,
																	zindex:4,
																	titlebar: false,
																	softshadow: false,
																	popup: true,
																	autoload: false,
																	align:'center',
																	valign:'center'
																});

				//setup lodge dropdown
					$('.lodge_dropdown a').click(function(){
														if($('.lodge_dropdown_list').is(':visible'))
														{
															hideDropdown('.lodge_dropdown_list');
														}else
														{
															showDropdown('.lodge_dropdown_list');
														}
														return false;
													});

					$('.lodge_dropdown a, .lodge_dropdown_list li').mouseout(function()
											{

												lodgeDropdown = setTimeout("hideDropdown('.lodge_dropdown_list')",1000);
											});
					$('.lodge_dropdown a, .lodge_dropdown_list li').mouseover(function()
											  {
												 clearTimeout(lodgeDropdown);
												 lodgeDropdown = null;
											  });
					$('#lodge-list').fadeIn('slow');

					//setup share link dropdown
					$('#shareLink').toggle(function()
											{
												var offset = $(this).offset();
												offset.left -= $('#shareIt').width() - $(this).outerWidth()+5;
												offset.top += $(this).outerHeight() +5;
												$('#shareIt').css(offset);
												showDropdown('#shareIt');

											},function()
											{

												hideDropdown('#shareIt');

											});

					//fires close of dropdown when a link is clicked on
					$('.share-it a').mousedown(function()
											{
												$('#shareLink').trigger('click');
											});

					//text size accessibility
					$('#smallerText').click(function(event)
								{
									if(document.getElementById('container').style.zoom != undefined)
									{
										var zoomLevel = (document.getElementById('container').style.zoom !='')? parseInt(document.getElementById('container').style.zoom) : 100;

										zoomLevel-= 10;
										if(zoomLevel > 0)
										{
											document.getElementById('container').style.zoom = zoomLevel+'%';
										}
									}else
									{
										var fontSize = parseInt($('p').css('font-size'));
										$('p').css('font-size',fontSize-1);
									}
									return false;
								});
					$('#biggerText').click(function(event)
								{
									if(document.getElementById('container').style.zoom != undefined)
									{
										var zoomLevel = (document.getElementById('container').style.zoom !='')? parseInt(document.getElementById('container').style.zoom) : 100;

										zoomLevel+= 10;
										document.getElementById('container').style.zoom = zoomLevel+'%';
									}else
									{
										var fontSize = parseInt($('p').css('font-size'));
										$('p').css('font-size',fontSize+1);
									}
									return false;
								});

					convertHeaders();
					pngfix();
});