var detailFadeInLenth = 500;
var detailFadeOutLenth = 500;
var detailDisplayLength = 8000;
var detailFgcolor = "#666666";
var detailBgcolor = "#ffffff";
var detailSteps = 10;

var detailIsrunning = false;
var detailFadeLevel = 0;
var detailStage = 0;

var fdetailTimer = null;
var detailTimer = null;
var current = 0;

var detailstitles = new Array();
var details = new Array();

detailstitles[0] = "WEB 2.0 Applications ";
details[0] = "Insieme di funzioni e </p>caratteristiche che definiscono</p> la \"Nuova Frontiera\" delle applicazioni</p> sul web; ";

detailstitles[1] = "Social Bookmarking";
details[1] = "Classificazione di risorse basata su etichette(tags)</p> create dagli esseri umani, che \"comprendono\" il significato</p> ed il contenuto delle risorse stesse.";

detailstitles[2] = "Rich Interfaces";
details[2] = "Migliorare l'interattivit&agrave;, la velocit&agrave; e l'usabili&agrave; </p> di una pagina web con AJAX e il Dynamic-HTML.";

detailstitles[3] = "Common Workspaces";
details[3] = "Supporto per facilitare e rendere pi&ugrave; efficace il lavoro</p> cooperativo da parte di pi&ugrave; persone.<br/>" +
				"Permettere a tutti di aggiungere contenuti, </p>ma anche di modificare i contenuti esistenti inseriti da altri utenti.";

detailstitles[4] = "Multi-Channel Delivery";
details[4] = "Scrivere e organizzare il contenuto una volta, per farlo arrivare ovunque e renderlo accessibile da ogni media e tecnologia: Web, RSS, TV, Mobile.";

detailstitles[5] = "Social Software";
details[5] = "Applicazioni che consentono agli individui di incontrarsi, </p> interagire e collaborare in rete, costruendo </p>delle comunit&agrave; onLine.";

detailstitles[6] = "Service Oriented Architecture";
details[6] = "Processi di Business non pi&ugrave; </p>vincolati da una specifica piattaforma o da </p>un'applicazione, ma indipendenti e </p>riutilizzabili a richiesta come risorse </p>computazionali. </p>" +
				"Permette di agevolare l'interazione tra </p>le diverse realt&agrave; aziendali </p>permettendo alle attivit&agrave; di business </p>di sviluppare processi efficienti, </p>aumentandone la flessibilit&agrave;</p>" +
				" e l'adattabilit&agrave;."; 
				
detailstitles[7] = "Portal Applications";
details[7] = "Ingresso privilegiato verso tutte le risorse informatiche della tua azienda.</p> NovaWorks produce portali per l'impresa che rispettano le specifiche " +
				"Open Directory Project: <br/>"; 
				
detailstitles[8] = "Content Management";
details[8] = "Organizza e semplifica la creazione collaborativa di documenti ed altri contenuti, definendone la semantica e molteplici formati di pubblicazione."; 

detailstitles[9] = "Business Intelligence";
details[9] = "Raccogliere informazioni per trarre stime, valutazioni e permettere alle persone di prendere decisioni strategiche, aggiornate e significative nel "+
				"contesto di mercato cui partecipano."; 

function initialiseDetailer() {
	detailIsrunning = false;
}

function runDetailer() {
	
	detailStage = 2;
	//detailTimer = self.setTimeout("work()", detailDisplayLength);
	detailWork();
}

function detailWork() {
	//alert("detailIsrunning = " + detailIsrunning + ", detailStage = " + detailStage);
	if (detailIsrunning == true) {
	
		//detailStage = 1 Fading out
		//detailStage = 2 Swapping
		//detailStage = 3; Fading in
		//detailStage = 4; Waiting
		//detailStage = 5; User engaging with detailer
	if (detailStage == 1) { // fade out
		if (detailIsrunning == true && detailFadeLevel <= detailSteps) {
			setDetailerColor(htmlColor(calculateDetailColor(detailFgcolor, detailBgcolor, detailFadeLevel)))
			detailFadeLevel ++;
			fdetailTimer = self.setTimeout("detailWork()", Math.round(detailFadeOutLenth/detailSteps));
		}
		if (detailFadeLevel > detailSteps) {
			detailStage = 5;
			hideBox();
		}
	} else if (detailStage == 2) { // swap
		
		setDetailTitle(detailstitles[current]);
		setDetail(details[current]);
		if (detailIsrunning == true) {
			// Set the detailTimer
			detailTimer = self.setTimeout("detailWork()", 1);
		}
		detailStage = 3;
	} else if (detailStage == 3) { // Fade in
		displayBox();
		if (detailIsrunning == true && detailFadeLevel >= 0) {
			setDetailerColor(htmlColor(calculateDetailColor(detailFgcolor, detailBgcolor, detailFadeLevel)))
			detailFadeLevel --;
			fdetailTimer = self.setTimeout("detailWork()", Math.round(detailFadeInLenth/detailSteps));
		}
		if (detailFadeLevel < 0) {
			detailStage = 4;
		}
	} else if (detailStage == 4) { // Waiting
		if (detailIsrunning == true) {
			// Set the detailTimer
			detailTimer = self.setTimeout("detailWork()", detailDisplayLength);
		}
		detailStage = 1; // next detailStage
	} 
	}
}

function pause() {
	detailIsrunning = false;
	if (detailTimer) {
		self.clearTimeout(detailTimer);
	}
	if (fdetailTimer) {
		self.clearTimeout(fdetailTimer);
	}
	// Restore color
	detailFadeLevel = 0;
	setDetailerColor(htmlColor(calculateDetailColor(detailFgcolor, detailBgcolor, detailFadeLevel)))
}

function unpause() {
	detailIsrunning = true;
	detailStage = 4;
	detailWork();
	
}

function fadeIn() {
	if (detailIsrunning == true && detailFadeLevel >= 0) {
		setDetailerColor(htmlColor(calculateDetailColor(detailFgcolor, detailBgcolor, detailFadeLevel)))
		detailFadeLevel --;
		//fdetailTimer = self.setTimeout("fadeIn()", Math.round(detailFadeInLenth/detailSteps));
	}
}

function fadeOut() {
	if (detailIsrunning == true && detailFadeLevel <= detailSteps) {
		setDetailerColor(htmlColor(calculateDetailColor(detailFgcolor, detailBgcolor, detailFadeLevel)))
		detailFadeLevel ++;
		//fdetailTimer = self.setTimeout("fadeOut()", Math.round(detailFadeOutLenth/detailSteps));
	}
}

function setDetailerColor(colour) {
	//alert("Setting color to " + colour);
	detailerContent = document.getElementById('detail-content');
	if (detailerContent) {
		detailerContent.style.color = colour;
	}
}

function calculateDetailColor(start, end, step) {
	var startColors = makeColorArray(start);
	var endColors = makeColorArray(end);
	
	var colors = null;
	
	if (startColors && endColors) {
		var diff = new Array(endColors[0]-startColors[0], endColors[1]-startColors[1], endColors[2]-startColors[2]);
		colors = new Array(Math.round(startColors[0] + ((diff[0]*step)/detailSteps)), Math.round(startColors[1] + ((diff[1]*step)/detailSteps)), Math.round(startColors[2] + ((diff[2]*step)/detailSteps)));
	}
	
	return colors;
}

function htmlDetailColor(colors) {
	return "rgb(" + colors[0] + ", " + colors[1] + ", " + colors[2] + ")";
}

/*function makeColorArray(colorStr) {

	var cArray = null;
	
	if (colorStr.length == 7) {
		cArray = new Array(parseInt("0x"+colorStr.substr(1, 2)), parseInt("0x"+colorStr.substr(3, 2)), parseInt("0x"+colorStr.substr(5, 2)));
	} else if (colorStr.length == 18) {
		cArray = new Array(parseInt(colorStr.substr(4, 3)), parseInt(colorStr.substr(9, 3)), parseInt(colorStr.substr(14, 3)));
	} else if (colorStr.length == 15) {
		cArray = new Array(parseInt(colorStr.substr(4, 2)), parseInt(colorStr.substr(8, 2)), parseInt(colorStr.substr(12, 2)));
	} else if (colorStr.length == 12) {
		cArray = new Array(parseInt(colorStr.substr(4, 1)), parseInt(colorStr.substr(7, 1)), parseInt(colorStr.substr(10, 1)));
	}
	
	return cArray;
}*/

function setDetailTitle(title) {
	document.getElementById('detail-title').innerHTML = title;
	return true;
}

function setDetail(content) {
	document.getElementById('detail-content').innerHTML = content;
	return true;
}

function startDetailer() {
	initialiseDetailer();	
	detailIsrunning = true;
	runDetailer();
}

function stopDetailer() {
	initialiseDetailer();
	if (detailTimer) {
		self.clearTimeout(detailTimer);
	}
}

function displayBox(){
	//new Effect.Appear("cxcontent");
	var mxcontent = document.getElementById('mxcontent');
	if(mxcontent.style.display == 'none'){
		mxcontent.style.display = '';
		staticbar();
	}
}

function hideBox(){
	//new Effect.Appear("cxcontent");
	var mxcontent = document.getElementById('mxcontent');	
	mxcontent.style.display = 'none';
}

function engage(key){
	current = key;
	//var mxcontent = document.getElementById('mxcontent');
	//mxcontent.style.color = "#c1e950";
	//setOpacity('mxcontent');
	//alert(cxcontent.class);
	startDetailer();
}

var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 30 //set x offset of bar in pixels
var startY = 5 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function staticbar(){

	barheight = document.getElementById("mxcontent").offsetHeight;
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		
		var el = d.getElementById(id);

		if(d.layers) 
			el.style = el;
			
		el.sP = function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
			el.y = startY;
		else{
			el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
			el.y -= startY;
		}
		return el;
	}

	window.stayTopLeft = function(){
		if (verticalpos=="fromtop"){
			var pY = ns ? pageYOffset : iecompattest().scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
			var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		var newX = parseInt(window.innerWidth*0.6) - 550;
		if(newX > startX) ftlObj.x = newX;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	
	ftlObj = ml("mxcontent");
	stayTopLeft();
}

/*if (window.addEventListener)
	window.addEventListener("load", staticbar, false)
else if (window.attachEvent)
	window.attachEvent("onload", staticbar)
else if (document.getElementById)
	window.onload=staticbar*/


var setOpacity = function(element, value){  
  element= $(element);  
  if (value == 1){
    Element.setStyle(element, { opacity: 
      (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 
      0.999999 : 1.0 });
    if(/MSIE/.test(navigator.userAgent) && !window.opera)  
      Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});  
  } else {  
    if(value < 0.00001) value = 0;  
    Element.setStyle(element, {opacity: value});
    if(/MSIE/.test(navigator.userAgent) && !window.opera)  
     Element.setStyle(element, 
       { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
                 'alpha(opacity='+value*100+')' });  
  }
} 

/****************************************************************************************************************************/


function showDetail(key){
					/*var thumbWindow = new Window('testo',{className:"mac_os_x", width:480, height:360, zIndex: 10, resizable: false, title: 'Scegli immagine', closable: true, draggable:true, wiredDrag: true } );
					// alert('chooseImage');
	            	thumbWindow.getContent().innerHTML = res;
	            	thumbWindow.setDestroyOnClose();
					thumbWindow.showCenter(true);*/
					
					
}


