$(document).ready(function(){
	
	//secretAgent by KneeDeepInCode.com (http://kneedeepincode.com/topics/secretagent/)
	$(function(){var debug = false; var ua=navigator.userAgent.toLowerCase();var myBrowsers={mozilla:$.browser.mozilla,safari:$.browser.safari,opera:$.browser.opera,ie:$.browser.msie,ie6:$.browser.msie&&($.browser.version<7),ie7:$.browser.msie&&($.browser.version==7),ie8:$.browser.msie&&($.browser.version>7),iphone:/iphone/.test(ua),chrome:/chrome/.test(ua),firefox:/firefox/.test(ua),webkit:/webkit/.test(ua),osx:/mac os x/.test(ua),win:/win/.test(ua),linux:/linux/.test(ua)};if(debug){i=1;}$.each(myBrowsers,function(a,b){if(b)$('html').addClass(a);if(b&&debug){if(i==1){x='Browser: '}else if(i==2){x='Browser Version: '}else{x='OS: '}alert(x+a);i++;}});});
	
	
	//This will get the height and width of the random image on the home page
	var width = $('#fncy img').width();
	var height = $('#fncy img').height();
	
	//This will check if it is a landscape or portrait photo and swap the divs background accordingly.
	if(width > height) {
		$('#fncy').removeClass().addClass('fancy_corners_hori');
		$('#mail_signup').removeClass().addClass('long');
	}
	else {
		$('#fncy').removeClass().addClass('fancy_corners_vert');
		$('#mail_signup').removeClass().addClass('short');
	}
	
	//For the input type="text" in the mail sign up form.
	$('#mail_signup form input[type$="text"]').css({width:"99%",border:'1px solid #3a0803',marginBottom:'6px'});
	
	 //Populates the text fields with the populate class.
	  $('.populate').each(function(){
	    $(this).val( $(this).attr('title') ).focus(function(){
	      $(this).val('');
	    });
	  });

	//$('#carousel').jcarousel();
	
	
	 $('#carousel').jcarousel({
        scroll: 4
    });

	
	//Left menu on sub pages. Creates the little sliding animation
   //	$('#sub_left ul.sub_nav_inventory li ul').css({display:'none'});
	
	//Appending the down arrow state so that there is no flicker when the user clicks on an option for the first time
	$('body').append('<div class="preloader"><img src="images/background/sub_nav_arrows2.png" alt="preloaded image" /></div>');
	$('.preloader').css({display:'none'});

	//Actual animation in a toggle.
	$('#sub_left ul.sub_nav_inventory li a.toggleOff').toggle(
		function(){
		    if($(this).hasClass('toggleOff'))
            $(this).removeClass('toggleOff').addClass('toggleOn');
            else
            $(this).removeClass('toggleOn').addClass('toggleOff');

			$(this).next('ul').slideToggle(1000);
		},
		function(){
            if($(this).hasClass('toggleOff'))
            $(this).removeClass('toggleOff').addClass('toggleOn');
            else
            $(this).removeClass('toggleOn').addClass('toggleOff');

			$(this).next('ul').slideToggle(1000);
		}
	);
    $('#sub_left ul.sub_nav_inventory li a.toggleOn').toggle(
		function(){
            if($(this).hasClass('toggleOff'))
            $(this).removeClass('toggleOff').addClass('toggleOn');
            else
            $(this).removeClass('toggleOn').addClass('toggleOff');
            
			$(this).next('ul').slideToggle(1000);
		},
		function(){
            if($(this).hasClass('toggleOff'))
            $(this).removeClass('toggleOff').addClass('toggleOn');
            else
            $(this).removeClass('toggleOn').addClass('toggleOff');

			$(this).next('ul').slideToggle(1000);
		}
	);

var options = {
    target:     '#contactResponse',
    url:        'includes/ajax/send_mail.php',
    beforeSubmit: validate,
    success:    function() {
        $('#contactResponse').fadeIn('slow');
        }
};
$('#contactForm').ajaxForm(options);

//load();

});


   function validate(formData, jqForm, options) {
    // formData is an array of objects representing the name and value of each field
    // that will be sent to the server;  it takes the following form:
    //
    // [
    //     { name:  username, value: valueOfUsernameInput },
    //     { name:  password, value: valueOfPasswordInput }
    // ]
    //
    // To validate, we can examine the contents of this array to see if the
    // username and password fields have values.  If either value evaluates
    // to false then we return false from this method.

    for (var i=0; i < formData.length; i++) {
        if (!formData[i].value) {
            alert('Please enter a value for required fields');
            return false;
        }
    }
  //  alert('All fields contain values.');
}

function reloadImage() {
//  alert('in reload image');
     $.ajax({
   type: "POST",
   url: "includes/ajax/security_image_code_ajax.php",
   success: function(html){
//	alert(html);
   $('#sec_image').fadeOut('fast');
   $('#sec_image').empty();
   $('#sec_image').append(html);
   $('#sec_image').fadeIn('fast');
   }
 });
}
   /*
    //<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
      }
    }
    //]]>
    */