// JavaScript Document

// --- Some of the extra things in here are jquery things that go on every page
// --- since the contact form is also on every page

(function($){$.fn.filestyle=function(options){var settings={width:250};if(options){$.extend(settings,options);};return this.each(function(){var self=this;var wrapper=$("<div>").css({"width":settings.imagewidth+"px","height":settings.imageheight+"px","background":"url("+settings.image+") 0 0 no-repeat","background-position":"right","display":"inline","position":"absolute","overflow":"hidden"});var filename=$('<input class="file">').addClass($(self).attr("class")).css({"display":"inline","width":settings.width+"px"});$(self).before(filename);$(self).wrap(wrapper);$(self).css({"position":"relative","height":settings.imageheight+"px","width":settings.width+"px","display":"inline","cursor":"pointer","opacity":"0.0"});if($.browser.mozilla){if(/Win/.test(navigator.platform)){$(self).css("margin-left","-142px");}else{$(self).css("margin-left","-168px");};}else{$(self).css("margin-left",settings.imagewidth-settings.width+"px");};$(self).bind("change",function(){filename.val($(self).val());});});};})(jQuery);



$(document).ready(function(){
	
		$('#footerextra').accordion({ 
		    autoheight: false,
			header: ".moreinfo" ,
			active:false,
			alwaysOpen:false
		});
	
	
	// --- Clear out the text once focus comes in the Message area
	$("#message").focus(function () {
         if($("#message").val().match(/Message./)){
			 $("#message").val("");
		 }
    });

	

	jQuery('#contact-link').click(function(){
		if(jQuery('#contact-slider').css('display') == 'none'){
			jQuery('#contact-slider').slideDown();
		} else {
			jQuery('#contact-slider').slideUp();
		}
		return false;
	});
	
	
	$("#submit").click(function(){
		
		
		//--- Validate phone number address before sending
		if($("#name").val() == ''){
			alert("Please enter your name");
			return false;
		}

		// --- Validate Email address before sending
		apos=$("#email").val().indexOf("@");
		dotpos=$("#email").val().lastIndexOf(".");
		if(apos<1||dotpos-apos<2){
			alert("Please enter a valid e-mail address");
			return false;
		}

		//--- Validate phone number address before sending
		if($("#captcha").val() != 3){
			switch($("#captcha").val()){
				case '1':
					alert("A bear? Somehow I don't believe you can type with such large paws. Please try again.");
					break;
				case '2':
					alert("Penguins are great! However, we do not accept submissions from penguins. Try again.");
					break;
				case '4':
					alert("You are the reason we created this security question. Your submission has not gone through.");
					break;
				default:
					alert("Please answer the security question");
					break;
			}
			return false;
		}
								 
		
	});
	
  
	$("input[type=file]").filestyle({ image: "/images/choosefile.png", imageheight : 25, imagewidth : 25, width : 180 });
	
	$("input.file").live('click', function() {
		$("#attachment").click();
	});
	  
	  
	$(".contactlink").click(function() {
		$("#contact-link").click();
	});
});


