var statusManager = new manageStatus(1021);
statusManager.storeStatus('HOME',1);
statusManager.storeStatus('MORE',1);
statusManager.storeStatus('CONTATTI',1);
statusManager.storeStatus('TECH',2);
statusManager.storeStatus('COM',0);
statusManager.move('HOME');

function hideDiv(divID) {
	$('#'+divID).hide();
}

function showDiv(divID) {
	$('#'+divID).show();
}

function fadeOutDiv() {
	var configObject = {
		divID: arguments[0],
		time: arguments[1],
		callback: function(){}
	};
	
	if (arguments.length>2) {
		if (typeof arguments[2] == 'function') configObject['callback'] = arguments[2];
	}
	
	$('#'+configObject['divID']).fadeOut(configObject['time'],configObject['callback']());
}

function fadeInDiv() {
	var configObject = {
		divID: arguments[0],
		time: arguments[1],
		callback: function(){}
	};
	
	if (arguments.length>2) {
		if (typeof arguments[2] == 'function') configObject['callback'] = arguments[2];
	}
	
	$('#'+configObject['divID']).fadeIn(configObject['time'],configObject['callback']());
}

function moveDIV() {
	var configObject = {
		divID: arguments[0],
		time: arguments[1],
		leftScroll: arguments[2],
		topScroll: arguments[3],
		callback: function(){}
	}
	
	if (arguments.length>4) {
		if (typeof arguments[4] == 'function') configObject['callback'] = arguments[4];
	}
	
	if (configObject['leftScroll']*1==0 && configObject['topScroll']*1==0) {
		configObject['callback']();
	} else {
		$('#'+configObject['divID']).animate({"left": "+="+configObject['leftScroll']+"px","top": "+="+configObject['topScroll']+"px"},{duration:configObject['time']},{complete:setTimeout(function(){configObject['callback']();},(configObject['time']*1+10))});
	}
}

function topMenuGestione() {
	var where;
	if (arguments.length>0) {
		where = arguments[0];
	} else {
		where = 'HOME';
	}
	
	if (gestoreLivelli.currentStatus=='more') {
		go(where);
	} else {
		if (where!='MORE') fromMore(where);
	}
}

function fromMore(where) {
	var functionExec = function() {
		if (where!='HOME') {
			callbackFromMore['functionCallback'] = function() {
				go(where);
				callbackFromMore['functionCallback'] = function(){};
			}
		}
		go('HOME');
		goMore();
	}
	var backgroundVisibile = (($('#more_contatti').is(':hidden'))?false:true);
	if (!backgroundVisibile) {
		visualizzaContattiMore(functionExec);
	} else {
		functionExec();
	}
}

function go() {
	var where;
	if (arguments.length>0) {
		where = arguments[0];
	} else {
		where = 'HOME';
	}
	
	var callbackFunction = function(){};
	
	if (where=='COM' || where=='TECH') {
		callbackFunction = function() {
			setTimeout(function(){visualizzaArea(where);showHideArea();},500);
		}
	} else if (where=='HOME' && arguments.length>1) {
		callbackFunction = arguments[1];
	} else if (where=='MORE') {
		go('HOME',function(){
			goMore();
		});
		return;
	}
	
	var configObject = {
		divId: 'mover',
		time: 1000,
		leftScroll: (statusManager.calculateDistance(where)*statusManager.getFrameSize()),
		topScroll: 0,
		callback: callbackFunction
	}
	
	statusManager.move(where);
	if (hideShowContentManager.isVisible()) {
		showHideContent(function(){
			moveDIV(configObject['divId'],configObject['time'],configObject['leftScroll'],configObject['topScroll'],function(){
				visualizzaContenuto('white.html');
				cambiaColoreTitolo(where);
				setLeftRight();
				configObject['callback']();
			});
		});
	} else if (hideShowAreaManager.isVisible()) {
		showHideArea(function(){
			moveDIV(configObject['divId'],configObject['time'],configObject['leftScroll'],configObject['topScroll'],function(){
				visualizzaContenuto('white.html');
				cambiaColoreTitolo(where);
				setLeftRight();
				configObject['callback']();
			});
		});
	} else {
		moveDIV(configObject['divId'],configObject['time'],configObject['leftScroll'],configObject['topScroll'],function(){
			cambiaColoreTitolo(where);
			setLeftRight();
			configObject['callback']();
		});
	}
}

function cambiaColoreTitolo(where) {
	var configObject = {
		HOME: '#ED3',
		TECH: '#444',
		COM: '#BB1F52'
	};
	
	$('#details_title').css({color: configObject[where]});
}
