// menu
var g_strImageNames = new Array();

g_strImageNames[0] = 'square_about';
g_strImageNames[1] = 'square_solutions';
g_strImageNames[2] = 'square_approach';
g_strImageNames[3] = 'square_skills';
g_strImageNames[4] = 'square_clients';
g_strImageNames[5] = 'square_partners';
g_strImageNames[6] = 'btn_about';
g_strImageNames[7] = 'btn_solutions';
g_strImageNames[8] = 'btn_approach';
g_strImageNames[9] = 'btn_skills';
g_strImageNames[10] = 'btn_clients';
g_strImageNames[11] = 'btn_partners';

// preload all the images listed in the array "p_strImagesNames" passed as parameter
function PreLoadImages(p_strImagesNames)
{
	var g_oPreLoadedImages = new Array();

	for(i = 0; i < p_strImagesNames.length; i++)
	{
   		g_oPreLoadedImages[i] = new Image();
   		g_oPreLoadedImages[i].src = p_strImagesNames[i];
	}
}

var g_strOriginalImagesSrc = new Array();

// Each navigation section (ie, skills, clients,...) has diferent squares and text highlighted by default.
// This function store the path of the images contained in "g_strImageNames" composing each navigation section. This information
// will be used by the "RestoreOriginalImagesSrc" in order to restore the default images
function StoreImageSrc(p_txtPath, p_iSection)
{
	for(i = 0; i < 6; i++)
	{
		g_strOriginalImagesSrc[i] = p_txtPath + "square_off.gif";
		g_strOriginalImagesSrc[i + 6] = p_txtPath + g_strImageNames[i + 6] + "_off.gif";
	}

	switch(p_iSection)
	{
		case 6:
			for(i = 0; i < 5; i++)
			{
				g_strOriginalImagesSrc[i] = p_txtPath + "square_over.gif";
			}
			g_strOriginalImagesSrc[5] = p_txtPath + "square_on.gif";
			break;
		default:
			g_strOriginalImagesSrc[p_iSection] = p_txtPath + "square_over.gif";
			g_strOriginalImagesSrc[p_iSection + 6] = p_txtPath + g_strImageNames[p_iSection + 6] + "_on.gif";
			break;
	}
}

function StoreOriginalImageSrc(p_strLayerName)
{
	if(!ie4 && !ns6 && p_strLayerName != '')
	{
		for(i = 0; i < g_strImageNames.length; i++)
		{
			g_strOriginalImagesSrc[i] = document.layers[p_strLayerName].document.images[g_strImageNames[i]].src;
		}
	}
	else
	{
		for(i = 0; i < g_strImageNames.length; i++)
		{
			g_strOriginalImagesSrc[i] = document.images[g_strImageNames[i]].src;
		}
	}
}

function RestoreOriginalImagesSrc(p_strLayerName)
{
	if(!ie4 && !ns6 && p_strLayerName != '')
	{
		for(i = 0; i < g_strImageNames.length; i++)
		{
			document.layers[p_strLayerName].document.images[g_strImageNames[i]].src = g_strOriginalImagesSrc[i];
		}
	}
	else
	{
		for(i = 0; i < g_strImageNames.length; i++)
		{
			document.images[g_strImageNames[i]].src = g_strOriginalImagesSrc[i];
			//if(i == 0 || i == 1) alert(i + ", store: " + g_strOriginalImagesSrc[i]);
		}
	}
}

function ChangeImage(p_strLayerName, p_strImageName, p_strFile)
{
	if(!ie4 && !ns6 && p_strLayerName != '')
	{
		document.layers[p_strLayerName].document.images[p_strImageName].src = p_strFile;
	}
	else
	{
		document.images[p_strImageName].src = p_strFile;
	}
}

var g_bBILogoState = false;

function ShowAllOff(p_strLayerName)
{
	if(g_bBILogoState == false)
	{
		ChangeImage(p_strLayerName, 'square_about', '../images/common/square_off.gif');
		ChangeImage(p_strLayerName, 'btn_about', '../images/common/btn_about_off.gif');
		
		ChangeImage(p_strLayerName, 'square_solutions', '../images/common/square_off.gif');
		ChangeImage(p_strLayerName, 'btn_solutions', '../images/common/btn_solutions_off.gif');
		
		ChangeImage(p_strLayerName, 'square_approach', '../images/common/square_off.gif');
		ChangeImage(p_strLayerName, 'btn_approach', '../images/common/btn_approach_off.gif');
	
		ChangeImage(p_strLayerName, 'square_skills', '../images/common/square_off.gif');
		ChangeImage(p_strLayerName, 'btn_skills', '../images/common/btn_skills_off.gif');
		
		ChangeImage(p_strLayerName, 'square_clients', '../images/common/square_off.gif');
		ChangeImage(p_strLayerName, 'btn_clients', '../images/common/btn_clients_off.gif');
		
		ChangeImage(p_strLayerName, 'square_partners', '../images/common/square_off.gif');
		ChangeImage(p_strLayerName, 'btn_partners', '../images/common/btn_partners_off.gif');
		
		g_bBILogoState = true;
	}
}

function RestoreAll(p_strLayerName)
{
	if(g_bBILogoState == true)
	{
		RestoreOriginalImagesSrc(p_strLayerName);
		g_bBILogoState = false;
	}
}

//Layer
window.onerror = null;
var topMargin = 0;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);

function layerObject(id,left) {
	if (ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		return this.obj;
	}
	else if(ie4) {
		this.obj = document.all[id].style;
		this.obj.left = left;
		return this.obj;
	}
	else if(ns4) {
		this.obj = document.layers[id];
		this.obj.left = left;
		return this.obj;
   }
}

function layerSetup() {
	floatLyr = new layerObject('floatLayer', pageWidth * .0);
	floatLyr2 = new layerObject('floatLayer2', 0);
	window.setInterval("main()", 10);
}

function floatObject() {
	if (ns4 || ns6) {
		findHt = window.innerHeight;
	} else if(ie4) {
		findHt = document.body.clientHeight;
   }
}

function main() {
	if (ns4) {
		this.currentY = document.layers["floatLayer"].top;
		this.scrollTop = window.pageYOffset;
		mainTrigger();
	}
	else if(ns6) {
		this.currentY = parseInt(document.getElementById('floatLayer').style.top);
		this.scrollTop = scrollY;
		mainTrigger();
	} else if(ie4) {
		this.currentY = floatLayer.style.pixelTop;
		this.scrollTop = document.body.scrollTop;
		mainTrigger();
   }
}

function mainTrigger() {
	var newTargetY = this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
	animator();
   }
}

function floatStart() {
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt) {
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}
	else {
		this.D = this.currentY;
   }
}

function animator() {
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
		if(ie4)
		{
			//if(newY < scrollHeight)
			//{
				document.all.floatLayer.style.pixelTop = newY;
				document.all.floatLayer2.style.pixelTop = newY;
			//}
		}
		
		if(ns4)
		{
			document.layers["floatLayer"].top = newY;
			document.layers["floatLayer2"].top = newY;
		}
		
		if(ns6)
		{
			document.getElementById('floatLayer').style.top = newY + "px";
			document.getElementById('floatLayer2').style.top = newY + "px";
		}
   }
}

function start() {
	if(ns6||ns4) {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup();
		floatObject();
	}
	else if(ie4) {
		scrollHeight = document.body.scrollHeight - 540;
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		layerSetup();
		floatObject();
   }
}

// random
var theImages = new Array();

theImages[0] = '../images/random/pic0.jpg';
theImages[1] = '../images/random/pic1.jpg';
theImages[2] = '../images/random/pic2.jpg';
theImages[3] = '../images/random/pic3.jpg';
theImages[4] = '../images/random/pic4.jpg';
theImages[5] = '../images/random/pic5.jpg';
theImages[6] = '../images/random/pic6.jpg';
theImages[7] = '../images/random/pic7.jpg';
theImages[8] = '../images/random/pic8.jpg';
theImages[9] = '../images/random/pic9.jpg';

var whichImage = Math.round(Math.random() * (theImages.length - 1));

function ShowRandomImage()
{
	document.write("<img src=\'" + theImages[whichImage] + "\'>");
}

