// JavaScript Document
// jQuery

jQuery.noConflict();
//var jQuery = jQuery.noConflict();
jQuery(document).ready(function(){
	var windowShadeHeight = jQuery('#windowShade').height();
	var windowShadeUp = 0 - (windowShadeHeight-44);
	jQuery('#windowShade').css( {'top' : windowShadeUp  } );
	//jQuery('#windowShade #windowShadeTab').css('display','auto');
	
	sentUp = true;
	jQuery('#windowShade #windowShadeTab').toggle(
		function () { 
				if( sentUp == false ){
					jQuery('#windowShade').animate({ 
						top: windowShadeUp
					}, 500 );
					
					jQuery('#windowShade #windowShadeTab').css('background-position','0 0');
					
					sentUp = true;
				
				}else{
					jQuery('#windowShade').animate({ 
						top: "0"
					}, 500 ); 
					
					jQuery('#windowShade #windowShadeTab').css('background-position','0 -44px');
					
					sentUp = false;
				
				}
			
			} ,
			
		function () {
				
				if( sentUp == false ){
				
					jQuery('#windowShade').animate({ 
						top: windowShadeUp
					}, 500 );
					
					jQuery('#windowShade #windowShadeTab').css('background-position','0 0');
					
					sentUp = true;
				
				}else{
					jQuery('#windowShade').animate({ 
						top: "0"
					}, 500 ); 
					
					jQuery('#windowShade #windowShadeTab').css('background-position','0 -44px');
					
					sentUp = false;
				
				}
			
			}	
	);
	
	jQuery('#windowShade #close').hover(
		function(){
			jQuery('#windowShade #close').css('background-position','0 bottom');
		},
		function(){
			jQuery('#windowShade #close').css('background-position','0 top');
		}
	);
	
	
	jQuery('#windowShade #close').click(
		function(){ 
			jQuery('#windowShade').animate({ 
				top: windowShadeUp
			}, 500 );
			
			jQuery('#windowShade #windowShadeTab').css('background-position','0 0');
			
			sentUp = true;
			
		}
	);
	
	
	jQuery('#windowShade #submit').click(
		function(){
			
			// Get values
			var fname = jQuery("#simpleContact input#fname").val();
			var lname = jQuery("#simpleContact input#lname").val();
			var phone = jQuery("#simpleContact input#phone").val();
			var email = jQuery("#simpleContact input#email").val();
			var comments = jQuery("#simpleContact input#comments").val();
			var interests = jQuery("#simpleContact select#interests").val();
			var dest = jQuery("#simpleContact input#dest").val();
			var key = jQuery("#simpleContact input#key").val();
			var returnpage = jQuery("#simpleContact input#returnpage").val();
			// Validate that sometyhing is being sent
			var valid = true;
			var errorMessages = new Array();
			jQuery('#contact_form #errorMessages').html("");
			if( fname=='' ){
				errorMessages.push("Please provide your first name.");
				valid = false;
			}
			if( lname=='' ){
				errorMessages.push("Please provide your last name.");
				valid = false;
			}
			
			if( phone=='' && email=='' ){
				errorMessages.push("Please provide a phone number or email address so that we may contact you.");
				valid = false;
			}
						
			if( interests=='' ){
				errorMessages.push("Please tell us what you would like us to contact you about.");
				valid = false;
			}
			
			if( fname.indexOf('http://')>-1 || lname.indexOf('http://')>-1 || phone.indexOf('http://')>-1 || email.indexOf('http://')>-1 || comments.indexOf('http://')>-1 ){
				errorMessages.push("Please, do not include links in this correspondence.");
				valid = false;
			}
			
			if( valid ){
//				var dataString = 'fname='+fname+'&lname='+lname+'&phone='+phone+'&email='+email+'&comments='+comments+'&interests='+interests+'&dest='+dest+'&key='+key+'&returnpage='+returnpage;
//				alert(dataString);
//				jQuery.ajax({
//					type: "POST",
//					url: "connectsubmit.php",
//					data: dataString,
					
//					success: function() {
//						jQuery('#contact_form').html("<div id='message'></div>");
//						jQuery('#message').html("<h2>Contact Form Submitted!</h2>")
//						.append("<p>We will be in touch soon.</p>")
//						.hide()
//						.fadeIn(1500);
//					},
					
//					error: function(){
//						jQuery('#contact_form #errorMessages').append("<p>We sincerely apologize, but it appears that something is wrong with our form. This error has automatically been reported to our site technicians. Please consider using our other contact forms located <a href=\"/contact\">here</a>.</p>");
//					}
				
//				});
			}else{
				jQuery('#contact_form #errorMessages').append("<h2>Information is missing</h2><ul>");
				for(i=0; i<errorMessages.length; i++){
					jQuery('#contact_form #errorMessages').append("<li>"+errorMessages[i]+"</li>");
				}
				jQuery('#contact_form #errorMessages').append("</ul>");
				jQuery('#contact_form #errorMessages').fadeIn(500).fadeTo(4000,1).fadeOut(500);
				return false;
			}
		}
	);
		
});