function autoFill(id, v){
	jQuery(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
		if(jQuery(this).val()==v){
			jQuery(this).val("").css({ color: "#fff" });
		}
	}).blur(function(){
		if(jQuery(this).val()==""){
			jQuery(this).css({ color: "#b2adad" }).val(v);
		}
	});

};

function contactautoFill(id, v){
	jQuery(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
		if(jQuery(this).val()==v){
			jQuery(this).val("").css({ color: "#000" });
		}
	}).blur(function(){
		if(jQuery(this).val()==""){
			jQuery(this).css({ color: "#b2adad" }).val(v);
		}
	});

};

jQuery(document).ready(function($){




// Global Navigation
		
		$('.openup')
			.bind("click", function(){$("[childof="+$(this).parent().attr('id')+"]").slideDown();});
		
		
		$('.n-dropnext')
			.bind("mouseenter", function(){$(".navdrop[childof="+$(this).attr('id')+"]").show();})
			.bind("mouseleave", function(){$(".navdrop[childof="+$(this).attr('id')+"]").hide();});
		
		$('.navdrop')
			.bind("mouseenter", function(){$(this).show();})
			.bind("mouseleave", function(){$(this).hide();});
	
		autoFill($('#search'), "Search...");
		
		
		
		
/*
		$('#id_submit').click(function() {
			$('#id_submit').attr("value", "Sending...");
		}); 
*/

		$('#questionform').submit(function() {
			$('#id_submit').attr("value", "Sending...");
		}); 

		
		
		$('#questionform').ajaxForm(function(data) {
			if (data==1){
				$('#questionform').hide(); 
				$('#ajaxmessage').show();
			}
			else if (data==2){
				$('#id_submit').attr("value", "Try Sending Again");
				$('#email-form-message').attr("innerHTML", "<strong>There was a problem sending your message. Please try again, or phone us at (403) 265-2636.</strong>").css("background-color", "#ff5c27").css("padding", 5);
			}
			else if (data==3)
			{
				$('#id_submit').attr("value", "Send");
				$('#email-form-message').attr("innerHTML", "<strong> Sorry, but your email address appears to be invalid. Please try again:</strong>").css("background-color", "#ff5c27").css("padding", 5);
			}
		});
		
		
		/*

		var options = {
	 		success:	function() { $('#questionform').hide(); $('#ajaxmessage').show();},
	 		beforeSubmit:function() { 
	 			if ($('#contact_method').attr("value") == "Email or phone number") {
	 				$('#email-form-message').attr("innerHTML", "<strong>Please enter an email address or phone number where we can reach you:</strong>").css("background-color", "#ff5c27").css("padding", 5);
	 				return false;
	 			}
	 			$('#id_submit').attr("value", "Sending...");}
	    };	 	
	    // bind 'myForm' and provide a simple callback function 
	    $('#questionform').ajaxForm(options); 
*/
       
       contactautoFill($('#id_question'), "Ask your question here");
       contactautoFill($('#contact_method'), "Email address");
       contactautoFill($('#join_list'), "Your email address");
       
      /*  Enable AJAX for the action-bar */
      
      function showLoader(){$('#bodonav-extralinks-loader').show();} // Loaders to show when content is being loaded via ajax
      function hideLoader(){$('#bodonav-extralinks-loader').hide();}
      
      function useinActionbar() {
       // Redirect the links in the actionbar to show the result inside actionbar-contents
      	showLoader();
      	var toLoad = $(this).attr('href')+' .centercol';
      	var whichlink = $(this).attr('title'); // Need this later to see if it's the Log Out link
      	$('#bodonav-actionbar-contents').load(toLoad,'',showNewContent);
      	function showNewContent() {
      		hideLoader();
      		$('#bodonav-actionbar table.pager:first').hide();
      		$('#bodonav-actionbar').slideDown('normal', function(){
      			if(whichlink=="Log Out") { // If it was the "Log Out" link, redirect to the home page
      				window.location='/';
      			} else {
      			$('#bodonav-actionbar .pager a').click(useinActionbar); //Enable internal links again
      			
      			}
      			
      		});
      	}
      	return false; // Prevents the default behaviour of the link
      
      }
      
      $('#bodonav-extralinks a').click(useinActionbar);
      
      
      	
      	
      	
      	
      	$('#search_mini_form').submit(function(){
      		showLoader();
      		var toLoad = $(this).attr('action')+'?'+$('#search_mini_form').formSerialize()+'&mode=grid&limit=6 .centercol';
      		$('#bodonav-actionbar-contents').load(toLoad,'',showNewContent);
      		function showNewContent() {
      			hideLoader();
      			$('#bodonav-actionbar table.pager:first').hide();
      			$('#bodonav-actionbar').slideDown('normal');
      			$('#bodonav-actionbar .pager a').click(useinActionbar);
      		}
      		return false;
      	});

      
      
      $('#bodonav-actionbar-close').click(function(){$('#bodonav-actionbar').slideUp('normal');})
		
		});
		
			 
function ggslider(slidethis) {
		var $panels = slidethis.find('.gg_slider_panel').css('float', 'left');
		var $container = slidethis.find('.gg_slider_scrollContainer');
		var $scroll = slidethis.find('.gg_slider_scroll').css({
			'overflow': 'hidden',
			'width': '949px'
		});
		
		// Add next/previous buttons
		$scroll.before('<img class="gg_slider_scrollButtons g-left" src="/assets/images/gg_show-arrow-left.gif" />').before('<img class="gg_slider_scrollButtons g-right" src="/assets/images/gg_show-arrow-right.gif" />');
		
		// selectNav handles the 'selected' class addition & removal
		function selectNav() {
	    	jQuery(this)	
	    		.parents('div:first')
	    			.find('a')
	    			.removeClass('selected')
	    			.end()
	    		.end()
	    	.addClass('selected');
	    }
	    
	    function trigger(data) {
	    	//within the .navigation element, find the A element
	    	//whose href ends with ID
	    	var el = slidethis.find('.gg_slider_navigation').find('a[href$="' + data.id + '"]').get(0);
	    	
	    	// we are passing in the actual element, not the jQuery instance.
	    	
	    	selectNav.call(el);
	    }
	    
	    if (window.location.hash) {
	    	trigger({ id : window.location.hash.substr(1)});
	    	} else {
	    	slidethis.find('.gg_show_navigation a:first').click();
	    }

		$container.css('width', $panels[0].offsetWidth * $panels.length);
		
		    var scrollOptions = {
        target: $scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.gg_slider_navigation a',

        // allow the scroll effect to run both directions
        axis: 'xy',
        
        prev: 'img.gg_slider_scrollButtons.g-left',
	    next: 'img.gg_slider_scrollButtons.g-right',
	    

        // duration of the sliding effect
        duration: 500,
        onAfter: trigger,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
	        easing: 'swing'
	    };
	
	    // apply serialScroll to the slider - we chose this plugin because it 
	    // supports// the indexed next and previous scroll along with hooking 
	    // in to our navigation.
	    jQuery('#gg_slider').serialScroll(scrollOptions);
			
    	jQuery.localScroll(scrollOptions);
		scrollOptions.duration = 1;
		jQuery.localScroll.hash(scrollOptions);
	}
	
	
