
$(document).ready(function() {

	/* IE6 fix for dropdowns  */

	if (document.all) {
	
		 $("#globalnav li").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});

				
       $("#mainnav li").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		$("#pagetools").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		
		$("#space div").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		$("#btn_spaceforlease").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		$("div.legend").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
    }
	
	/* Page tools */
	
	$("#email").click(function(){
		location.href='mailto:?SUBJECT=Link to Website of LAREM - (http://www.lareminc.com)&BODY=Below is a link to a page from the LAREM web site that contains information I think you%27ll find interesting:%0D%0A%0D%0ATo view the page, visit '+escape(location.href)+'%0D%0A%0D%0A--------------------------------------------------------%0D%0Ahttp://www.lareminc.com/%0D%0';
		return false;
	}).hover(function(){
		$("#pagetools span.info").html("Email this page");
	},function(){
		$("#pagetools span.info").html("&nbsp;");
	});
	
	$("#bookmark").click(function(){
	
		var general = "First click OK and then hit CTRL+D to bookmark this page.";
		var opera =" First click OK and then hit CTRL+T to bookmark this page.";
	
		if($.browser.opera)
			alert(opera);
		else
			alert(general);
			
		return false;
	}).hover(function(){
		$("#pagetools span.info").html("Bookmark this page");
	},function(){
		$("#pagetools span.info").html("&nbsp;");
	});
	
	$("#print").click(function(){
		print();
		return false;
	}).hover(function(){
		$("#pagetools span.info").html("Print this page");
	},function(){
		$("#pagetools span.info").html("&nbsp;");
	});
	
	$("p.print a").click(function(){
		print();
		return false;
	});
	
	/* Prepare external links */
	
	$("a").each(function(i){
		if($(this).attr("rel")=="external")
			$(this).attr("target","_blank");

	});
	
	/* Text Size tools */
	
	if($.cookie("ac_textsize")==null)
		$("#maincontent").attr("class","small");
	else
		$("#maincontent").attr("class",$.cookie("ac_textsize"));

	$("#pagetools #increase").click(function(){

		if ($("#maincontent").attr("class")=="small")
			$("#maincontent").attr("class","medium");
		else
			$("#maincontent").attr("class","large");
			
		$.cookie('ac_textsize', $("#maincontent").attr("class"), { path: '/', expires: 60 });
		
		return false;
	}).hover(function(){
		$("#pagetools span.info").html("Increase text size");
	},function(){
		$("#pagetools span.info").html("&nbsp;");
	});
	
	
	$("#pagetools #decrease").click(function(){
		if ($("#maincontent").attr("class")=="large")
			$("#maincontent").attr("class","medium");
		else
			$("#maincontent").attr("class","small");
			
		$.cookie('ac_textsize', $("#maincontent").attr("class"), { path: '/', expires: 60 });
			
		return false;
	}).hover(function(){
		$("#pagetools span.info").html("Decrease text size");
	},function(){
		$("#pagetools span.info").html("&nbsp;");
	});
	
	
	/* Linkareas  */
	
	$(".linkarea").hover(function(){
		$(this).css({ cursor: 'pointer' });
	},function(){
	});
	
	
	$(".linkarea").click(function(){
		$(this).find("a").eq(0).click();
	});
	
	$(".linkarea a").click(function(){

		if ($(this).attr("rel")=="external") {
			var newWindow = window.open($(this).attr("href"), '_blank');
			newWindow.focus();
				
			return false;
		}
		else {
			document.location = $(this).attr("href");
			
			return false;
		}
	});		
	
	$(".linkarea.thickbox").unbind("click");
	
	$(".linkarea.thickbox").click(function(event){
		$(this).find("a:eq(0)").trigger("click");
		return false;
	});
	
	/* Forms */
	
	$("input.email").click(function(){
		if (this.value=="Enter Email...") this.value="";
	});
	
	$("#emailalerts").submit(function(){
	
		if ($("#emailalerts input.email").attr("value") == '' || $("#emailalerts input.email").attr("value") == undefined) { 
			alert('Please enter you email address'); 
			return false;
		} 		
		
		if (window.RegExp)
		{
			var tempStr = "a";
			var tempReg = new RegExp(tempStr);
			if (tempReg.test(tempStr)) supported = 1;
		}
		
		var str = $("#emailalerts input.email").attr("value");

		if (!supported) 
			return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
			
		var valid = (!r1.test(str) && r2.test(str));
			
		if (valid == false)
			alert("'"+str+"'" + " is not a valid email address");
			
		return valid;
	});
	
	/* Tables */
	
	
	$("table.stripe").each(function(i){
		$(this).find("tr:even").addClass('even');
	});
	
	/* Property Finder */
	
	$("form.propertyselect select").change(function(){ 
		if (this.options[this.selectedIndex].value!="#")
			document.location = this.options[this.selectedIndex].value;
	});
});