// JavaScript Document
$(function(){
	$("#menu li").hover(
		function(){
			$(this).find(".submenu").show();
		},
		function(){
			$(this).find(".submenu").hide();	
		}
	);
	
	$("#events li:not(:last)").clone().insertBefore($("#events li:last"));
	setInterval(function(){$("#events li:first").insertBefore( $("#events li:last") );}, 20000);
	$("div.imgs li:not(:first)").animate({opacity:0},1);
	$("div.nav-button li span").click(function(){
		var index = $("div.nav-button li span").index(this);
		$("div.nav-button li").removeClass("current");
		$(this).parent().addClass("current");

		$("div.imgs li.current").animate({opacity:0}).removeClass("current");
		$("div.imgs li").eq(index).animate({opacity:1}).addClass("current");
		
		clearInterval(animate);
		animate = setInterval("changePic()", 20000);
	});
	
	var animate = setInterval("changePic()", 20000);

	$(".nav ul li:not(:has(ul)) span").remove();
	$(".nav ul li:has(ul)")./**prepend("<span>&nbsp;&nbsp;&nbsp;</span>").**/find("ul").hide();
	$(".nav ul li.current").parent().parent().find('span:first').addClass("expand").parent().find("ul").show();
	$(".nav ul li.current span").addClass("expand").parent().find("ul").show();
	$(".nav ul li > span").click(
		function(){
			if ( $(this).hasClass("expand") ) {
				$(this).removeClass("expand").nextAll('ul').hide().parent().find('> span').removeClass("expand");
			} else {
				$(this).addClass("expand").nextAll('ul').show().parent().find('> span').addClass("expand");
			}
		}	
	);
	
	$("#services-container ul li").find("ul").hide();
	$("#services-container ul li:has(ul) > span").addClass('hasChildren').click(function(){
		if ( $(this).hasClass("expand") ) {
			$(this).removeClass("expand").nextAll('ul').hide().parent().find('> span').removeClass("expand");
		} else {
			$(this).addClass("expand").nextAll('ul').show().parent().find('> span').addClass("expand");
		}
	});
	
	$("#content .text table").find("tr:first td").addClass("first_tr");
	$("#content .text tr:even td").addClass("n");
	
	$("#tip li:first").css("paddingLeft", 0).css("background", 'none');

});

function changePic() {
	var currentSpan = $("div.nav-button li.current span");
	var index = $("div.nav-button li span").index(currentSpan[0]);
	var size = $("div.nav-button li span").size();
	if ( index == (size - 1) ) {
		$("div.nav-button li span:first").click();
	} else {
		currentSpan.parent().next().find("span").click();
	}
}