$(document).ready(init);
window.onresize = checkWebsitePos;

function init()
{
	checkSlideShow();
	checkWebsitePos();
	initMenu();
}

function checkWebsitePos()
{
	var w = $('#APP_MAIN').width();
	var h = $('#APP_MAIN').height();
	
	// horizontal
	if($('body').width() < w)
	{
		$('#APP_MAIN').css({left: 0, marginLeft: '-40px'});
	}
	else
	{
		$('#APP_MAIN').css({left: '50%', marginLeft: '-525px'});
	}
	
	// vertikal
	if($('body').height() < h)
	{
		$('#APP_MAIN').css({top: 0, marginTop: 0});
	}
	else
	{
		$('#APP_MAIN').css({top: '50%', marginTop: '-288px'});
	}
}

function initMenu()
{
	for(var i = 1; i <= 6; i++)
	{
		$('#pc_m'+ i +'.noactive').hover
		(
			function()
			{
				$('#'+ $(this).attr('id') +'_pic').animate({opacity: 0}, 'fast');
			}
			,
			function()
			{
				$('#'+ $(this).attr('id') +'_pic').animate({opacity: 1}, 'normal');
			}
		);
	}
}

function checkSlideShow()
{
	if($('#pc_contentPic img').length > 1)
	{
		$('#pc_contentPic img:gt(0)').css({opacity: 0});
		slideShow(-1);
	}
}

var tmpPic = 0;
var stop = false;
function slideShow(n)
{
	var pics = $('#pc_contentPic img').length - 1;
	var t = 3000;

	if(n == -1)
	{
		window.setTimeout('slideShow(0)', t);
	}
	else
	{
		if(!stop)
		{
			var n2 = (n + 1 > pics)? 0 : n + 1;
			$('#pc_contentPic img').eq(n2).css('z-index', 12);
			$('#pc_contentPic img').eq(tmpPic).css('z-index', 10);
						
			tmpPic = n2;
			$('#pc_contentPic img').eq(n2).css({display: 'block'});
			$('#pc_contentPic img').eq(n2).animate({opacity: 1}, 4000, function()
			{
				$('#pc_contentPic img').eq(n).css({display: 'none', opacity: 0});
				window.setTimeout('slideShow('+ n2 +')', t);
			}
			);
		}
	}
}
