// JavaScript Document

function toggleActive(tempid){
	$("#navigation ." + tempid + " a").addClass("active");
	$("#navigation ." + tempid + " li a").removeClass("active");
} //active menu button function

//	Smooth scrolling on internal links
$(function(){
	$('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
});

$(document).ready(function(){

	switch ($("#navigation").attr("class")) //get attr class
	{
	case "menu1":
		toggleActive("menu1");
		break;
	case "menu2":
		toggleActive("menu2");
		break;
	case "menu3":
		toggleActive("menu3");
		break;
	case "menu4":
		toggleActive("menu4");
		break;
	case "menu5":
		toggleActive("menu5");
		break;
	case "menu6":
		toggleActive("menu6");
		break;
	}
   	
	$('#navigation li ul').hide(0);
	
	$('#navigation li#comingHome').hover(
		function() { $('#navigation li#comingHome ul').show(); },
		function() { $('#navigation li#comingHome ul').hide();
	});
	
	$('#navigation li#owningTheLifestyle').hover(
		function() { $('#navigation li#owningTheLifestyle ul').show(); },
		function() { $('#navigation li#owningTheLifestyle ul').hide();
	});
	
	$('tbody tr:nth-child(odd)').addClass("odd"); // zebra table
	

	$('.inputText').css("color", "#667534");	
	$('.inputText').focus(function() {
		if (this.value == this.defaultValue){
			$('.inputText').css("color", "#333333");
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('.inputText').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			$('.inputText').css("color", "#667534");
		}
	});
	
    $('#flashBannerHolder-home').flash(
        { src: 'swf/home.swf',
          width: 909,
          height: 277,
		  wmode: 'transparent'},
        { version: 8 }
    );
	
    $('#flashBannerHolder-condo').flash(
        { src: 'swf/condo.swf',
          width: 909,
          height: 277,
		  wmode: 'transparent'},
        { version: 8 }
    );
	
    $('#flashBannerHolder-feature').flash(
        { src: 'swf/features.swf',
          width: 909,
          height: 277,
		  wmode: 'transparent'},
        { version: 8 }
    );
	
    $('#map a').lightBox();


	// newsletter function, James Alvarez
	$('button[name=newsletterSub]').click(function(){
		$('button[name=newsletterSub]').css('background-image', 'url(images/button-submit-disabled.gif)').attr('disabled',true);
		$.post('db.php?newsletter=1', $('.newsletterForm').serialize(), function(o){
			resp = o.split(':');
			alert(resp[1]);
			$('button[name=newsletterSub]').css('background-image', 'url(images/button-submit.gif)').attr('disabled',false);
			if(resp[0] == 'done')
				$('input[name=newsletterEmail]').val('Type email here');
			else
				$('input[name=newsletterEmail]').focus();
		});
		return false;
	});
	
	$('input[name=newsletterEmail]').keydown(function(o){
		if(o.which == 13)
		{
			if(!$('button[name=newsletterSub]').attr('disabled'))
				$('button[name=newsletterSub]').click();

			return false;
		}
	});
	
	$('input[name=newsletterEmail]').focus(function(){
		if($(this).val()=='Type email here')
			$(this).val('');
	});

	$('input[name=newsletterEmail]').blur(function(){
		if($(this).val()=='')
			$(this).val('Type email here');
	});
	
	//preload image
	$('<img src="images/button-submit.gif" />').appendTo('body').hide();
	$('<img src="images/button-submit-disabled.gif" />').appendTo('body').hide();
	// end newsletter function


	// contact form function, James Alvarez
	$('.contactForm[name=cnSub]').click(function(){
		$('.contactForm[name=cnSub]').html('Please wait..').attr('disabled',true);
		$.post('db.php?contact=1', $('.contactForm').serialize(), function(o){
			resp = o.split(':');
			alert(resp[2]);
			$('.contactForm[name=cnSub]').html('Submit').attr('disabled',false);
			if(resp[0] == 'done')
				$('.contactForm[name!=cnSub]').val('').html('');
			else
				$('.contactForm[name='+resp[1]+']').focus();
		});
		return false;
	});
	// end contact form function
	
});

