(function($){ 

    $.fn.extend({
		
		megaMenu: function() {
			
			mainCont = this.parent();
			
			totalWidth = (mainCont.children('.super-menu-child').children('.super-menu-child-column').length) * 195;
			
			mainCont.children('.super-menu-child').children('.super-menu-child-column:last').addClass('last');
			
			mainCont.children('.super-menu-child').css({ width: totalWidth+'px' });
			
			mainCont.hoverIntent(function() {
				
				mainCont.addClass('hovered');
				mainCont.children('.super-menu-child').stop(false, true).slideDown(400);	
				
			}, function() {
				
				mainCont.children('.super-menu-child').stop(false, true).slideUp(400, function() {
					
					mainCont.removeClass('hovered');
					
				});	
				
			});
			
		},
		
		tabbedContent: function() {
			
			//define vars
			var myTabs = this.children('ul:first');
			var myContent = this.children('ul:last');
			
			//let's create a number to be increased
			var i = 1;
			
			//Let's add classes to differ each one of them
			myTabs.children('li').each(function() {
				
				jQuery(this).addClass('tab_'+i);
				
				i++;
				
			});
			
			//let's create a number to be increased
			var x = 1;
			
			//Let's add classes to differ each one of them
			myContent.children('li').each(function() {
				
				jQuery(this).addClass('tab_'+x);
				
				x++;
				
			});
			
			//Let's add the current class to the firsts items
			myTabs.children('li:first').addClass('current');
			myContent.children('li:first').addClass('current');
			
			playingTab = 0;
			
			//Let's change tabs when click a button
			myTabs.children('li').click(function() {
					
			var myTabClass = jQuery(this).attr('class').split(' ');
			
			if(myTabClass[1] != 'current') {
				
				if(playingTab == 0) {
					
					playingTab = 1;
					
					var myTabId = myTabClass[0].split('_');
					
					myTabs.children('li.current').removeClass('current');
					jQuery(this).addClass('current');
					
					myContent.children('li.current').removeClass('current').addClass('playing').animate({ opacity: 0 }, 300, function() {
						
						jQuery(this).hide();
						
						myContent.children('li.tab_'+myTabId[1]).css({ display: 'block', opacity: 0 }).animate({ opacity: 1 }, 400, function() {
							
							jQuery(this).addClass('current');
							playingTab = 0;
							
						});
						
					});
					
				}
				
			}
				
			});
			
		}
		
	});
	
})(jQuery);

function dropDown() {
	
	jQuery('#main-menu ul li').children('ul').each(function() {
		
		jQuery(this).children('li:last-child').children('a').css({ border: 'none' });
		
	});
	
	jQuery("#main-menu ul li").hoverIntent(function() {
		jQuery(this).find('ul:first').stop(true, true).slideDown(400) //Slides down when hover the UL
		jQuery(this).addClass("hovered"); //Adds a hovered class, so you can see the menu path you are following
	}, function() {
		jQuery(this).find('ul:first').stop(true, true).slideUp(300); //Slides up on mouseleave
		jQuery(this).removeClass("hovered"); //removes the hovered class.
	});
	
}

function showHiddenSearch() {
	
	jQuery('#hidden-search > img').click(function() {
		
		if(jQuery('#hidden-search > form > p').css('display') == 'none') {
		
			jQuery('#hidden-search > form > p').stop(true, true).fadeIn(300);
			
		} else {
			
			jQuery('#hidden-search > form > p').stop(true, true).fadeOut(300);
			
		}
		
	});
	
}

function CommentForm() {
	if(jQuery('#hidden-form').css('display') == 'none') {
		jQuery('#hidden-form').stop(true, true).fadeIn(300);
	} else {
		jQuery('#hidden-form').stop(true, true).fadeOut(300);
	}
}

function handleEnter(field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} else
		return true;
}

function manageHeight(i,j) {
	var t1 = jQuery('#tobechecked'+i);
	var t2 = jQuery('#tobechecked'+j);
	if ( t1.height()>t2.height())
		t2.height(t1.height());
	else if ( typeof t2.height() != 'undefined')
		t1.height(t2.height());
}

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

