 var tabIndex = 0; 
 var lastTab = 0;
 
function triggerTab() {	
	setTimeout("triggerTab();", 8500); 
	lastTab = tabIndex;
	(tabIndex == 4) ? tabIndex=0 : tabIndex ++; 	
	var element = $("div.jimgMenu ul li:nth-child("+tabIndex+") a" );
	hoverIn(element);
	
	if (lastTab >= 0) {
		lastElement = $("div.jimgMenu ul li:nth-child("+lastTab+") a" );
		hoverOut(lastElement);
	}		
}

function hoverIn(element) {
    // if the element is currently being animated (to a easeOut)...
    if ($(element).is(':animated')) {
      $(element).stop().animate({width: "539px"}, {duration: 850, easing:"easeOutQuad"});
    } else {
      // ease in quickly
      $(element).stop().animate({width: "539px"}, {duration: 800, easing:"easeOutQuad"});
    }
}

function hoverOut(element) {
    if ($(element).is(':animated')) {
      $(element).stop().animate({width: "31px"}, {duration: 800, easing:"easeInOutQuad"})
    } else {
      // ease out slowly
      $(element).stop('animated:').animate({width: "31px"}, {duration: 850, easing:"easeInOutQuad"});
    }	
}

$(document).ready(function () {							
	//@ Modified 20100818 by Musaffar Patel to allow periodic automatic trigerring of the hover event.

	// find the elements to be eased and hook the hover event
	$('div.jimgMenu ul li a').hover(function() {
		hoverIn(this);
	}, function () {
		// on hovering out, ease the element out
		hoverOut(this);
	});	
	
	triggerTab();    
});
