/** HELPER FUNCTIONS **/	
	function Is() {
		agent = navigator.userAgent.toLowerCase();
		this.major = parseInt(navigator.appVersion);
		this.minor = parseFloat(navigator.appVersion);
		this.ns = ((agent.indexOf('mozilla') != -1) &&
		(agent.indexOf('spoofer') == -1) &&
		(agent.indexOf('compatible') == -1) &&
		(agent.indexOf('opera') == -1) &&
		(agent.indexOf('webtv') == -1) &&
		(agent.indexOf('hotjava') == -1));
		this.ns2 = (this.ns && (this.major == 2));
		this.ns3 = (this.ns && (this.major == 3));
		this.ns4 = (this.ns && (this.major == 4));
		this.ns6 = (this.ns && (this.major >= 5));
		this.ie = ((agent.indexOf("msie") != -1) &&
		(agent.indexOf("opera") == -1));
		this.ie3 = (this.ie && (this.major < 4));
		this.ie4 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 4") != -1));
		this.ie5 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 5.") != -1) &&
		(agent.indexOf("msie 5.5") == -1) &&
		(agent.indexOf("mac") == -1));
		this.iem5 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 5.") != -1) &&
		(agent.indexOf("mac") != -1));
		this.ie55 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 5.5") != -1));
		this.ie6 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 6.") != -1));
		this.ie7 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 7.0b") != -1));
		this.nsdom = (this.ns4 || this.ns6);
		this.ie5dom = (this.ie5 || this.iem5 || this.ie55);
		this.iedom = (this.ie4 || this.ie5dom || this.ie6);
		this.w3dom = (this.ns6 || this.ie6 ||this.ie7);
}
var is = new Is();
	

function TB_position(layer,width,height) {
	var pagesize = getPageSize();	
	var arrayPageScroll = getPageScrollTop();
	$("#"+layer).css({left: ((pagesize[0] - width)/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-height)/2))+"px" });
}

function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return arrayPageScroll;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

var posX = 0;
var posY = 0;

window.document.onmousemove = getMouseXY;

function getMouseXY(e) {

	if(navigator.appName == "Netscape"){
		posX = e.pageX
	 	posY = e.pageY

	} else {
		posX = event.clientX + document.body.scrollLeft
 		posY = event.clientY + document.body.scrollTop
	}

	if (posX <= 0) {posX = 0} 
	if (posY <= 0) {posY = 0}   
 	return true
}

/** END HELPER FUNCTIONS **/



// JavaScript Document

$(document).ready(function(){
	$("#home_copy").mouseover(function(){
		$(this).removeClass('left').addClass('left_on');
	});
	
	$("#home_copy").mouseout(function(){
		$(this).removeClass('left_on').addClass('left');
	});
	
	$("#home_copy").click(function(){
		location.href = 'acommodations.php';
	});
	
	$(".houses_nav a").click(function(){
			$(".houses_nav a").removeClass('house_on');
			var num = $(this).attr('name');
			$(this).addClass('house_on');
			//$("#house_image").children('img').attr('src','images/acommodations_plan_'+num+'.gif');
			$("#house_image").children('img').fadeOut('normal',function(){
				$(this).remove();
				$("#house_image").append('<img src="images/acommodations_plan_'+num+'.gif" style="display:none;" />');
				$("#house_image").children('img').fadeIn();
			});
	});
	
	
	$("a.pop_amenities").click(function(){
			var arrayPageScroll = getPageScrollTop();
			
			var height = parseInt($("#pop_amenities").height());
			$("#pop_amenities").css('top',posY+arrayPageScroll[1]-height-20+'px').fadeIn();
			return false;
	
	});
	
	$("a#friend").click(function(){
			var height = parseInt($("#tell_a_friend").height());
			var width = parseInt($("#tell_a_friend").height());
			var page = $("body").attr('id');
			TB_position('tell_a_friend',width,height);
			//else $("#tell_a_friend").css('top',posY-280+"px").css('left',posX-700+"px");
			$("#tell_a_friend").fadeIn();
			return false;
	
	});
	
	$("a#terms").click(function(){
			var height = 380;
			var width = 780;
			var page = $("body").attr('id');
			TB_position('popup_holder',width,height);
			
			$("#popup_holder .pop_content").load('php/terms.php','',function(str){
				$("#popup_holder").fadeIn();
			});
			
			
			return false;
	
	});
	
	$("a#privacy").click(function(){
			var height = 380;
			var width = 780;
			var page = $("body").attr('id');
			TB_position('popup_holder',width,height);
			
			$("#popup_holder .pop_content").load('php/privacy.php','',function(str){
				$("#popup_holder").fadeIn();
			});
			
			
			return false;
	
	});
	
	$(".close a").click(function(){
		$(this).parent('div').parent('div').parent('div').fadeOut();
		return false;
	});
	
	$("#callout_email").mouseover(function(){
		$(this).removeClass('email').addClass('email_on');
	});
	
	$("#callout_email").mouseout(function(){
		$(this).removeClass('email_on').addClass('email');
	});
	
	$("#callout_email").click(function(){
		location.href = 'mailto:info@seascapexuma.com';
	});
	
	
	$("#btn_submit").mouseover(function(){
		$(this).attr('src','images/btn_send_on.gif');
	});
	
	$("#btn_submit").mouseout(function(){
		$(this).attr('src','images/btn_send_off.gif');
	});
	
	$("a#submit").click(function(){
		var p = {};						 	
		$("#tell_a_friend input").each(function(){
			var name = $(this).attr('name');
			var value = $(this).val();
			
			p[name] = value;
		});
		
		$("#tell_a_friend textarea").each(function(){
			var name = $(this).attr('name');
			var value = $(this).val();
			
			p[name] = value;
		});
		
		$("#tell_a_friend .pop_content").load('php/email.php',p,function(str){
																
		});
		
	});
	
});
