// BACKGROUND
(function($) {

    $.backstretch = function(src, options, callback) {
        var settings = {
            centeredX: false,         // Should we center the image on the X axis?
            centeredY: false,         // Should we center the image on the Y axis?
            speed: 300                // fadeIn speed for background after image loads (e.g. "fast" or 500)
        },
        rootElement = ("onorientationchange" in window) ? $(document) : $(window), // hack to acccount for iOS position:fixed shortcomings
        imgRatio, bgImg, bgWidth, bgHeight, bgOffset, bgCSS;
        
        // Extend the settings with those the user has provided
        if(options && typeof options == "object") $.extend(settings, options);
    
        // Initialize
        $(document).ready(_init);
  
        // For chaining
        return this;
    
        function _init() {
            // Prepend image, wrapped in a DIV, with some positioning and zIndex voodoo
            if(src) {
                var container = $("<div />").attr("id", "backstretch")
                                            .css({left: 0, top: 0, position: "fixed", overflow: "hidden", zIndex: -9999}),
                    img = $("<img />").css({position: "relative", display: "none"})
                                      .bind("load", function(e) {                                          
                                          var self = $(this);
                                          imgRatio = $(e.target).width() / $(e.target).height();
    
                                          _adjustBG(function() {
                                              self.fadeIn(settings.speed, function(){
                                                  if(typeof callback == "function") callback();
                                              });
                                          });
                                      })
                                      .appendTo(container);
                  
                $("body").prepend(container);
                img.attr("src", src); // Hack for IE img onload event

                // Adjust the background size when the window is resized or orientation has changed (iOS)
                $(window).resize(_adjustBG);
            }
        }
            
        function _adjustBG(fn) {
            try {
                bgCSS = {left: 0, top: 0}
                bgWidth = rootElement.width();
                bgHeight = bgWidth / imgRatio;

                // Make adjustments based on image ratio
                // Note: Offset code provided by Peter Baker (http://ptrbkr.com/). Thanks, Peter!
                if(bgHeight >= rootElement.height()) {
                    bgOffset = (bgHeight - rootElement.height()) /2;
                    if(settings.centeredY) $.extend(bgCSS, {top: "-" + bgOffset + "px"});
                } else {
                    bgHeight = rootElement.height();
                    bgWidth = bgHeight * imgRatio;
                    bgOffset = (bgWidth - rootElement.width()) / 2;
                    if(settings.centeredX) $.extend(bgCSS, {left: "-" + bgOffset + "px"});
                }

                $("#backstretch img").width( bgWidth ).height( bgHeight ).css(bgCSS);
            } catch(err) {
                // IE7 seems to trigger _adjustBG before the image is loaded.
                // This try/catch block is a hack to let it fail gracefully.
            }
      
            // Executed the passed in function, if necessary
            if (typeof fn == "function") fn();
        }
    };
  
})(jQuery);

// LOGIN FORM
function validate_login_form() {
	var valid = true;
	if($("#username").val()==''){
		alert("Please enter a Username");
		valid = false;
	}else if($("#password").val()==''){
		alert("Please enter a Password");
		valid = false;
	}
	
	return valid;
	
}
$(document).ready(function() {
	// make the log-in button work
	$('#submit-form')
		.button()
		.click(function() {
	});
	
	$('#password').focus(function(){$('#password').removeClass('bg_text_on').addClass('bg_text_off');});
	$('#password').blur(function(){if($('#password').val()==''){$('#password').removeClass('bg_text_off').addClass('bg_text_on');}});
	$('#username').focus(function(){$('#username').removeClass('bg_text_on').addClass('bg_text_off');});
	$('#username').blur(function(){if($('#username').val()==''){$('#username').removeClass('bg_text_off').addClass('bg_text_on');}});
	
$("#loginButton").click(function(){
		if($("#loginBar").hasClass('show')){
			$("#loginBar").removeClass('show');
			$("#loginBar_skin").fadeOut(200, function(){$("#loginBar").slideUp(); });
		}else{
			$("#loginBar").addClass('show');
			$("#loginBar").slideDown(400, function(){$("#loginBar_skin").fadeIn(200);});
														
		}
	});

});

// FORM FIELD FUNCTIONS
function getCheckedValue(radioObj) {
			if(!radioObj){return "";}
			var radioLength = radioObj.length;
			if(radioLength == undefined){
				if(radioObj.checked){return radioObj.value;}else{return "";}
			}
			for(var i = 0; i < radioLength; i++) {
				if(radioObj[i].checked) {return radioObj[i].value;}
			}
			return "";
		}

$(function(){
	
		   $('#globalMenu li a').append('<span class="hover"></span>');
		   $('#globalMenu li span.hover').css("opacity", "0");
		   
$('#globalMenu li a').hover(
	function() {
		// Stuff that happens when you hover on + the stop()
		$('.hover', this).stop().animate({
			'opacity': 1
			}, 600, 'easeOutExpo')
	},function() {
		// Stuff that happens when you unhover + the stop()
		$('.hover', this).stop().animate({
			'opacity': 0
			}, 600, 'easeOutExpo')
	})
		   
		  
		    $('.search_box').focus(function(){$(this).removeClass('bg_text_on').addClass('bg_text_off');});
	$('.search_box').blur(function(){if($(this).val()==''){$(this).removeClass('bg_text_off').addClass('bg_text_on');}});
		   
		   $('.button').button();
								 $.backstretch("http://www.shenington-gliding.co.uk/images/background.jpg");
								 });

$(document).ready(function(){  
	$(".CheckBoxClass").change(function(){  
		if($(this).is(":checked")){  
			$(this).next("label").addClass("LabelSelected");  
		}else{  
			$(this).next("label").removeClass("LabelSelected");  
		}  
	});  
});	

