$(document).ready(function(){

	
	// === Apply first/last/only class to list items
    $('ul li:first-child').not(':only-child').addClass('first');
    $('ul li:last-child').not(':only-child').addClass('last');
    $('ul li:only-child').addClass('only');

	// dropdowns

	$("ul.subnav").parent().append("<span></span>");
	
	$("ul#mainmenu li a").hover(function() {
		
		$(this).siblings('span').addClass('subhover');
		$(this).parent().addClass('subhover');
		$(this).parent().find("ul.subnav").slideDown('fast').show();

	
	}).parent().hover(function() {
		// do nothing
	}, function() {
		$(this).removeClass('subhover');
		$(this).find('span').removeClass('subhover');
		$(this).parent().find("ul.subnav").slideUp('fast');
	});

	// end dropdowns	



	$("#quick-enquiry").bind("submit", function(e) {
		
		e.preventDefault();
		
		$('.error-message').remove();
		
		$.ajax({
			type: "POST",
			url: "/homes/ajax_enquiry",
			data: $("#quick-enquiry").serialize(),
			dataType: "json",
			success: function(response) {
				
				if(response.success) {
					
					$('.error-message').remove();
					
					$('.success-message').show();
					
				} else {
					
					$.each(response.errors, function(key, value){
					
						$('#Enquiry'+key).after('<div class="error-message">' + value + '</div>');
					});
				}
			},
			error: function(msg) {
				
			}			
			
		});
	
	});



});


	function launchWS(winName) { 
		//window height and width
		myHeight = screen.height*.80;
		myWidth = 784;

		//widow height bounds
		if ( myHeight < 556 ) {
			myHeight = 556;
		} else if (myHeight>700) {
			myHeight = 700;
		}
	                  
		//get screen size, and cacl center screen positioning
		var height = screen.height;
		var width = screen.width;
		var leftpos = width / 2 - myWidth / 2;
		var toppos = (height / 2 - myHeight / 2) - 40;
		
		//open window
		msgWindow=window.open(winName,"ws_window","toolbar=no,location=no,directories=no,resizable=yes,menubar=no,scrollbars=no,status=yes,width=" 
							+ myWidth + ",height="+ myHeight + ", left=" 
							+ leftpos + ",top=" + toppos); 
															
		//focus window
		setTimeout('msgWindow.focus()',1);
	}

