$(document).ready(function(){      
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	// Side Contact Form
	/////////////////////////////////////////////////////////////////////////////////////////////////	
	
	 $(".sideSubmit").click(function() {
		var emailAddress = $('#emailAddress').val();
		var dataString = $("form").serialize();
			if(emailAddress.length>0)
				{
					//alert(dataString);
					$.ajax({
					type: "POST",
					url: "inc/sideContactFormProcess.php",
					data: dataString,
					cache: false,
					success: function(html)
						{							
							//$("#pwd_"+ID).html('<span style="color:blue">password changed!</span>');
							$("#cForm").fadeOut();
							$("#cFormMessage").fadeIn();							
						}
				});
			}
			else
				{
					alert('You Must Enter a Valid Email Address!');
					//$(".editbox").hide();						
					//$("#cFormError").show();	
					//$("#pwd_"+ID).html('<span style="color:red">password not changed!</span>');				
				}
		});
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	// Dropdown Menu
	/////////////////////////////////////////////////////////////////////////////////////////////////		
	
	$(function(){
	
		var config = {    
			 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 2000,  // number = milliseconds for onMouseOver polling interval    
			 over: doOpen,   // function = onMouseOver callback (REQUIRED)    
			 timeout: 2000,   // number = milliseconds delay before onMouseOut    
			 out: doClose    // function = onMouseOut callback (REQUIRED)    
		};
		
		function doOpen() {
			$(this).addClass("hover");
			$('ul:first',this).css('visibility', 'visible');
		}
	 
		function doClose() {
			$(this).removeClass("hover");
			$('ul:first',this).css('visibility', 'hidden');
		}
	
		$("ul.dropdown li").hoverIntent(config);
		
		$("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
	
	});		
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	// Modal
	/////////////////////////////////////////////////////////////////////////////////////////////////	
	
	$('a.modalMe').click(function() {

		// Display an external page using an iframe
		var src = $(this).attr("href");
		//alert(src);
		$.modal('<iframe src="' + src + '" height="400" width="920" style="border:0">', {
			closeHTML:"",
			overlayClose:true
		});	
		return false;
	});
	
	
 	$("#instantQuote").change(funcOnDropdownChange);
	
		function funcOnDropdownChange () {

			 var selectedVal	= $('#instantQuote option:selected').val();
			 var urlDestination	= pageLookup(selectedVal);			 
			 
			 if (urlDestination) {
				 loadModal(urlDestination);
			 }
		}
		
		function pageLookup(dropdownVal){	
			if(dropdownVal=="Auto") {
				urlAddress = 'https://modern.ibqagents.com/auto/';   
				return urlAddress;				
				}            
			else if(dropdownVal=="Home") {
				urlAddress = 'https://modern.ibqagents.com/ho3';
				return urlAddress;				
				}
			else if(dropdownVal=="Condo") {
				urlAddress = 'https://modern.ibqagents.com/ho6';
				return urlAddress;				
				}
			else if(dropdownVal=="Renter") {
				urlAddress = 'https://modern.ibqagents.com/ho4';
				return urlAddress;
				}
			else {return false;}
		}
		
		function loadModal(pageToLoad){
			$.modal('<iframe src="' + pageToLoad + '" height="400" width="920" style="border:0">', {
				closeHTML:"",
				overlayClose:true
			});	
			return false;
		}
});
