function setupCufon(setup_translate) {
	setup_translate = $defined(setup_translate)? setup_translate : true;	
	if (setup_translate) {
		//google translate
		if (typeof google != "undefined") {
			$$(".item_news").each( function(el) { 
				dbug.log(el);
				new CCDTranslate(el, {
					langFrom:'pt', 
					langTo: lingua, 
					onTraduziu: function() {												
						Cufon.refresh();	
						
						this.container.getElements(".center_icon").each( function(el) { 
							setupCenterIcon(el);		
						}) ;
						
						if (Shadowbox) {
							var links = this.container.getElements('a[rel=shadowbox]');	
							if (links.length) Shadowbox.setup(links);
						}					
					}
				});		
			});	  
		}
	}
	//Cufon.set('fontFamily', 'KlavikaPlain').replace('#content h2');
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('#container h2', {hover: true});
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('#container h3', {hover: true});
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('#mais_que h2');
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('#painel_servicos ul li a', {hover: true});
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('#emp_col2 dt');
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('h1.sub');	
	Cufon.set('fontFamily', 'HelveticaNeueLtStdLtCn').replace('.item_news .titulo');	
	Cufon.now();
}

var dbug = {
	log: function(str) {
		if (typeof console != "undefined") {
			console.log(str);
		} else {
			//alert(str);
		}		
	}
};
function get_obj_str(obj) {
	var res = "";
	for (var prop in obj) {
		res += prop.toString() + ": "+ obj[prop]+",";
	}
	return "{" + res + "}";
}

/* http://davidwalsh.name/jquery-hover-mootools  */
Element.implement({
	'hover': function(fn1,fn2) {
		return this.addEvents({
			'mouseenter': function(e) {
				fn1.attempt(e,this);
			},
			'mouseleave': function(e) {
				fn2.attempt(e,this);
			}
		})
	}
});

/* http://davidwalsh.name/mootools-dotter */
var Dotter = new Class({
	
	/* implements */
	Implements: [Options,Events],

	/* options */
	options: {
		delay: 1000,
		dot: '.',
		message: 'Loading',
		numDots: 3,
		property: 'text',
		reset: false/*,
		onDot,
		onStart,
		onStop
		*/
	},
	
	/* initialization */
	initialize: function(container,options) {
		/* set options */
		this.setOptions(options);
		this.container = $(container);
		this.dots = 0;
		this.running = false;
	},
	
	/* adds dot */
	dot: function() {
		if(this.running) {
			var text = this.container.get(this.options.property);
			this.dots++;
			this.container.set(this.options.property,(this.dots % this.options.numDots != 0 ? text : this.options.message) + '' + this.options.dot);
		}
		return this;
	},
	
	/* loads or resets the dotter */
	load: function() {
		this.loaded = true;
		this.dots = 0;
		this.dotter = function(){ this.dot(); this.fireEvent('dot'); }.bind(this);
		this.periodical = this.dotter.periodical(this.options.delay);
		this.container.set(this.options.property,this.options.message + '' + this.options.dot);
		return this;
	},
	
	/* start the dotter */
	start: function() {
		if(!this.loaded || this.options.reset) this.load();
		this.running = true;
		this.fireEvent('start');
		return this;
	},
	
	/* stop the dotter */
	stop: function() {
		this.running = this.loaded = false;
		$clear(this.periodical);
		this.fireEvent('stop');
		return this;
	}
});

/*
Script: CCDCenterIcon.js
Shows an icon centered over a container with FX

container usually an <a> tag
container style must be { display: block;  position: relative; }
centerElement usually an <img> tag
ie6 has some issues yet

developed by claudio@castelcd.com.br
*/
var CCDCenterIcon = new Class({
	Implements: [Options],
	options: {
		width: 16,
		height: 16,		
		forceRelative: false,		
		useFX: false,
		fxOpacity: 0.8, //applied when useFx==true
		fxOptions: {
			transition:Fx.Transitions.Sine.easeInOut,
			duration: 500,
			wait: false
		},		
		hoverStyle: {
		    position: 'absolute',
		    zIndex: '1000',
		    opacity: 0.8 //applied when useFx==false
		}
	},
	getAbsolutePosition: function() {
		var imageSize = this.centerElm.getSize();
		return {
			left: Math.round(Math.abs(imageSize.x-this.options.width)/2),
			top: Math.round(Math.abs(imageSize.y-this.options.height)/2) 
		};
	},
	setHoverStyle: function() {
		var pos = this.getAbsolutePosition();
		this.finalHoverStyle = $merge(
			this.options.hoverStyle, 
			{
				left: pos.left + 'px',
				top:  pos.top + 'px',
				width: this.options.width + 'px',
				height: this.options.height + 'px'
			}
		);		
		
		//fix for ie6 positioning bug
		if (Browser.Engine.trident4) {
			var cFloat = this.centerElm.getStyle("float");
			if (cFloat == "left" || cFloat == "right") {
				//this.options.hoverStyle.position = "relative";
				this.finalHoverStyle.marginLeft = "-" + (pos.left + this.options.width) + "px";
				this.finalHoverStyle.left = "0";
			}
		}		
		
		if (this.options.useFX) {
			this.finalHoverStyle.opacity = 0;
		} else {
			this.finalHoverStyle.display = "none";
		}
	},	
	setupHover: function() {
		//get the size again AFTER the image is loaded - for webkit and other browsers
		var event = (Browser.Engine.trident4)? "onload" : "load";
		this.centerElm.addEvent(event, function() { 
			if (this.hoverElm) {
				var pos = this.getAbsolutePosition();
				this.hoverElm.setStyles(pos);
			}
		}.bind(this));	
				
		this.setHoverStyle();
		
		//create the hover element
		this.hoverElm = new Element('span',	{styles: this.finalHoverStyle});
		this.container.grab(this.hoverElm, 'top');
		
		//if (Browser.Engine.trident4) Browser.fixPNG(this.hoverElm);		
		if (this.options.useFX) {
			this.hoverElm.set('morph', this.options.fxOptions);		
		}
		
		//hover
		this.container.hover(function(e) {
			dbug.log("hover in");
			if (this.options.useFX) {
				this.hoverElm.morph({'opacity': [0, this.options.fxOpacity]});				
			} else {
				this.hoverElm.setStyle("display", "block");
			}
		}.bind(this), function(e) {
			dbug.log("hover out");
			if (this.options.useFX) {
				this.hoverElm.morph({'opacity': [this.options.fxOpacity, 0]});				
			} else {
				this.hoverElm.setStyle("display", "none");
			}
		}.bind(this));	
	},
	initialize: function(container, options){
		dbug.log("CCDCenterIcon initialize");
		this.container = $(container);		
		this.centerElm = this.container.getFirst();
		
		this.setOptions(options);
		
		if (this.options.forceRelative) {
			//set the container to { display: block;  position: relative; }
			this.container.setStyles({ 
					display: 'block',  
					position: 'relative'
			});		
		}
		this.setupHover();	
	}
});

function ismail( oMail ) {
	// Valida oMail como um e-mail, retorna true/false

	//MyRegExp = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(oMail));
}


function validaLogin(oForm) {
	return true;

	var erro = false;
	var erroMsg = "";
	if(oForm.login.value.length < 4){
		if (!erro) { oForm.login.select(); oForm.login.focus(); }
		erro = true; erroMsg += "Digite seu nome de usuário (login)\n";
	}	
	if(oForm.senha.value.length < 4){
		if (!erro) { oForm.senha.select(); oForm.senha.focus(); }
		erro = true; erroMsg += "Digite sua senha\n";
	}	
	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		return true;
	}
}
	
	
var CCDTranslate = new Class({
	Implements: [Options, Events],
	options: {
		langFrom: 	'pt',
		langTo: 	'en',
		insertRelativeTo: null, //default to parent
		insertPosition: 'top',
		startMode:	'translate' //[translate,restore]		
		//onTraduziu
	},	
	linkEl: null,
	maxChunkLength: 900,
	currentChunkIdx: 0,
	originalChunks: [],
	originalContent: "",
	translatedContent: null,	
	initialize: function(_container, options){		
		this.container = _container;		
		this.originalContent = this.container.innerHTML;
		//dbug.log(this.originalContent);
		this.setOptions(options);
		this.setMode(this.options.startMode);
		this.createLink();		 
	},
	setMode: function(_mode) {
		this.mode = _mode;
		if (this.linkEl) {
			this.linkEl.setProperty("text", this.getLabel());
		}
	},
	getLabel: function() {
		if (this.mode == "translate") {
			return (this.options.langTo == "es")
					? "Traducir con Google"
					: "Translate with Google" ;		
		} else {
			return (this.options.langTo == "es")
					? "Texto Original"
					: "Original Text" ;
		}
	},
	createLink: function () {
		this.linkEl = new Element('div', {'class': 'translate', text: this.getLabel()});		
		this.linkEl.addEvent("click", function(ev) {
			if (this.mode == "translate") {
				this.translate();
			} else if (this.mode == "restore") {
				this.restore();
			}			
		}.bind(this));	
		var _relativeTo = $(this.options.insertRelativeTo) || this.container.getParent();		
		_relativeTo.grab(this.linkEl, this.options.insertPosition);	
		this.dotter = new Dotter(this.linkEl, {message: this.getLabel(), delay:400});
	},
	translate: function() {		
		//dbug.log("translate");
		if (this.translatedContent) {
			this.setTranslatedContent();
		} else {
			this.dotter.start();
			var tam = Math.ceil(this.originalContent.length / this.maxChunkLength);
			this.currentChunkIdx = 0;
			this.originalChunks = [];
			this.translatedContent = "";
			for (var i=0; i<tam; i++) {				
				var start 	= i * this.maxChunkLength;
				var end 	= (i+1) * this.maxChunkLength;					
				this.originalChunks.push(this.originalContent.substring(start, end));
			}						
			this.callService();			
		}			
	},	
	callService: function () {
		dbug.log("call service " + this.currentChunkIdx);		
		google.language.translate(this.originalChunks[this.currentChunkIdx], this.options.langFrom, this.options.langTo, function(result) {		
			dbug.log("traduzido chunk " + this.currentChunkIdx);							
			//dbug.log(result);							
			if (result.translation) {												
				this.translatedContent += result.translation;						
				if (this.currentChunkIdx < (this.originalChunks.length-1)) {				
					this.currentChunkIdx++;					
					this.callService.bind(this).delay(100);						
				} else {
					//dbug.log("fecho");
					this.dotter.stop();
					this.setTranslatedContent();
				}
			} else {
				alert("Google Translate Error");
			}					
		}.bind(this));
		return this;
	},
	restore: function() {
		this.setMode("translate");
		this.container.innerHTML = this.originalContent;	
		this.fireEvent('traduziu');
		return this;
	},
	setTranslatedContent: function() {
		this.setMode("restore");
		this.container.innerHTML = this.translatedContent;		
		this.fireEvent('traduziu');
		return this;
	}	
});
	
function setupCenterIcon(el) {
	dbug.log(el);
	var img_center = (Browser.Engine.trident)? 'zoom2.gif' : 'zoom.png';
	new CCDCenterIcon(el, {
		forceRelative: true,
		useFX: true,
		width: 32,
		height: 32,	
		fxOptions: { duration: 400 },
		hoverStyle: {backgroundImage: 'url(' + asset_path + 'img/' + img_center + ')'}
	}); 
}	

window.addEvent('domready', function() {			
	var myMenu = new MenuMatic();
    swfobject.embedSWF(asset_path + "swf/relogios.swf", "relogios", "200", "75", "8.0.0", asset_path + "swf/expressInstall.swf", null, {wmode: 'transparent'}, {});
   	swfobject.embedSWF(asset_path + "swf/banner.swf", "flash_home", "377", "151", "8.0.0", asset_path + "swf/expressInstall.swf", null, {wmode: 'transparent'}, {});
   	//swfobject.embedSWF(asset_path + "swf/banner.swf", "painel_noticias_img", "307", "151", "8.0.0", asset_path + "swf/expressInstall.swf", null, {wmode: 'transparent'}, {});
   	
	//hover thumbs
	//if (!Browser.Engine.trident4) {

	$$(".center_icon").each( function(el) { 
		setupCenterIcon(el);		
	}) ;
	
	
	$$('ul.losango li').each(function(el) {  
		var fx = new Fx.Morph(el,{ duration:300, link:'cancel' });
		el.addEvents({
			'mouseenter': function() { fx.start({ 'margin-left': 6 }); },
			'mouseleave': function() { fx.start({ 'margin-left': 0 }); }
		});
	});
	

	$$('#painel_servicos ul li').each(function(el) {  
		var fx = new Fx.Morph(el,{ duration:300, link:'cancel' });
		el.addEvents({
			'mouseenter': function() { fx.start({ 'margin-left': 6 }); },
			'mouseleave': function() { fx.start({ 'margin-left': 0 }); }
		});
	});
	

});		
