function shrink(obj, time){}
//Cufon.replace(["span.calibri", "a.calibri"]);
function resizeByWidth(img, width)
{
	var maxWidth = width;
	var image = new Image();
	image.src = img.src;
	var width = image.width;
	var height = image.height;
	if(width > maxWidth) {
		var ratio = width / height;
		width = maxWidth;
		height = width / ratio;
		img.width = width;
		img.height = height;
	}
}
function resizeByHeight(img, height)
{
	var maxHeight = height;
	var image = new Image();
	image.src = img.src;
	var width = image.width;
	var height = image.height;
	if(height > maxHeight) {
		var ratio = width / height;
		height = maxHeight;
		width = height * ratio;
		img.width = width;
		img.height = height;
	}
}
function resize(img, width, height)
{
	var maxWidth = width;
	var maxHeight = height;
	var image = new Image();
	image.src = img.src;
	var width = image.width;
	var height = image.height;
	if(width <= maxWidth && height <= maxHeight) {
		img.width = width;
		img.height = height;
	}
	else if(width > maxWidth && height <= maxHeight) {
		var ratio = width / height;
		width = maxWidth;
		height = parseInt(width / ratio);
		img.width = width;
		img.height = height;
	}
	else if(height > maxHeight && width <= maxWidth) {
		var ratio = width / height;
		height = maxHeight;
		width = parseInt(height * ratio);
		img.width = width;
		img.height = height;
	}
	else {
		var ratio = width / height;
		if(ratio > 1) {
			width = maxWidth;
			height = parseInt(width / ratio);
		}
		else {
			height = maxHeight;
			width = parseInt(height * ratio);
		}
		img.width = width;
		img.height = height;
	}
}
$(function()
{
	$("#login").click( function() {
		var _login = $("input[name='login']").val();
		var _pwd = $("input[name='pwd']").val();
		$.post( "public/login.php",
				{login:_login, pwd:_pwd},
				function(res) {
					if(res == "false")
						alert("Login name or password is wrong!");
					else {
					 	location.href = "default.php";
					}
				});
	});
	
	$("input[name='pwd']").focus( function() {
		$(this).keydown(function(e)
		{
			var e = window.event ? window.event : e;
			if(e.keyCode == 13)
				$("#login").click();
		});
	});
	
	$("#forgetPwd").click( function() {
		$("tr.forgetBtn").hide();
		$("tr.forgetEmail").show();
	});
	
	$("#getPwd").click( function() {
		var _email =  $("input[name='email']").val();
		if(_email.length == 0){
			alert("Email can not be empty!");
			return false;
		}
		var _type = 5;
		$.blockUI({ message: "<h1><span class='gray_13'><br><br>Your login and password have been sent to your email. Please check your spam box in case you did not receive it and contact your president if you have not yet received the email.<br><br><br></span></h1>" });
		$.post( "management/ajax/reset_member.php",
				{email:_email, type:_type},
				function(res)
				{
					$.unblockUI();
					if(res == "true") {
						alert("Reset successfully!");
						location.reload()
					}
					else{
						
						alert(res);
						return false;
					}
				});
	});
 
	
	var gid = 0;
	//var now_time = 1280275200000
	var old_time = Date.parse("2010-07-27");
	var one_day_time = 24*3600*1000;
	
	 $(document).ready(function(){   
	 	var $project = $("img.project"); 
		var $btn = $("img.button");
		$("img.project-subject").hide();
		
		var now_time = new Date().getTime();
		var now_days = (now_time - old_time)/one_day_time;
		gid = Math.floor((now_days%25)/5);
		
		$project.eq(gid).css({top:"0px"});
		$("img.project-subject").eq(gid).show();
		if(gid == 0) {
			$btn.eq(0).attr("src", "public/button1-full.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			//$("img.project-more").attr("src", "public/energy-more.gif");
		}
		else if(gid == 1) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-full.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			$("#intro").hide();
		}
		else if(gid == 2) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-full.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			$("#intro").hide();
		}
		else if(gid == 3) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-full.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			$("#intro").hide();
		}
		else if(gid == 4) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-full.png");
			$("#intro").hide();
		}		

	 });
	 
	//$("#arrow").click( function()
	$("img.button").click(function()
	{
		var $btn = $("img.button");
		var id = $btn.index(this);
		var $project = $("img.project");
		if(id == 0) {
			$btn.eq(0).attr("src", "public/button1-full.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			//$("img.project-more").attr("src", "public/energy-more.gif");
		}
		else if(id == 1) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-full.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			$("#intro").hide();
		}
		else if(id == 2) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-full.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			$("#intro").hide();
		}
		else if(id == 3) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-full.png");
			$btn.eq(4).attr("src", "public/button5-empty.png");
			$("#intro").hide();
		}
		else if(id == 4) {
			$btn.eq(0).attr("src", "public/button1-empty.png");
			$btn.eq(1).attr("src", "public/button2-empty.png");
			$btn.eq(2).attr("src", "public/button3-empty.png");
			$btn.eq(3).attr("src", "public/button4-empty.png");
			$btn.eq(4).attr("src", "public/button5-full.png");
			$("#intro").hide();
		}		

		$("img.project-subject").hide();
		$project.css({left:"-800px",top:"0px"});
		$project.eq(gid).css({left:"0px"});
		$project.eq(gid).animate({left:"-=300px", queue:false, duration:0.1})
				.animate({left:"+1100px", queue:false, duration:0.1},
				function(){
					$project.eq(id).css({left:"-800px"});
					$project.eq(id).animate({left:"+=800px", queue:false, duration:15});
					$("img.project-subject").eq(id).show();
					if(id == 0)
						$("#intro").show();
				});
		gid = id;
	});
	
	$("#more").mouseover(function()
	{
		$("img.project-more").eq(gid).fadeIn(800);
	});
	$("#more").mouseout(function()
	{
		$("img.project-more").fadeOut(800);
	});
	$("span.home-news-more-link").mouseover(function()
	{
		var $newsLink = $("span.home-news-more-link");
		var $newsContent = $("div.home-news-content");
		var id = $newsLink.index(this);
		$newsContent.eq(id).show();
	});
	function exitMenu()
	{
		$("div.home-news-content").hide();
	}
	$("div.menu-top-shade").mouseout(function()
	{
		window.setTimeout(exitMenu, 500);
	});

	var top = 0;
	var up;
	var down;
	function moveUp()
	{
		if(top >= 0)
			return;
		top = top + 1;
		$("#share-member-wrapper").css({"top":top+"px"});
	}
	function moveDown()
	{
		if(top <= -300)
			return;
		top = top - 1;
		$("#share-member-wrapper").css({"top":top+"px"});
	}
	$("#up").mouseover(function()
	{
		up = window.setInterval(moveUp, 20);
	});
	$("#up").mouseout(function()
	{
		clearInterval(up);
	});
	$("#down").mouseover(function()
	{
		down = window.setInterval(moveDown, 20);
	});
	$("#down").mouseout(function()
	{
		clearInterval(down);
	});
	$("div.share-member").mouseover(function()
	{
		var $member = $("div.share-member");
		var $memberImage = $("div.share-member-image");
		var $memberIntro = $("div.share-member-intro");
		var $memberProfile = $("div.share-member-profile");
		var id = $member.index(this);
		$memberImage.hide();
		$memberIntro.hide();
		$memberProfile.hide();
		$memberImage.eq(id).show()
		$memberIntro.eq(id).show();
		$memberProfile.eq(id).show();
	});
	$("div.share-alumni-image").mouseover(function()
	{
		var $profile = $("div.share-profile-cell");
		var $shade = $("div.border-shade");
		var id = $("div.share-alumni-image").index(this);
		$shade.hide();
		$shade.eq(id).show();
		$profile.hide();
		$profile.eq(id).show();
	});
});
