/* 
	© fmv Group
	
*/

$(document).ready(function(){

		
	// spam protect


	var $email = $(".mail");  
	var address = $email.text()
		.replace(/\s*\publishing\s*/, '@')   
			.replace(/\s*\[dot\]\s*/g, '.');  
				$email.html('<a href="mailto:' + address + '">'  
				 + address +'</a>');  
				 
				 
	$('ul#logos li').click(function(){
			
			$('ul#logos li.current').removeClass('current').find('span').fadeOut("fast");
			
			$(this).find('span').fadeIn("normal");
			$(this).addClass("current");
			
			// ajax loading 
			
			var hash = $(this).children('a').attr("href");
		
			hash = hash.replace(/^.*#/, '');
			var page = 'ajax/'+hash;
			$.get(page,'',function(data){

				$("#desccontainer").html(data);
			
			});
			return false;
			
		});
		
	// initial load
	
	var hash = $('ul#logos li.current').children('a').attr("href");
	hash = hash.replace(/^.*#/, '');
			var page = 'ajax/'+hash;
			$.get(page,'',function(data){

				$("#desccontainer").html(data);
			
			});
	
	/* live search */
	
	$('#liveSearch').toggleVal();
			
	$('#liveSearch').bind("change keyup", function(){
					
					$("#filter_results").slideDown("fast");
					$("div#results").html('');
					$("#load").fadeIn("fast");
					
					var timer = false;
					
					if(timer) clearTimeout(timer);
					timer = setTimeout( function() { 

			        // grab the input value and store in variable
			        term = $('#liveSearch').attr('value');
					
					if(term == ""){ $("#filter_results").slideUp("fast"); }
					
					else{
					
						$.get('ajax/search.php?&query='+term,'',function(data){

							$("#load").fadeOut("fast", function(){
							
								$("div#results").html(data);
							
							});
							
						
						});
					}
					

					}, 600);
					
					$(this).bind("change keyup", function(){
							if(timer) clearTimeout(timer);
					});

					
			});    
				 
				 
		$("#search").submit(function () { return false; });
				
		$("#search").click(function(e) {
												e.stopPropagation();
		}); 

		$('#filter_results').click(function(e) {
												e.stopPropagation();
		}); 	

		
		$('body').click(function(){
			
			$("#load").hide();
			$("#filter_results").slideUp("fast");
		
		});
		
		
		
		
});


/* Delayed Mouse effect */

(function($) {
 
  $.fn.delayedMouseEnter = function(callback, options) {
 
	var options = $.extend({ delay: 200 }, options);
 
	return this.not("span").each(function() {
		var obj = $(this);
		var timer = false;
		obj.mouseenter( function(event) {
			if(timer) clearTimeout(timer);
			timer = setTimeout( function() { callback.apply(obj[0], [event]); }, options.delay );
		});		
		obj.mouseleave( function(event) {
			if(timer) clearTimeout(timer);
			timer = false;
		});		
	});
  };
 
})(jQuery);

(function($) {
 
  $.fn.delayedMouseLeave = function(callback, options) {
 
	var options = $.extend({ delay: 300 }, options);
 
	return this.not("span").each(function() {
		var obj = $(this);
		var timer = false;
		obj.mouseleave( function(event) {
			if(timer) clearTimeout(timer);
			timer = setTimeout( function() { callback.apply(obj[0], [event]); }, options.delay );
		});		
		obj.mouseenter( function(event) {
			if(timer) clearTimeout(timer);
			timer = false;
		});		
	});
  };
 
})(jQuery);
