// jQuery 1.6.1

function mo_search() {
		
		var searchWebsite = '';	
		var tag_list      = $('#search-tags').val();
		var availableTags = tag_list.split(' @');
		
		function split(val) { return val.split( /,\s*/ ); }
		
		function extractLast(term) { return split(term).pop(); }

		$("#search-q").bind("keydown", function(event) {
				if(event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) 
				  event.preventDefault();
		}).autocomplete({
				minLength: 2,
				source: function(request, response) { 
				  response($.ui.autocomplete.filter(availableTags, extractLast(request.term))); },
				focus: function() { return false; },
				select: function( event, ui ) {
						var terms = split(this.value);
						terms.pop(); terms.push('"'+ui.item.value+'"'); terms.push("");
						this.value = terms.join(", ");
						return false;
				},
				appendTo: "#suggested-tags"
		});	
		
		$('#search-q').focus(function() {
				if($(this).val() == $(this).attr('title')) {
						$('#search-form').animate({top: '0px'}, 200);
						searchWebsite = $(this).val();
						$(this).val('');
						$('#search-enter').slideDown(200);
						mo_search_q();
				}
		});
		
		$('#search-q').keydown(function(e) {	mo_search_q(); });
		
		$('#search-enter').click(function() { $('#search-form').submit(); });
		
		$('#search-q').blur(function() {
				if($(this).val() == '')	{
						$('#search-form').animate({top: '17px'}, 200);
				  $(this).val(searchWebsite);
						$('#search-enter').slideUp(200);
				};
		});
		
		function mo_search_q() {
				if($('#search-q').val().length >= 1 || $('#search-q').val() != '') 
				  $('#search-send').html('Press enter to search or click here');
				else 
      $('#search-send').html('Start typing to see suggested keywords');
		};
};

function mo_navigation() {
	
	 $('#navigation-menu ul li:first')
		  //.addClass('nav-home').next()
				.addClass('nav-basketball').next()
				.addClass('nav-volleyball').next()
				.addClass('nav-mma').next()
				.addClass('nav-gear').next()
				.addClass('nav-catalog').next()
				.addClass('nav-about').next()
				.addClass('nav-contact');
	
	 $('#footer-menu ul li:first')
				.addClass('footer-basketball').next()
				.addClass('footer-volleyball').next()
		  .addClass('footer-home').next()
				.addClass('footer-gear').next()
				.hide().next()
				.hide().next()
				.hide();
				
		$('.footer-home').hover(function() {
			 $(this).find('a:first').addClass('footer-home-hover');
		}, function() {
			 $(this).find('a:first').removeClass('footer-home-hover');
		});
				
		$('.footer-basketball').hover(function() {
			 $(this).find('a:first').addClass('footer-basketball-hover');
		}, function() {
			 $(this).find('a:first').removeClass('footer-basketball-hover');
		});
				
		$('.footer-volleyball').hover(function() {
			 $(this).find('a:first').addClass('footer-volleyball-hover');
		}, function() {
			 $(this).find('a:first').removeClass('footer-volleyball-hover');
		});
				
		$('.footer-gear').hover(function() {
			 $(this).find('a:first').addClass('footer-gear-hover');
		}, function() {
			 $(this).find('a:first').removeClass('footer-gear-hover');
		});
		
		$('#footer-contact').hover(function() {
  		$('#contactus-title').addClass('footer-contact-hover');
		}, function() {
  		$('#contactus-title').removeClass('footer-contact-hover');
		});
		
		$('#footer-contact span').click(function() { window.location = '/contact'; });
				
		$('#footer-menu ul').css({'height':$('#footer-navigation').height()+'px'});
		$('#footer-contact ul').css({'height':$('#footer-navigation').height()+'px'});
	
		function mouse_over() { $(this).find('ul:first').slideDown(300); };
		function mouse_leave() { $(this).find('ul:first').slideUp(300); };
		
		$('#navigation-menu ul li').hoverIntent({ sensitivity: 3, interval: 50, over: mouse_over, timeout: 50, out: mouse_leave });
	 
	 $('#icon').click(function() { window.location = '/'; });
	 
};

function mo_contact() {
	
	 $('#iframe').attr("onload", "mo_map()");
	 
		$('#contact-email').keyup(function () { 
		 	if(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/g.test($('#contact-email').val())) {
						$('#contact-submit').html('Send');
						$('.invalid').hide();
				};
  });
		
		$('#contact-submit').click(function() {
				if(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/g.test($('#contact-email').val()) 
				  && $('#contact-email').val() != '') {
						$('#contact-submit').html('Sending');
						setTimeout(function() { $('#contact-form').submit(); }, 100);
				} else { 
						$('#contact-submit').html('Error!');
						$('.invalid').show();
						$('#contact-email').focus();
				};
		});
		
		$('#contact-reset').click(function() {
  	  $('#contact-name'   ).val('');
  	  $('#contact-team'   ).val('');
  	  $('#contact-email'  ).val('');
  	  $('#contact-phone'  ).val('');
  	  $('#contact-message').html('');
					$('#contact-submit' ).html('Send');
					$('.invalid').hide();
		});
	
	 $('.input').focus(function() { $(this).css({'color' : '#000', 'background-color' : '#bbb', 'border' : '1px solid #888'}); });
	 $('.input').blur( function() { $(this).css({'color' : '#111', 'background-color' : '#ccc', 'border' : '1px solid #999'}); });
		
		$('.email-sales').click(function() { window.location.href = "mailto:sales@morenogear.com"; });
		$('.email-brian').click(function() { window.location.href = "mailto:brian@morenogear.com"; });
		$('.email-eric' ).click(function() {	window.location.href = "mailto:eric@morenogear.com";  });
		
};

function mo_loadImg($page) {
	 if($page == 0) {
    $('#image-loading').hide();
		} else {
     //$(this).parent().css({'background-color':'#e3e3e3'});
    
		};
};

function loadimg($catcher) {
	 $('#'+$catcher).css({'background-image':'none'});
};

function mo_map() {
  $('#iframe').css({'visibility':'visible'});
		$('#contact-map').css({'background-image':'none'});
};

function mo_products() {
		
	 $('.available-colours').find('a:first').css(
		  {'background-color':'#eee', 'border':'1px solid #aaa'});
	
		$('.colour-option').click(function() {
			 if($(this).attr('title') != $('.product-photo').attr('name')) {
						$('.colour-option').css(
						  {'background-color':'#e3e3e3', 'border':'1px solid #d0d0d0'});
						$(this).css({'background-color':'#eee', 'border':'1px solid #aaa'});
						$('#image-loading').show();
						$photo_url = '/wp-content/themes/moreno/scripts/img.php?src=/products/'+
						  $(this).attr('name')+'-'+$(this).attr('title')+'.png&w=400&h=500&f=png';
						$('.product-photo').attr('src', $photo_url);
						$('.product-photo').attr('name', $(this).attr('title'));
				}
		});
		
		if($('#product-info').height() > $('.product-photo').height()) {
			 $('.image-container').css({'height':$('#product-info').height()+'px'});
		};
		
		$container_height = $('.image-container').height()/2;
		$loader_top        = $container_height - ($('#image-loading').height() / 2);
		
		$('#image-loading').css({'top':$loader_top+'px'});
	 
		$('#image-loading').show();
		$('.image-loader').show();
		
};

$(document).ready(function() { 
  mo_navigation();
  mo_search();
		mo_contact();
		mo_products();
		
});

<!-- Google Analytics -->
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		try {
				var pageTracker = _gat._getTracker("UA-12414395-1");
				pageTracker._trackPageview();
		} catch(err) {}
<!-- End Google Analytics -->

