$(document).ready(function(){
	
	$('.gal').cycle();
	$('.trigger').click(function(){
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			$('.topper').appendTo($('#topper'));
			$('.topper').show();
			$('.trigger').hide(); // <- HERE
		}
		else {
		$('.topper').appendTo($('#topper'));
		$('.topper').slideToggle();
		$('#header-inner').addClass('clear');
		$('.trigger').text($(this).text() == 'CLICK HERE' ? 'HIDE' : 'CLICK HERE'); // <- HERE
    	return false;
    	}
	});
	// Footer Animation
	var slide = false;
	var height = $('#footer-more').height();
	
	$('.foot-trigger').click(function() {
	
		var docHeight = $(document).height();
		var windowHeight = $(window).height();
		var scrollPos = docHeight - windowHeight + height;
		$('#footer-more').animate({ height: "toggle"}, 200);
		if(slide == false) {
			if($.browser.opera) { //Fix opera double scroll bug by targeting only HTML.
				$('html').animate({scrollTop: scrollPos+'px'}, 200);
			} else {
				$('html, body').animate({scrollTop: scrollPos+'px'}, 200);
			}
			slide = true;
		} 
		
		else {
			slide = false;
		}
	
	});
	
	$(".topper-col a").prepend("<span></span>");
	
	$(".topper-col a span").css({opacity : 0});
	
	$(".topper-col a[class!=cur]").hover(
		function(){
			$(this).animate({opacity:1,"padding-left":"8px"},{duration:200,queue:false}).addClass("cur");
			$(">span",this).animate({opacity:1,"margin-left":"-3px"},{duration:200,queue:false});
		},
		function(){
			$(this).animate({opacity:1,"padding-left":"0px"},{duration:200,queue:false}).removeClass("cur");
			$(">span",this).animate({opacity:0,"margin-left":"0px"},{duration:200,queue:false});
		}
	);
	
	$(function() {
		swapValues = [];
			$("input.box").each(function(i){
				swapValues[i] = $(this).val();
				$(this).focus(function(){
					if ($(this).val() == swapValues[i]) {
						$(this).val("");
					}
				}).blur(function(){
					if ($.trim($(this).val()) == "") {
						$(this).val(swapValues[i]);
				}
			});
		});
	});
	
	
	
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
	
	$("#submit_btn").click(function(){
	
		//Check First Name	
		var id_firstname=$("input#id_firstname").val();
		if(id_firstname==""){		
			$("#id_firstname").css({ backgroundColor : "#ff5656"});			
			$("#id_firstname").click( function(){
				$(this).css({ backgroundColor : "#FFF"});
			});
				
			return false;
		}
		
		//Check Last Name	
		var id_lastname=$("#id_lastname").val();		
		if(id_lastname==""){		
			$("#id_lastname").css({ backgroundColor : "#ff5656"});			
			$("#id_lastname").click( function(){
				$(this).css({ backgroundColor : "#FFF"});
			});
				
			return false;
		}
	
		//Check Email
		var id_email=$("#id_email").val();
		if(id_email != 0){
			if(isValidEmailAddress(id_email)){
				
			} 
			else {
				
				$("#id_email").css({ backgroundColor : "#ff5656"});			
				$("#id_email").click( function(){
					$(this).css({ backgroundColor : "#FFF"});
				});
					
				return false;
			}
		}		
		else {
			$("#id_email").css({ backgroundColor : "#ff5656"});			
			$("#id_email").click( function(){
				$(this).css({ backgroundColor : "#FFF"});
			});
				
			return false; 
		}
		
		//Check Phone Number	
		var id_phone_2=$("input#id_phone_2").val();
		if(id_phone_2==""){		
			$("#id_phone_2").css({ backgroundColor : "#ff5656"});			
			$("#id_phone_2,").click( function(){
				$(this).css({ backgroundColor : "#FFF"});
			});
				
			return false; 
		}
		
		var id_zip_code=$("#id_zip_code").val();
		
		if(id_zip_code.length != 5){
				
			$("#id_zip_code").css({ backgroundColor : "#ff5656"});			
			$("#id_zip_code").click( function(){
				$(this).css({ backgroundColor : "#FFF"});
			});
				
			return false; 
		}
	


	});
	


});

