var centerTimeout;
var centerContentDefault;
var centerMenuDefault;
var centerBackgrounds = 2;
var selectedBackground;
var centerHold = true;
var centerTimeout;

var centerBackgroundData = new Array();
centerBackgroundData[0] = new Array("bg1.jpg","#FFF");
centerBackgroundData[1] = new Array("bg2.jpg","#ffdb7f");
//centerBackgroundData[2] = new Array("bg3.jpg","#d9bca9");
//centerBackgroundData[3] = new Array("bg4.jpg","#e7fffc");



function centerBuild(){
							centerContentDefault = $("#div_content").css("left");
							centerMenuDefault = $("#div_menu").css("top");
							
							changeTheme('start');
							
							
							$("#div_alpha").css('opacity','0.8');

							$("#div_backgroundSelector").css('margin-left','-'+($("#div_backgroundSelector").outerWidth()/2)+'px');
							
							$("#div_center").css('margin-top','-'+($("#div_center").outerHeight()/2)+'px');
							$("#div_center").css('margin-left','-'+($("#div_center").outerWidth()/2)+'px');
							
							$("#centerShadow").css('width',($("#div_center").outerWidth()+20)+'px');
							$("#centerShadow").css('height',($("#div_center").outerHeight()+20)+'px');				
							
							$("#centerShadow").css('margin-left','-'+($("#centerShadow").width()/2)+'px');				
							$("#centerShadow").css('margin-top','-'+($("#centerShadow").height()/2)+'px');
							
							$("#div_center").hover(
								function () {
										clearTimeout(centerTimeout);
										centerShowObjects();

								}, 
								function (){
										centerTimeout = setTimeout("centerHideObjects()",2000);
								}
							);
						  }

function centerHideObjects(){
	if(!centerHold)
	{
		$("#div_menu").stop();
		$("#div_content").stop();
		$("#div_adjustMenu").stop();
		$("#div_menu").animate({"top": "-30px"}, "slow");
		$("#div_adjustMenu").animate({'top': '-'+ $("#div_adjustMenu").outerHeight() +'px'}, "slow");
		$("#div_content").animate({"left": "-"+$("#div_content").outerWidth()+"px"}, "slow");
	}
}

function centerShowObjects(){
	if(!centerHold)
	{
		$("#div_menu").stop();
		$("#div_content").stop();
		$("#div_adjustMenu").stop();
		$("#div_menu").animate({"top": centerMenuDefault}, "slow");
		$("#div_adjustMenu").animate({"top": "0px"}, "slow");
		$("#div_content").animate({"left": centerContentDefault}, "slow");
	}
}

function changeTheme(direction){
	
	if(direction == 'start')
	{
		selectedBackground = Math.floor(Math.random()*centerBackgroundData.length);
		$("#div_center").fadeIn("slow");
		$("#centerShadow").fadeIn("slow");
		$("#div_backgroundSelector").fadeIn("slow");		
		$("#centerBackground").attr('src','img/'+ centerBackgroundData[selectedBackground][0]);
		$(".menuItem").css('color',centerBackgroundData[selectedBackground][1]);
		$("#div_alpha").css('background-color',centerBackgroundData[selectedBackground][1]);
		$("#centerBackground").fadeIn("slow");
		$("#div_menu").fadeIn("slow");
		$("#div_content").fadeIn("slow");
		$("#div_adjustMenu").fadeIn("slow", function(){centerHold = false;});
	}
	else if(direction == 'back')
	{
		selectedBackground = (selectedBackground - 1) >= 0 ? selectedBackground - 1 : centerBackgroundData.length - 1;
		changeThemeEffect();
	}
	else
	{
		selectedBackground = (selectedBackground + 1) <= centerBackgroundData.length - 1 ? selectedBackground + 1 : 0;
		changeThemeEffect();
	}
}

function changeThemeEffect(){
	centerHold = true;

	$("#div_menu").fadeOut("slow");
	$("#div_content").fadeOut("slow");
	$("#div_adjustMenu").fadeOut("slow");
	
	$("#centerBackground").fadeOut("slow", function(){
															$("#centerBackground").attr('src','img/'+ centerBackgroundData[selectedBackground][0]);
															$(".menuItem").css('color',centerBackgroundData[selectedBackground][1]);
															$("#div_alpha").css('background-color',centerBackgroundData[selectedBackground][1]);
															$("#centerBackground").fadeIn("slow");
															$("#div_menu").fadeIn("slow");
															$("#div_content").fadeIn("slow");
															$("#div_adjustMenu").fadeIn("slow", function(){centerHold = false;});													
													});	
}
	