
$(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");
		});
		
    }
	
	/* Page tools */
	
	$("#email").click(function(){
		location.href='mailto:?SUBJECT=Link to Website of Basin Street Properties - (http://www.basin-street.com)&BODY=Below is a link to a page from the Basin Street Properties 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%0AABOUT BASIN STREET PROPERTIES. -  http://www.basin-street.com%0D%0ABasin Street Properties is a real estate investment firm that has built a renowned track record of successfully developing, acquiring and managing residential, office, retail and hospitality properties throughout the Western United States.';
		return false;
	});
	$("#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;
	});
	$("#print").click(function(){
		print();
		return false;
	});	

	/* Prepare external links */
	
	$("a").each(function(i){
		if($(this).attr("rel")=="external")
			$(this).attr("target","_blank");

	});
	
	
	/* 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 Your Email") this.value="";
	});
	
	$("#emailalerts").submit(function(){
	
		if ($("#emailalerts input.email").attr("value") == '') { 
			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(){ 
		document.location = this.options[this.selectedIndex].value;
	});
});