/*----------------------------- JavaScript Document ----------------------------
 [Author]: Fisherhuang  
 [Date]: 2010-06-11  
 [Contact]: www.maesinfo.com  
/*------------------------------------------------------------------------------*/
$(document).ready(function() {
	// ---------------------clear search input---------------------
		$("#keywords").focus(function() {
			if ($(this).val() == "Key words") {
				$(this).val("");
			}
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).val("Key words");
			}
		});

		// ---------------------set site
		// map----------------------------------------------
		$(document).ready(function() {
			$('.site_map_btn').click(function() {
				$('#sitemap').slideToggle("slow");
			});
		});

		// ----------------------set sub page
		// menu--------------------------------------
		var location = $('#location').text();
		var m_dd = $('.article_menu dd a');
		m_dd.each(function() {
			if (location == $(this).text())
				$(this).attr('id', 'sub_menu_now');
		})
	});

function gotoPage(crepage, topage) {
	$('.' + crepage).hide();
	$('.' + topage).show();
}

$(function() {
	$
			.ajax( {
				type : "POST",
				url : "xml/banner.xml",
				dataType : ($.browser.msie) ? "text" : "xml",

				success : function(data) {
					var xml;
					if (typeof data == "string") {
						xml = new ActiveXObject("Microsoft.XMLDOM");
						xml.async = false;
						xml.loadXML(data);
					} else {
						xml = data;
					}
					$(xml)
							.find("list")
							.each(
									function(i) {
										var bimg = $(this).children("bimg")
												.text();
										var simg = $(this).children("simg")
												.text();
										var title = $(this).children("title")
												.text();
										var des = $(this).children("des")
												.text();
										var url = $(this).children("url")
												.text();
										var bannerli = document
												.createElement("li");
										var navli = ("<li num=" + i
												+ "><dl><dt><img src=" + simg
												+ "></dt><dd>" + title + "</dd><dd class='ddar'></dd></dl></li>");
										$("#banner_nav").find("ul").append(
												$(navli));
										$(bannerli)
												.html(
														"<div class='banner_title'>"
																+ title
																+ "</div><div class='banner_des'>"
																+ des
																+ "</div><div class='banner_show'><a href="
																+ url
																+ "><img src="
																+ bimg
																+ "></a></div>");
										$("#banner_list").find("ul").append(
												$(bannerli));

									});
					var banner = $("#banner_list").find("li");
					$("#banner_nav").find("li").eq(0).addClass("active");
					banner.eq(0).fadeIn(500);
					banner.eq(0).find(".banner_title").animate( {
						"top" : 30
					}, 1000);
					setTimeout(function() {
						banner.eq(0).find(".banner_des").animate( {
							"left" : 10
						}, 1000);
					}, 500);
					$("#banner_nav").find("li").click(function() {
						$("#banner_nav").find("li").removeClass("active");
						$("#banner_nav").find(".ddar").hide();
						$(this).addClass("active");
						$(this).find(".ddar").show();
						banner.fadeOut(500);
						var n = $(this).attr("num");
						banner.find(".banner_title").css("top", "-30px");
						banner.find(".banner_des").css("left", "-500px");
						banner.eq(n).fadeIn(500);
						banner.eq(n).find(".banner_title").animate( {
							"top" : 30
						}, 1000);
						setTimeout(function() {
							banner.eq(n).find(".banner_des").animate( {
								"left" : 10
							}, 1000);
						}, 500);
					});

				},
				error : function(data) {
					
				}
			});
})
// auto play
var timer = null;
var offset = 5000;
var index = 0;
function show(a) {
	$("#banner_nav").find("li").removeClass("active");
	$("#banner_nav").find(".ddar").hide();
	$("#banner_nav").find("li").eq(a).addClass("active");
	$("#banner_nav").find("li").eq(a).find(".ddar").show();
	$("#banner_list").find("li").fadeOut(500);
	$("#banner_list").find("li").find(".banner_title").css("top", "-80px");
	$("#banner_list").find("li").find(".banner_des").css("left", "-500px");
	$("#banner_list").find("li").eq(a).fadeIn(500);
	$("#banner_list").find("li").eq(a).find(".banner_title").animate( {
		"top" : 30
	}, 1000);
	setTimeout(function() {
		$("#banner_list").find("li").eq(a).find(".banner_des").animate( {
			"left" : 10
		}, 1000);
	}, 500);
}
function auto() {
	index++;
	if (index > 1) {
		index = 0;
	}
	show(index);
	window.setTimeout(auto, offset);
}
$(function() {
	window.setTimeout(auto, offset);
});

$(function(){
	  $("#menuBox").find("li").hover(function(){
	    $(this).addClass("sfhover");
		$(this).find("ul").show();
	  },function(){
	    $(this).removeClass("sfhover");
		$(this).find("ul").hide();
	  })
	})
