


/*MAIN*/



/* * *
	BACKGROUND IMAGE CACHE
* * */
Try.these(function(){
	document.execCommand("BackgroundImageCache", false, true);
});

/* * *
	EXTEND PROTOTYPE 
* * */
Function.prototype.delay = function(){
    var __method = this, args = $A(arguments), timeout = args.shift();
    return window.setTimeout(function(){
      return __method.apply(__method, args);
    }, timeout);
}
Array.prototype.uniq = function(){
	return this.inject([], function(array, value, index){
		if(!index || !array.include(value))
			array.push(value);
		return array;
	});
}
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element, w){
    	$(element).style.width = w +"px";
	},
	setHeight: function(element, h){
    	$(element).style.height = h +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	},
	showBlock: function(element){
    	$(element).style.display = 'block';
	}
});

/* * *
	BACK BUTTON
* * */
var backButton = Object();
backButton = {
	init: function(){
		ContentLoaded(window, function(){
			if($('iBack'))
				Event.observe($('iBack'), 'click', backButton.click.bindAsEventListener(this));
		});
	},
	click: function(event){
		Event.stop(event);
		history.back();
	}
}

/* * * 
	IE HOVER
* * */
var IEHover = {
	onId:function(load, id){
		IEHover._on(function(){
			return [$(id)];
		}, load);
	},
	onTagName:function(load, tagName, self){
		IEHover._on(function(){
			return $(self || document).getElementsByTagName(tagName);
		}, load);
	},
	_on:function(getFunc, load){
		var func = function(){
			$A(getFunc()).each(function(element){
				Event.observe(element, 'mouseover', IEHover.over.bind(element));
				Event.observe(element, 'mouseout', IEHover.out.bind(element));
			});
		}
		
		if(load)
			ContentLoaded(window, func);
		else
			func();
	},
	
	over:function(){
		Element.addClassName(this, IEHover.hoverClass(this));
	},
	
	out:function(){
		Element.removeClassName(this, IEHover.hoverClass(this));
	},
	
	hoverClass:function(element){
		if(!element.className || element.className == 'hover')
			return 'hover';
		else
			return element.className.split(/\s+/)[0]+'Hover';
	}
}

/* * *
	EMAIL
* * */
var email = {
	decode: function(str){
		str = str.replace(/( \[arroba\] )/g, '@');
		str = str.replace(/( \[ponto\] )/g, '.');
		return str;
	}
}

/* * *
	GET PAGE SCROLL
* * */
function getPageScroll(){
	var xScroll, yScroll;
	if(self.pageYOffset){
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}else if(document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}else if(document.body){// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	return [xScroll, yScroll];
}


/* * *
	GET PAGE SIZE
* * */
function getPageSize(){
	var xScroll, yScroll;
	
	if(window.innerHeight && window.scrollMaxY){	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if(self.innerHeight){	// all except Explorer
		if(document.documentElement.clientWidth)
			windowWidth = document.documentElement.clientWidth; 
		else
			windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body){ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	var pageWidth, pageHeight;
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
		pageHeight = windowHeight;
	else
		pageHeight = yScroll;

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
		pageWidth = xScroll;		
	else
		pageWidth = windowWidth;

	return [pageWidth, pageHeight, windowWidth, windowHeight];
}

/* * *
	SELECT BOXES
* * */
function SelectBoxes(v){
	v = v ? 'visible' : 'hidden';
	$A(document.getElementsByTagName("select")).each(function(select){
		select.style.visibility = v;																												
	});
}

/* * *
	CONTENT LOADED
* * */
function ContentLoaded(w, fn){
	var d = w.document, u = w.navigator.userAgent.toLowerCase();

	function init(e){
		if (!arguments.callee.done) {
			arguments.callee.done = true;
			fn(e);
		}
	}

	// konqueror/safari
	if (/khtml|webkit/.test(u)) {

		(function () {
			if (/complete|loaded/.test(d.readyState)) {
				init('poll');
			} else {
				setTimeout(arguments.callee, 10);
			}
		})();

	// internet explorer all versions
	} else if (/msie/.test(u) && !w.opera) {

		(function () {
			try {
				d.documentElement.doScroll('left');
			} catch (e) {
				setTimeout(arguments.callee, 10);
				return;
			}
			init('poll');
		})();
		d.attachEvent('onreadystatechange',
			function (e) {
				if (d.readyState == 'complete') {
					d.detachEvent('on'+e.type, arguments.callee);
					init(e.type);
				}
			}
		);

	// browsers having native DOMContentLoaded
	} else if (d.addEventListener &&
		(/gecko/.test(u) && parseFloat(u.split('rv:')[1]) >= 1.8) ||
		(/opera/.test(u) && parseFloat(u.split('opera ')[1]) > 9)) {

		d.addEventListener('DOMContentLoaded',
			function (e) {
				this.removeEventListener(e.type, arguments.callee, false);
				init(e.type);
			}, false
		);

	// fallback to last resort
	} else {

		// from Simon Willison
		var oldonload = w.onload;
		w.onload = function (e) {
			if (typeof oldonload == 'function') {
				oldonload(e || w.event);
			}
			init((e || w.event).type);
		};

	}
}


/* * *
	EVENT
* * */
Object.extend(Event, {
	dispatch: function(target){
		target = $(target);
		var event;
		if(document.createEvent){ // gecko, safari 
			if(/Konqueror|Safari|KHTML/.test( navigator.userAgent )){
				event = document.createEvent('HTMLEvents');
				event.initEvent('click', true, true);
			}else{ // gecko uses MouseEvents  
				event = document.createEvent('MouseEvents');
				event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null ); 
			}
		}else{ // msie
			event = document.createEventObject();
		} 

		if(document.createEvent)
			target.dispatchEvent(event); 
		else  
			target.fireEvent('onclick', event);
	} 
});

/*-----------------------------------------------------------------------------------------------*/

backButton.init();
IEHover.onTagName(true, 'li', 'm');
IEHover.onTagName(true, 'button');



/*SWFOBJECT*/



/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	
	/* ADD */
	this.addParam('wmode', 'transparent');
	this.addParam('scale', 'noscale');
	/* END - ADD */

	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');	
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;




/*LIGHTBOX*/



var LightboxOptions = {
	overlayOpacity: 0.8,
	resizeSpeed: 7,
	borderSize: 5
};
Object.extend(Element, {
	getRelJS: function(link){
		if(link.getAttribute('rel')){
			var m = link.getAttribute('rel').match(/:([^\[\(]+)/im);
			if(m) return m[1];
		}
	},
	getRelGalery: function(link){
		if(link.getAttribute('rel')){
			var m = link.getAttribute('rel').match(/\[[^\]]+\]/im);
			if(m) return m[0];
		}
	},
	getRelDimensions: function(link){
		if(link.getAttribute('rel')){
			var m = link.getAttribute('rel').match(/\((.*?),(.*?)\)/im);
			if(m) return {w:parseInt(m[1]), h:parseInt(m[2])};	
		}
	}
});

// -----------------------------------------------------------------------------------

var Lightbox = Class.create();

Lightbox.prototype = {
	array: [],
	js: undefined,
	image_array: [], // construído a cada start
	image_current: undefined,
	
	initialize: function(){	
		this.resizeDuration = (11 - LightboxOptions.resizeSpeed) * 0.15;
		this.overlayDuration = 0.2;
		// list
		$A(document.getElementsByTagName('a')).each(function(a){
			var rel = String(a.getAttribute('rel'));
			if(a.getAttribute('href') && rel.toLowerCase().match('lightbox')){
				Event.observe(a, 'click', (function(event){Event.stop(event); this.start(a);}).bindAsEventListener(this));
				this.array.push(a);
			}
		}.bind(this));

		//	<div id="overlay" style="display:none"></div>
		//	<div id="lightbox">
		//		<div id="lightbox_close">
		//			<a href="#" id="iClose" class="icon"></a>
		//		</div>
		//		<div id="lightbox_content">
		//			<div id="lightbox_image">
		//				<img id="lightbox_img">
		//			</div>
		//			<div id="lightbox_loading">
		//				<img src="images/loading.gif">
		//			</div>
		//		</div>
		//		<div id="lightbox_data">
		//			<div class="caption"></div>
		//			<div class="pagination">
		//				<a href="#" id="prevLink" class="iPrev icon"></a>
		//				<a href="#" id="nextLink" class="iNext icon"></a>
		//			</div>
		//		</div>
		//	</div>
		var objBody = document.getElementsByTagName("body")[0];
		objBody.appendChild(Builder.node('div', {id:'overlay'}));
    objBody.appendChild(Builder.node('div', {id:'lightbox'}, [
			Builder.node('div', {id:'lightbox_close'}, [
				Builder.node('a', {href:'#', id:'lightbox_iClose', className:'icon iClose'})																 
			]),
			Builder.node('div', {id:'lightbox_content'}, [
				Builder.node('div', {id:'lightbox_image'}, [
					Builder.node('img', {id:'lightbox_img'})	
				]),
				Builder.node('div', {id:'lightbox_loading'}, [
					Builder.node('img', {src:'images/loading.gif'})
				])
			]),
			Builder.node('div', {id:'lightbox_data'}, [
				Builder.node('div', {className:'caption'}),
				Builder.node('div', {className:'pagination'}, [
					Builder.node('a', {href:'#', id:'lightbox_prev', className:'iPrev icon'}),
					Builder.node('a', {href:'#', id:'lightbox_next', className:'iNext icon'})
				])
			])
		]));

		Element.hide('overlay');			
		Event.observe('overlay', 'click', (function(event){Event.stop(event); this.end();}).bindAsEventListener(this));						
		Element.hide('lightbox');			
		Event.observe('lightbox', 'click', (function(event){
			var e = Event.element(event);
			if(e.id == 'lightbox' || Element.hasClassName(e, 'iClose')){
				Event.stop(event);
				this.end()
			}
		}).bindAsEventListener(this));						
		// usado apenas com image
		Event.observe('lightbox_prev', 'click', (function(event){this.image_change_nav(event, -1)}).bindAsEventListener(this));
		Event.observe('lightbox_next', 'click', (function(event){this.image_change_nav(event, +1)}).bindAsEventListener(this));
	},

	/* * *
		START
	* * */
	start: function(link){
		SelectBoxes(false);
		
		Element.setStyle('lightbox_content', {width:'100px', height:'100px'});
		
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		Element.setStyle('overlay', {width:arrayPageSize[0]+'px', height:arrayPageSize[1]+'px'});
		Element.setStyle('lightbox', {top:(arrayPageScroll[1] + ((arrayPageSize[3]-50) / 2))+'px', left:arrayPageScroll[0]+'px'});
		Element.hide('lightbox_loading');

		new Effect.Appear('overlay', {duration:this.overlayDuration, from: 0.0, to: LightboxOptions.overlayOpacity});

		this.js = eval(Element.getRelJS(link));
		if(this.js){ // js
			this.js_change(Element.getRelDimensions(link));
		}else{ // image
			this.image_array = [];
			this.image_current = 0;
			var galery = Element.getRelGalery(link);
			if(!galery){
				this.image_array.push([link.getAttribute('href'), link.getAttribute('title'), Element.getRelDimensions(link)]);
			}else{
				this.image_array = this.array.inject([], function(array, a, index){
					if(a.getAttribute('href') == link.getAttribute('href'))
						this.image_current = index;
					if(a.getAttribute('href') && Element.getRelGalery(a) == galery)
						array.push([a.getAttribute('href'), a.getAttribute('title'), Element.getRelDimensions(a)]);
					return array;
				}).uniq();
				
				while(this.image_array[this.image_current][0] != link.getAttribute('href'))
					this.image_current++;
			}
			this.image_change();
		}
	},
	
	/* * *
		RESIZE CONTAINER
	* * */
	resizeContainer: function(wNew, hNew, animate){
		var wCurrent = Element.getWidth('lightbox_content');
		var hCurrent = Element.getHeight('lightbox_content');

		wDiff = wCurrent - wNew;
		hDiff = hCurrent - hNew;
		var xScale = (wNew / wCurrent) * 100;
		var yScale = (hNew / hCurrent) * 100;

		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3]-hNew) / 2); // 16 metade do loading

		Element.setWidth('lightbox_close', wNew);
		Element.setWidth('lightbox_data', wNew);

		if(animate){
			if(hDiff) new Effect.Scale('lightbox_content', yScale, {scaleX: false, duration: this.resizeDuration, queue: 'front'});
			if(wDiff) new Effect.Scale('lightbox_content', xScale, {scaleY: false, delay: this.resizeDuration, duration: this.resizeDuration});
			new Effect.Move('lightbox', {y:lightboxTop - 20 - parseFloat(Element.getStyle('lightbox' ,'top')), duration:this.resizeDuration});
		}else{
			Element.setStyle('lightbox', {top:lightboxTop+'px'});
			Element.setStyle('lightbox_content', {width:wNew+'px', height:hNew+'px'});
			new Effect.Appear('lightbox', {duration:this.resizeDuration});
		}
		
		var t = 0;
		if(!hDiff && !wDiff) // se não mudar dimensoes
			t = (window.attachEvent && !window.opera) ? 250 : 100; // if IE 250
		return t;
	},
	
	/* * *
		CHANGE
	* * */
	_change: function(){
		Element.hide('lightbox_close');
		Element.hide('lightbox_img');
		Element.hide('lightbox_prev');
		Element.hide('lightbox_next');
		Element.hide('lightbox_data');
	},
	// JS
	js_change: function(dimensions){
		Element.hide('lightbox_image');
		this._change();
		
		this.resizeContainer(dimensions.w, dimensions.h, false);
		this.js.initialize.call(this.js);
	},
	// IMAGE
	image_change: function(){
		Element.show('lightbox');
		Element.show('lightbox_loading');
		this._change();

		var imgPreloader = new Image();
		imgPreloader.onload = function(){
			var img = this.image_array[this.image_current];
			Element.setSrc('lightbox_img', img[0]);
			
			var w = [imgPreloader.width], h = [imgPreloader.height];
			if(img[2]){
				w.push(img[2].w);
				h.push(img[2].h);
			}
			var t = this.resizeContainer(
				w.max() + LightboxOptions.borderSize * 2, 
				h.max() + LightboxOptions.borderSize * 2, 
				true
			);
			(function(){	
				Element.show('lightbox_image');
				Element.hide('lightbox_loading');
				
				new Effect.Appear('lightbox_img', {
					duration: this.resizeDuration,
					queue: 'end', 
					afterFinish: function(){
						this.image_details();
					}.bind(this)
				});
				this.image_preload();
			}).bind(this).delay(t);
		}.bind(this);
		imgPreloader.src = this.image_array[this.image_current][0];
	},
	image_change_nav: function(event, num){
		Event.stop(event); 
		this.image_current = this.image_current + num;
		Element.setStyle('lightbox', {top: parseFloat(Element.getStyle('lightbox','top')) + 36 +'px'});
		this.image_change(); 
	},

	/* * *
		IMAGE DETAILS
	* * */
	image_details: function(){
		// data
		var objCaption = document.getElementsByClassName('caption', $('lightbox_data'))[0];
		Element.setInnerHTML(objCaption, this.image_array[this.image_current][1]);
		new Effect.BlindDown('lightbox_data', {
			duration:this.resizeDuration,
			afterFinish: function() {
				var arrayPageSize = getPageSize();
				Element.setHeight('overlay', arrayPageSize[1]);
			}
		});
		// close
		new Effect.Parallel([
				new Effect.Move('lightbox', {sync: true, y:-36, duration:this.resizeDuration}),
				new Effect.BlindDown('lightbox_close', {sync: true, duration:this.resizeDuration})
			], { 
				duration:this.resizeDuration
			} 
		);
		// pagination
		if(this.image_current) Element.show('lightbox_prev');
		if(this.image_current != (this.image_array.length - 1)) Element.show('lightbox_next');
	},

	/* * *
		IMAGE PRELOAD
	* * */
	image_preload: function(){
		var preloadNextImage, preloadPrevImage;
		if(this.image_array.length > this.image_current + 1){
			preloadNextImage = new Image();
			preloadNextImage.src = this.image_array[this.image_current + 1][0];
		}
		if(this.image_current > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = this.image_array[this.image_current - 1][0];
		}
	},

	/* * *
		END
	* * */
	end: function(){
		Effect.Queue.each(function(effect){
			Effect.Queue.remove(effect);
		});
		if(this.js){ // js
			this.js.end();
		}else{ // image
			Element.setStyle('lightbox_close', {height: 'auto'});
			Element.setStyle('lightbox_data', {height: 'auto'});
		}
		Element.hide('lightbox');
		new Effect.Fade('overlay', {duration: this.overlayDuration});
		SelectBoxes(true);
	}
}

// ---------------------------------------------------

ContentLoaded(window, function(){
	new Lightbox();											 
});



/*LIGHTBOX_PAGES*/



/* ****************************
	VIRTUAL TOUR
**************************** */
var virtualtour = new Object();
Object.extend(virtualtour, {
	path: 'images/virtualtour/',
	time:.4,
	imgs_width:108,
	imgs_current:undefined,
	array:[
		['01', 'Adega Chesini', 'Vista aérea da Adega Chesini na localidade de Vila Rica, distrito de Farroupilha na serra gaúcha. Clima ideal para o cultivo de uvas de qualidade e elaboração de produtos especiais.'],
		['02', 'Adega Chesini', 'A Adega Chesini integra as "Microchampanharias de Garibaldi" e o roteiro enoturístico Rota das Cantinas também do município de Garibaldi/RS.'],
		['03', 'Varejo Adega Chesini', 'Logo na entrada da vinícola é possível descobrir o varejo da Adega Chesini, montado dentro de uma pipa de madeira que antigamente era utilizada para armazenamento de vinho.'],
		['04', 'Varejo Adega Chesini', 'No varejo, num ambiente tipicamente colonial, o visitante encontra uma ampla varidade de produtos da Adega Chesini.'],
		['05', 'Varejo Adega Chesini', 'Além de poder comprar vinhos e espumantes o visitante é convidado a degustar os produtos da vinícola e ainda encontra produtos artesanais no melhor estilo italiano.'],
		['06', 'Caves de chão batido', 'Já no interior da Adega Chesini é possível conhecer as tradicionais caves de chão batido com paredes de pedra onde os vinhos engarrafados são armazenados.'],
		['07', 'Caves de chão batido', 'Essa forma de armazenamento mantém o vinho em temperatura estável, amadurecendo seu bouquet até adquirir sua complexidade de aromas.'],
		['08', 'Artefatos Coloniais', 'Barris de carvalho e cestas de vime são artefatos facilmente encontrados num passeio pela adega.'],
		['09', 'Passeio entre as pipas', 'Em outro ponto da vinícola descobre-se as pipas de madeira que antigamente eram utilizadas para o armazenamento dos vinhos.'],
		['10', 'Passeio entre as pipas', 'O ambiente tipicamente colonial italiano faz com que o visitante sinta prazer em passear entre os barris e paredes de pedra e sentir os aromas dos produtos da vinícola.'],
		['12', 'Armazenamento dos produtos', 'O passeio continua entre as pipas de inox, atualmente utilizadas para o armazenamento dos vinhos e espumantes da Adega Chesini.'],
		['13', 'Espaço gastronômico', 'Ao final de um passeio destes, nada melhor que se deliciar com uma boa comida italiana e um bom vinho no espaço gastronômico da vinícola.'],
		['14', 'Espaço gastronômico', 'O clima típico da colônia italiana convida você para um almoço ou jantar inesquecíveis. Desde já você está convidado a fazer este passeio pessoalmente. Aguardamos a sua visita!']
	],
	
	/* * *
		INITIALIZE
	* * */
	initialize:function(){
		this.imgs_current = 2;
		
		Element.setStyle('lightbox_content', {background:'transparent'});
		$('lightbox_content').appendChild(Builder.node('div', {id:'virtualtour'}, [
			Builder.node('a', {href:'#', className:'icon iClose'}),
			Builder.node('h2', {id:'virtualtour'}, 'Passeio Virtual'),
			Builder.node('div', {id:'virtualtour_image'}, [
				Builder.node('img', {id:'virtualtour_img', width:'356', height:'212'}),
				Builder.node('div', {id:'virtualtour_loading'}, [
					Builder.node('img', {src:'images/loading.gif'})
				])
			]),
			Builder.node('div', {className:'info'}, [
				Builder.node('h3', {id:'virtualtour_tit'}),
				Builder.node('p', {id:'virtualtour_txt'})
			]),
			Builder.node('div', {className:'clear'}),
			Builder.node('div', {className:'navigation'}, [
				Builder.node('a', {id:'virtualtour_prev', className:'iPrev icon', title:'Imagem anterior'}),
				Builder.node('a', {id:'virtualtour_next', className:'iNext icon', title:'Próxima imagem'}),
				Builder.node('div', {id:'virtualtour_navigation'}, [
					Builder.node('div', {id:'virtualtour_imgs', style:'left:'+(this.imgs_width*3)+'px'})																										 
				])			
			])
		]));
		Element.setWidth($('virtualtour_imgs'), this.array.length*this.imgs_width);
		this.array.each(function(value, index){
			var a = Builder.node('a', {href:'#'}, [
				Builder.node('img', {width:'84', height:'50', src:this.path+value[0]+'pq.jpg'})																
			])
			$('virtualtour_imgs').appendChild(a);
			Event.observe(a, 'click', (function(event){Event.stop(event); this.getImg(index)}).bindAsEventListener(this));
		}.bind(this));
		
		Event.observe('virtualtour_prev', 'click', (function(event){Event.stop(event); this.changeImgs(-1)}).bindAsEventListener(this));
		Event.observe('virtualtour_next', 'click', (function(event){Event.stop(event); this.changeImgs(+1)}).bindAsEventListener(this));
		this.changeImgs(-2);
		this.getImg(0);
	},
	
	/* * *
		GET IMG
	* * */
	getImg:function(num){
		Element.hide('virtualtour_img');
		Element.show('virtualtour_loading');
		
		Element.setInnerHTML('virtualtour_txt', this.array[num][2]);
		Element.setInnerHTML('virtualtour_tit', this.array[num][1]);
		
		var img = this.array[num];
		var preloader = new Image();
		preloader.onload = function(){
			Element.hide('virtualtour_loading');
			$('virtualtour_img').src = preloader.src;
			new Effect.Appear('virtualtour_img', {duration: this.time});
		}.bind(this);
		preloader.src = this.path+img[0]+'gd.jpg'
	},

	/* * *
		CHANGE IMGS
	* * */
	changeImgs:function(num, t){
		this.imgs_current += num;
		if(this.imgs_current <= 0){
			this.imgs_current = 0;
			Element.hide('virtualtour_prev');
		}else{
			Element.show('virtualtour_prev');
		}
		
		if(this.imgs_current >= this.array.length-3){
			this.imgs_current = this.array.length-3;
			Element.hide('virtualtour_next');
		}else{
			Element.show('virtualtour_next');
		}

		new Effect.Move('virtualtour_imgs', {
			duration:this.time,
			mode:'absolute',
			transition:Effect.Transitions.sinoidal,
			x:-(this.imgs_current*this.imgs_width)
		});
	},

	/* * *
		END
	* * */
	end:function(){
		Element.setStyle('lightbox_content', {background:'#FFFFFF'});
		$('lightbox_content').removeChild($('virtualtour'));
	}
});


/* ****************************
	LOCATION MAP
**************************** */
var locationmap = new Object();
Object.extend(locationmap, {
	/* * *
		INITIALIZE
	* * */
	initialize:function(){
		Element.setStyle('lightbox_content', {background:'transparent'});
		$('lightbox_content').appendChild(Builder.node('div', {id:'locationmap'}, [
			Builder.node('a', {href:'#', className:'icon iClose'}),
			Builder.node('div', {id:'locationmapSWF'})
		]));
		
		new SWFObject("swf/location.swf", "locationmapSWF2", "656", "372", "8", "#FFFFFF").write('locationmapSWF');
	},
	
	/* * *
		END
	* * */
	end:function(){
		Element.setStyle('lightbox_content', {background:'#FFFFFF'});
		$('lightbox_content').removeChild($('locationmap'));
	}
});