var flipboardStatus = new Array();
flipboardStatus[1] = 1;
flipboardStatus[2] = 1;
flipboardStatus[3] = 1;
flipboardStatus[4] = 1;
flipboardStatus[5] = 1;
flipboardStatus[6] = 1;

function animateFlipboard()
{
	var rand_no = Math.floor(6*Math.random()) + 1;

	if(1 == flipboardStatus[rand_no])
	{
		$("#img_"+rand_no+"_1").stop().animate({width:'0px',height:'155px',marginLeft:'77px',opacity:'0.5'},{duration:500});
		setTimeout(function() {
			$("#img_"+rand_no+"_2").stop().animate({width:'155px',height:'155px',marginLeft:'0px',opacity:'1'},{duration:500});
			setTimeout(function() {
				$("#img_"+rand_no+"_2").stop().animate({width:'0px',height:'155px',marginLeft:'77px',opacity:'0.5'},{duration:500});
					setTimeout(function() {
						$("#img_"+rand_no+"_3").stop().animate({width:'155px',height:'155px',marginLeft:'0px',opacity:'1'},{duration:500});
					},500);
			},2500);
	
		},500);
	
	
		flipboardStatus[rand_no] = 3;
	} else
	{
		$("#img_"+rand_no+"_3").stop().animate({width:'0px',height:'155px',marginLeft:'77px',opacity:'0.5'},{duration:500});
		setTimeout(function() {
			$("#img_"+rand_no+"_2").stop().animate({width:'155px',height:'155px',marginLeft:'0px',opacity:'1'},{duration:500});
			setTimeout(function() {
				$("#img_"+rand_no+"_2").stop().animate({width:'0px',height:'155px',marginLeft:'77px',opacity:'0.5'},{duration:500});
					setTimeout(function() {
						$("#img_"+rand_no+"_1").stop().animate({width:'155px',height:'155px',marginLeft:'0px',opacity:'1'},{duration:500});
					},500);
			},2500);
	
		},500);
	
		flipboardStatus[rand_no] = 1;
	}

	setTimeout("animateFlipboard()", 6000);
}

function animateRotateboard()
{
	var rand_no = Math.floor(6 * Math.random()) + 1;

	$("#img_" + rand_no + "_1").stop().animate({width:'0px', marginLeft:'77px', opacity:'0.5'},{duration:500});
	
	setTimeout(function()
	{
		$("#img_" + rand_no + "_2").stop().animate({width:'155px', marginLeft:'0px', opacity:'1'},{duration:500});
		setTimeout(function()
		{
			$("#img_" + rand_no + "_2").stop().animate({width:'0px', marginLeft:'77px', opacity:'0.5'},{duration:500});
			setTimeout(function()
			{
				$("#img_" + rand_no + "_1").stop().animate({width:'155px', marginLeft:'0px', opacity:'1'},{duration:500});
			}, 500);
		}, 2500);

	}, 500);

	setTimeout("animateRotateboard()", 6000);
}

function rotateRotateboard(rand_no)
{
	if(1 == $("#img_" + rand_no + "_1").css("opacity"))
	{
		$("#img_" + rand_no + "_1").stop().animate({width:'0px', marginLeft:'77px', opacity:'0'},{duration:250});
		setTimeout(function()
		{
			$("#img_" + rand_no + "_2").stop().animate({width:'155px', marginLeft:'0px', opacity:'1'},{duration:250});
		}, 250);
		
		for(var ii = 1; ii < 7; ii ++)
		{
			if(rand_no != ii)
			{
				resetRotateboard(ii);
			}
		}
	}
}
function resetRotateboard(rand_no)
{
	$("#img_" + rand_no + "_2").stop().animate({width:'0px', marginLeft:'77px', opacity:'0'},{duration:250});
	setTimeout(function()
	{
		$("#img_" + rand_no + "_1").stop().animate({width:'155px', marginLeft:'0px', opacity:'1'},{duration:250});
	}, 250);
}


function init()
{
	var h = $(document).height() + 'px';
	$("#body_main").css({height:h});

	$("div[id^='div_menu_']").hover(
		function()
		{
			var div_id = $(this).attr("id");
			var img_id = new String(div_id).replace("div_", "img_");
			$("#" + img_id).stop().animate({opacity: 0.3}, 600);
		},
		function()
		{
			var div_id = $(this).attr("id");
			var img_id = new String(div_id).replace("div_", "img_");
			$("#" + img_id).stop().animate({opacity: 1}, 600);
		}
	);

	for(var ir = 1; ir < 7; ir ++)
	{
		$("#img" + ir).hover(
			function()
			{
				var id = (this).id;
				id = new String(id).substring(new String(id).length - 1);
				rotateRotateboard(id);
			}, 
			function()
			{
				var id = (this).id;
				id = new String(id).substring(new String(id).length - 1);
				resetRotateboard(id);
			}
		);
	}
	
	setTimeout("animateRotateboard()", 4000);
}
