$(function(){
/*============================image roll over===============================*/
	jQuery('.imgover').each(function(){
		this.osrc = jQuery(this).attr('src');
		this.rollover = new Image();
		this.rollover.src = this.osrc.replace(/(\.gif|\.jpg|\.png)/, "_o$1");
	}).hover(function(){
		jQuery(this).attr('src',this.rollover.src);
	},function(){
		jQuery(this).attr('src',this.osrc);
	});
	
/*============================vertical-menu===============================*/
	$("#lNav>li>ul").hide();

	/*$("#lNav a").click(function(){
		if($(this).next("ul").length > 0) {
			$(this).next("ul").slideToggle();
			return false;
		}
	});*/
	
	$("#lNav a").click(function(){
		if ($(this).next("ul").is(":hidden")) {
			$(this).addClass("active");
			$(this).next("ul").slideDown("slow");
		} else {
			$(this).removeClass("active");
			$(this).next("ul").slideUp("slow");
		}
	});
	
	$(".aboutTable tr:even").css("background-color", "#eee");
	
	$('#footer').wrap('<div id="footerWrap" />');
	


});


/*============================mail image scroll===============================*/

function is_mobile () {
	var useragents = ['iPhone','iPad','iPod','Android','dream','CUPCAKE','blackberry9500','blackberry9530','blackberry9520','blackberry9550','blackberry9800','webOS','incognito','webmate'];
	var pattern = new RegExp(useragents.join('|'), 'i');
	return pattern.test(navigator.userAgent);
}

$(document).ready(function(){

	var ele = $("#scrollOuter");
	var eleUp = $("#scrollUp");
	var eleDown = $("#scrollDown");
	var scrolling;
	var ua = navigator.userAgent;

	var H1 = ele.height();
	ele.css("height", "auto");
	var H2 = ele.height();
	var H3 = ele.height() - H1 - 10;
	ele.css("height", H1+"px");

	if(ele.scrollTop() == "0" ){
		eleUp.css("display", "none");
	} else {
		eleUp.css("display", "block");
	}
	if(ele.scrollTop() >= "H3" ){
		eleDown.css("display", "none");
	} else if(H3 < "0" ){
		eleDown.css("display", "none");
	} else {
		eleDown.css("display", "block");
	}

	if (is_mobile()) {
		var start = "click";
		var scroll = 5;
		var speed = 40;
		var stop = 500;
	} else {
		var start = "mouseenter";
		var end = "mouseleave";
		var scroll = 5;
		var speed = 40;
	}

	eleUp.bind(start,function() {
		if (is_mobile()) {
			if (scrolling) window.clearInterval(scrolling);
			scrolling = window.setInterval(function() {
				ele.scrollTop(ele.scrollTop() - scroll);
			}, speed);
			window.setTimeout(function() {
				if (scrolling) window.clearInterval(scrolling);
			}, stop);
		} else {
			scrolling = window.setInterval(function() {
				ele.scrollTop(ele.scrollTop() - scroll);
			}, speed);
		}
	});

	eleDown.bind(start,function() {
		if (is_mobile()) {
			if (scrolling) window.clearInterval(scrolling);
			scrolling = window.setInterval(function() {
				ele.scrollTop(ele.scrollTop() + scroll);
			}, speed);
			window.setTimeout(function() {
				if (scrolling) window.clearInterval(scrolling);
			}, stop);
		} else {
			scrolling = window.setInterval(function() {
				ele.scrollTop(ele.scrollTop() + scroll);
			}, speed);
		}
	});

	if (!is_mobile()) {
		eleUp.bind(end,function() {
			if (scrolling) window.clearInterval(scrolling);
		});
		eleDown.bind(end,function() {
			if (scrolling) window.clearInterval(scrolling);
		});
	}
	ele.scroll(function(){
		if($(this).scrollTop() == "0" ){
			eleUp.fadeOut("slow");
		} else {
			eleUp.fadeIn("slow");
		}
		if($(this).scrollTop() >= H3 ){
			eleDown.fadeOut("slow");
		} else {
			eleDown.fadeIn("slow");
		}
	});

});


