/* TRACER */
traceEnabled = false;
trace = function(a) {
	if (traceEnabled) {
		$('tracer').style.display = 'block';
		$('tracer').innerHTML += a.toString()+'<br />';
		$('tracer').scrollTop = 100000;
	}
};
clearTrace = function () {
	if (traceEnabled) {
		$('tracer').innerHTML = '';
		$('tracer').scrollTop = 100000;
		$('tracer').style.display = 'none';
	}
};
/* Funções diversas */
var isIE =(/\bmsie\b/i.test(navigator.userAgent)&& document.all&&!(/\bopera\b/i.test(navigator.userAgent)));
$ = function (a) {
	return document.getElementById(a);
};

var lastError = null;
	onerror = function(e,f,l) {
return true;
};

// Retorna um Ponto
_point = function (_x, _y) {
	_x = _x || 0;
	_y = _y || 0;
	return {x:_x, y:_y};
};
// Aplica um valor alpha de 0 a 100
setAlpha = function (e, a) {
	a = Math.round(a);
	if (typeof e == 'string') e = $(e);
	with (e.style) {
		if (isIE) {
			filter = 'alpha(opacity='+a+')';
		} else {
			opacity = a/100;
		}
	}
};
// Aplica a posição x e y a um objeto
setPosition = function (obj, x, y) {
	with (obj.style) {
		top = x+'px';
		left = y+'px';
	}
};
// Retorna a posição de um objeto
getPos = function (e) {
	if (typeof e == 'string') e = $(e);
	var left = 0;
	var top = 0;
	while (e.offsetParent) {
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	left += e.offsetLeft;
	top += e.offsetTop;
	return {x:left, y:top};
};
// Retorna o tamanho de um objeto
getSize = function (e) {
	if (typeof e == 'string') e = $(e);
	return {x:e.offsetWidth, y:e.offsetHeight};
};

// Retorna o scroll da página
getScroll = function () {
	if (self.pageXOffset) {
		sX = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft) {
		sX = document.documentElement.scrollLeft;
	} else if (document.body) {
		sX = document.body.scrollLeft;
	}
	if (self.pageYOffset) {
		sY = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		sY = document.documentElement.scrollTop;
	} else if (document.body) {
		sY = document.body.scrollTop;
	}
	return {x:sX, y:sY};
};
// Retorna a posição do mouse no documento
getMousePos = function (ev) {
	if (ev.pageX || ev.pageY) return {x:ev.pageX, y:ev.pageY};
	var SC = getScroll();
	return {x:ev.clientX+SC.x-document.body.clientLeft, y:ev.clientY+SC.y-document.body.clientTop};
};

// Faz um preloader de imagem
imgPreLoad = function (img, fn, a) {
	fn = fn || function () {};
	a = a || null;
	var i = new Image();
	i.onload = function() {
		fn(true, this.src, a);
	};
	
	i.src = img;
};

// Outros
setAllEvents = function () {
	// Seta os eventos privados da página
	setPageEvents();
};

/* Moldura da imagem */
var imgAtual = null;
var ptInicio = new _point();
var ptFinal = new _point();
var molduraAtiva = null;
playMoldura = function (o) {
	if (imgAtual != o && molduraAtiva) {
		imgAtual = o;
		var p = getPos(o);
		var s = getSize(o);
		setAlpha('molduraImagem', 10);
		s.x++;
		ptInicio = p;
		ptFinal.x = p.x+s.x;
		ptFinal.y = p.y+s.y;
		with ($('molduraImagem').style) {
			top = p.y+'px';
			left = p.x+'px';
			height = s.y+'px';
			width = s.x+'px';
			display = 'block';
		}
		$('molduraImagem').alphaTo(10, 30, 'linear', 0.2);
	}
};
stopMoldura = function (e) {
	var m = getMousePos(e);
	if (m.x<ptInicio.x || m.y<ptInicio.y || m.x>ptFinal.x || m.y>ptFinal.y) {
		$('molduraImagem').stopAlpha();
		setAlpha('molduraImagem', 0);
		with ($('molduraImagem').style) {
			top = '0px';
			left = '0px';
			display = 'none';
		}
		imgAtual = null;
		ptInicio = new _point();
		ptFinal = new _point();
	}
};
clickMoldura = function () {
	if (imgAtual) if (imgAtual.onclick) imgAtual.onclick();
};


/* Preloader das imagens */
functionLoader = function() {};
var posImgPL = -1;
loadNextImage = function () {
	if (++posImgPL<arrImgPL.length) {
		var arrSplit = arrImgPL[posImgPL].split('|');
		new imgPreLoad(arrSplit[1], function (e, _img, a) {
			if (e) {
				new alpha(a);
				setAlpha(a, 0);
				$(a).src = _img;
				$(a).alphaTo(0, 100, 'linear', 0.15, function () {
					loadNextImage();
				});
			} else {
				loadNextImage();
			}
		}, arrSplit[0]);
	} else {
		functionLoader();
	}
};







/* AJAX */
var requisicoes = new Number(0);
var XMLVersion = '';
xmlConnection = function () {
	var strNav = new String('');
	var objAjax = null;
	var strMethod = new String('');
	strMethod = 'POST';
	var strParams = new String('');
	var strURL = new String('');
	var strChildName = new String('');
	var arrParamName = new Array();
	var arrParamValue = new Array();
	var numTotalParams = new Number(0);
	var xmlReturn = null;
	var textReturn = new String('');
	var thisObj = this;
	this.onComplete = function() {
	};
	this.onLoad = function() {
	};
	this.onStateChange = function() {
	};
	
	this.add = function() {
		arrParamName[numTotalParams] = arguments[0];
		arrParamValue[numTotalParams] = arguments[1];
		numTotalParams++;
	};
	this.emptyParameters = function() {
		numTotalParams = new Number(0);
		arrParamName = new Array();
		arrParamValue = new Array();
	};
	this.setURL = function() {
		strURL = arguments[0];
	};
	this.setMethod = function() {
		if ((arguments[0].toUpperCase() == 'POST') || (arguments[0].toUpperCase() == 'GET')) {
			strMethod = arguments[0].toUpperCase();
		}
	};
	this.setChildName = function() {
		strChildName = arguments[0];
	};
	this.getStatus = function() {
		return objAjax.statusText;
	};
	this.getXML = function() {
		return xmlReturn;
	};
	this.getText = function() {
		return textReturn;
	};
	this.getCountItens = function() {
		return xmlReturn.getElementsByTagName(strChildName).length;
	};
	this.getAttByName = function() {
		try {
			return xmlReturn.getElementsByTagName(strChildName)[arguments[1]].getAttribute(arguments[0]);
		} catch (e) {
			return null;
		}
	};
	this.getDataByName = function() {
		try {
			return xmlReturn.getElementsByTagName(strChildName)[arguments[0]].firstChild.data;
		} catch (e) {
			return null;
		}
	};
	this.execute = function() {
		if (requisicoes++ == 0) {
			//
		}
		strParams = '';
		for (var i = 0; i<arrParamName.length; i++) {
			if (i>0) {
				strParams += '&';
			}
			strParams += arrParamName[i]+'='+encodeURIComponent(arrParamValue[i]);
		}
		if (strMethod == 'GET') {
			objAjax.open(strMethod, strURL+'?'+strParams, true);
		} else {
			objAjax.open(strMethod, strURL, true);
		}
		with (objAjax) {
			setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			setRequestHeader("CharSet", "UTF-8");
			setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			setRequestHeader("Pragma", "no-cache");
			onreadystatechange = function () {
				thisObj.onStateChange(objAjax.readyState);
				if (objAjax.readyState == 4) {
					thisObj.onLoad(objAjax.status);
					if (objAjax.status == 200) {
						xmlReturn = objAjax.responseXML;
						textReturn = objAjax.responseText;
						thisObj.onComplete();
					} else {
						thisObj.onError(objAjax.status, objAjax.statusText);
					}
					if (--requisicoes == 0) {
						//
					}
				}
			};
			if (strMethod == 'GET') {
				send(null);
			} else {
				send(strParams);
			}
		}
	};
	this.create = function() {
		if (window.ActiveXObject) {
			strNav = 'ie';
			if (XMLVersion == '') {
				var AXO = ['Msxml2.XMLHTTP.8.0','Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP.2.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP'];
				for (var i = 0; i < AXO.length; i++) {
					try {
						objAjax = new ActiveXObject(AXO[i]);
						XMLVersion = AXO[i];
						break;
					} catch (e) {
						continue;
					}
					if (i >= (AXO.length-1)) {
						objAjax = null;
						return;
					}
				};
			} else {
				try {
					objAjax = new ActiveXObject(XMLVersion);
				} catch (e) {
					objAjax = null;
					return;
				}
			}
		} else if (window.XMLHttpRequest) {
			XMLVersion = 'XMLHttpRequest';
			objAjax = new XMLHttpRequest();
			strNav = 'ff';
		} else {
			objAjax = null;
			return;
		}
		return true;
	};
};

/* Tween */
tween = function () {
	var obj = $(arguments[0]);
	obj.numStepTween = (isIE) ? 10 : 10;
	obj.thisIntervalTween = null;
	obj.posXTween = 100;
	obj.posYTween = 100;
	obj.onEnterFrameTween = function() {
		obj.numTimeTween += obj.numStepTween;
		var posX = findTweenValue(obj.numInicioXTween, obj.numFinalXTween, 0, obj.numTimeTween, obj.numDurationTween, obj.strEasingTween);
		var posY = findTweenValue(obj.numInicioYTween, obj.numFinalYTween, 0, obj.numTimeTween, obj.numDurationTween, obj.strEasingTween);
		setPosition(obj, posX, posY);
		if (obj.numTimeTween>=obj.numDurationTween) {
			setPosition(obj, obj.numFinalXTween, obj.numFinalYTween);
			clearInterval(obj.thisIntervalTween);
			obj.callbackTween();
		}
	};
	obj.tweenTo = function() {
		var pos = getPos(obj);
		this.numTimeTween = 0;
		this.numInicioXTween = pos.y;
		this.numInicioYTween = pos.x;
		this.numFinalXTween = arguments[0];
		this.numFinalYTween = arguments[1];
		this.strEasingTween = (arguments[2]) ? arguments[2] : 'linear';
		this.numDurationTween = (arguments[3]) ? arguments[3]*1000 : 1000;
		this.callbackTween = arguments[4] || function () {
		};
		clearInterval(obj.thisIntervalTween);
		obj.thisIntervalTween = setInterval(obj.onEnterFrameTween, obj.numStepTween);
	};
	obj.stopTween = function() {
		clearInterval(obj.thisIntervalTween);
	};
};
/* Shake */
shake = function () {
	var obj = $(arguments[0]);
	var dist = 4;
	var moving = false;
	obj.numStepShake = 25;
	obj.thisIntervalShake = null;
	obj.onEnterFrameShake = function() {
		obj.numTimeShake += obj.numStepShake;
		var posX = Math.round((Math.random()*dist*2-dist)+obj.numInicioXShake);
		var posY = Math.round((Math.random()*dist*2-dist)+obj.numInicioYShake);
		setPosition(obj, posX, posY);
		if (obj.numTimeShake>=obj.numDurationShake) {
			setPosition(obj, obj.numInicioXShake, obj.numInicioYShake);
			clearInterval(obj.thisIntervalShake);
			obj.callbackShake();
			moving = false;
		}
	};
	obj.shakeNow = function() {
		if (moving == true) {
			obj.stopShake();
		}
		var pos = getPos(obj);
		this.numTimeShake = 0;
		this.numInicioXShake = pos.y;
		this.numInicioYShake = pos.x;
		this.numDurationShake = (arguments[0]) ? arguments[0]*1000 : 1000;
		this.callbackShake = arguments[1] || function () {
		};
		obj.thisIntervalShake = setInterval(obj.onEnterFrameShake, obj.numStepShake);
		moving = true;
	};
	obj.stopShake = function() {
		clearInterval(obj.thisIntervalShake);
		setPosition(obj, obj.numInicioXShake, obj.numInicioYShake);
	};
};
/* Alpha */
alpha = function () {
	var obj = $(arguments[0]);
	obj.numStepAlpha = (isIE) ? 45 : 40;
	obj.thisIntervalAlpha = null;
	obj.onEnterFrameAlpha = function() {
		obj.numTimeAlpha += obj.numStepAlpha;
		var newAlpha = findTweenValue(obj.numInicioAlpha, obj.numFinalAlpha, 0, obj.numTimeAlpha, obj.numDurationAlpha, obj.strEasingAlpha);
		setAlpha(obj, newAlpha);
		if (obj.numTimeAlpha>=obj.numDurationAlpha) {
			setAlpha(obj, obj.numFinalAlpha);
			clearInterval(obj.thisIntervalAlpha);
			obj.callbackAlpha();
		}
	};
	obj.alphaTo = function() {
		this.numTimeAlpha = 0;
		this.numInicioAlpha = arguments[0];
		this.numFinalAlpha = arguments[1];
		this.strEasingAlpha = (arguments[2]) ? arguments[2] : 'linear';
		this.numDurationAlpha = (arguments[3]) ? arguments[3]*1000 : 1000;
		this.callbackAlpha = arguments[4] || function () {
		};
		clearInterval(obj.thisIntervalAlpha);
		obj.thisIntervalAlpha = setInterval(obj.onEnterFrameAlpha, obj.numStepAlpha);
	};
	obj.stopAlpha = function() {
		clearInterval(obj.thisIntervalAlpha);
	};
};

/* Função de easing */
findTweenValue = function (PS, PD, TS, TN, TD, AT, E1, E2) {
	var t = TN-TS, b = PS, c = PD-PS, d = TD-TS, a = E1, p = E2, s = E1;
	switch (AT.toLowerCase()) {
	case "linear" :
		return c*t/d+b;
	case "easeinexpo" :
		return (t == 0) ? b : c*Math.pow(2, 10*(t/d-1))+b;
	case "easeoutexpo" :
		return (t == d) ? b+c : c*(-Math.pow(2, -10*t/d)+1)+b;
	case "easeoutelastic" :
		if (t == 0) {
			return b;
		}
		if ((t /= d) == 1) {
			return b+c;
		}
		if (!p) {
			p = d*.3;
		}
		if (!a || a<Math.abs(c)) {
			a = c;
			var s = p/4;
		} else {
			var s = p/(2*Math.PI)*Math.asin(c/a);
		}
		return (a*Math.pow(2, -10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b);
	}
};

// indexxxxxxxx  

// Funções da página
setPageEvents = function () {

};

window.onload = function() {
	// Seta os eventos
	setAllEvents();
	// Inicia o preloader das imagens
	loadNextImage();
	// ALPHA
	new alpha('molduraImagem');
	new alpha('fundoBranco');
	// Cria o evento da moldura
	document.onmousemove = function(e) {
		e = e || event;
		stopMoldura(e);
	};
	molduraAtiva = true;
	// Inicia o preloader das imagens
	loadSiteImages();
	
	if (primeiraVez == '1') {
		SA.onClose = function() {
			SA.onClose = function() {};
		};
	}
};

