// For IE6 the CSS child selector '>' will not work. Add ids and classes to elements.
jQuery(document).ready(function(){
	jQuery('.navMenuItem > ul').addClass('itemSubMenu');
	jQuery('.navMenuItem > ul > li').addClass('subMenuItem');
	jQuery('.navMenuItem > ul > li > a').addClass('subMenuItemLink');
});

// IE6 Fixes
jQuery(document).ready(function(){
	jQuery('.subMenuItem').hover(function(){
		jQuery(this).addClass('hover');
	}, function(){
		jQuery(this).removeClass('hover');
	});
});

var currentImage = 0;
var totalImage = 3;
var autoScrollDelay = 6500;
jQuery(document).ready(function(){
	setTimeout('autoScroll();', autoScrollDelay);
	
	jQuery('.navMenuItem').hover(
		function(){
			var content = jQuery(this).html();
			jQuery(this).find('.hoverBg').remove();
			//Original hoverBg #dbad31
			jQuery(this).append('<div class="hoverBg" style="background-color:#988c44;position:absolute;width:0px;height:0px;top:20px;left:75px;z-index:2;overflow:hidden;">' + content + '</div>');
			jQuery(this).find('.hoverBg').stop(false, true).animate({'top':'0px','left':'0px','width':'152px','height':'40px'},200,'linear');
		},
		function(){
			var activeMenuItem = jQuery(this);
			jQuery(this).css({ overflow: 'hidden' }).find('.hoverBg').stop(false, true).animate({'width':'152px','top':'40'},200,'linear',
													function(){
														jQuery(this).remove();
														activeMenuItem.css({ overflow: 'visible' });
													}
			);
			jQuery(this).find('a').stop(false, true).css({'line-height':'16px'});
			jQuery(this).find('a').stop(false, true).animate({'line-height':'40px'},500,'easeOutBounce');
		}
	);
});

//jQuery(document).ready(function(){
//	jQuery('.navMenuItem').has('ul').hover(function(){
//		var submenuHeight = $(this).children('ul').height();
//		$(this).children('ul').css({ height: 0, left: 0 }).stop(false, true).animate({ height: submenuHeight });
//	}, function(){
//		$(this).children('ul').stop(false, true).css({ left: '-9999px' });
//	});
//});

jQuery(document).ready(function(){
	jQuery('.navMenuItem').has('ul').hover(function(){
		jQuery(this).find('> ul').addClass('hover');
	}, function(){
		jQuery(this).find('> ul').removeClass('hover');
	});
});

function autoScroll(){
	currentImage ++;
	if(currentImage>=totalImage){
		currentImage = 0;
	}
	jQuery('.bannerPanel').animate({'left': -1*currentImage*918+'px'},800,'easeOutExpo');;
	setTimeout('autoScroll();', autoScrollDelay);
}

function showButton(button){
	button.stop().animate({'opacity':'1'},300);
	number = button.attr('id').replace('button','')-1;
	jQuery('div.scrollWrapper').stop().animate({'left': -1*number*960+'px'},800,'easeOutExpo',function(){
	});
	jQuery('div.secondMenu').children('div:not(#' + button.attr('id') + ')').stop().animate({'opacity':'0'},300);
}

jQuery(document).ready(function(){
	jQuery('.sponsors').cycle('fade');
});

// Menu expand/collapse function
//jQuery(document).ready(function(){
//	jQuery('.menuArrow').click(function(){
//		var mainMenuHeight = jQuery('.mainMenu').height();
//		if(mainMenuHeight<200){
//			jQuery('.mainMenu').stop().animate({
//				height: '225px'
//			}, 'easeInQuad');
//		} else {
//			jQuery('.mainMenu').stop().animate({
//				height: '55px'
//			}, 'easeInQuad')
//		}
//	});
//});

// Cufon font replacement
Cufon.replace('.content h1');
