var UFO = {
	requiredAttrParams: ["movie", "width", "height", "majorversion", "build", "vid", "vname"],
	optionalAttrEmb: ["name", "swliveconnect", "align"],
	optionalAttrObj: ["id", "align"],
	optionalAttrParams: ["play", "loop", "menu", "quality", "scale", "salign", "wmode", "bgcolor", "base", "flashvars", "devicefont", "allowscriptaccess"],
	
	create: function(FO, id) {
		UFO.setElementDisplay(id, "none");
		var loadfn = function() {
			if (UFO.hasRequiredAttrParams(FO) && UFO.hasFlashVersion(FO.majorversion, FO.build)) {
				UFO.writeFlashObject(FO, id);
			}
			UFO.setElementDisplay(id, "block");
		};
		UFO.addLoadEvent(loadfn);
	},

	setElementDisplay: function(id, display) {
		if (!document.createElement || !document.getElementsByTagName) return;
		var selector = "#" + id;
		var property = "display: " + display;
		var style = document.createElement("style");
		style.setAttribute("type", "text/css");
		style.setAttribute("media", "screen");
		document.getElementsByTagName("head")[0].appendChild(style);
		var agt = navigator.userAgent.toLowerCase(); 
		var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
		var is_win = (agt.indexOf("win") != -1);
		if (!(is_ie && is_win)) {
			var styles = document.getElementsByTagName("style");
			if (styles && styles.length > 0 && document.createTextNode) {
				var lastStyle = styles[styles.length - 1];
				var rule = document.createTextNode(selector + " {" + property + ";}");
				lastStyle.appendChild(rule); // Hopelessly bugs in IE/Win
			}
		}
		else if (document.styleSheets && document.styleSheets.length > 0) {
			var stylesheet = document.styleSheets[document.styleSheets.length - 1];
			if (typeof stylesheet.addRule == "object"){ // This test bugs in IE/Mac and Safari
				stylesheet.addRule(selector, property);
			}
		}
	},

	hasRequiredAttrParams: function(FO) {
		for (var i = 0; i < UFO.requiredAttrParams.length; i++) {
			if (typeof FO[UFO.requiredAttrParams[i]] == "undefined") return false;
		}
		return true;
	},
	
	hasFlashVersion: function(majorVersion, build) {
		var reqVersion = parseFloat(majorVersion + "." + build);
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			var desc = navigator.plugins["Shockwave Flash"].description;
			if (desc) {
				var descArr = desc.split(" ");
				var majorArr = descArr[2].split(".");
				var major = majorArr[0];
				if (descArr[3] != "") {
					var minorArr = descArr[3].split("r");
				}
				else {
					var minorArr = descArr[4].split("r");
				}
				var minor = minorArr[1] > 0 ? minorArr[1] : 0;
				var flashVersion = parseFloat(major + "." + minor);
			}
		}
		else if (window.ActiveXObject) {
			try {
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				var desc = flash.GetVariable("$version");
				if (desc) {
					var descArr = desc.split(" ");
					var versionArr = descArr[1].split(",");        
					var major = versionArr[0];
					var minor = versionArr[2];
					var flashVersion = parseFloat(major + "." + minor);
				}
			}
			catch(e) {}
		}
		if (typeof flashVersion != "undefined"){
			return (flashVersion >= reqVersion ? true : false); 
		}
		return false;
	},

	writeFlashObject: function(FO, id) {
		if (!document.getElementById) return;
		var el = document.getElementById(id);
		if (typeof el.innerHTML == "undefined") return;
		var embHTML = "";
		var objAttrHTML = "";
		var objParamHTML = "";
		for (var i = 0; i < UFO.optionalAttrEmb.length; i++) {
			if (typeof FO[UFO.optionalAttrEmb[i]] != "undefined" && FO[UFO.optionalAttrEmb[i]] != "") {
				embHTML += ' ' + UFO.optionalAttrEmb[i] + '="' + FO[UFO.optionalAttrEmb[i]] + '"';
			}
		}
		for (var i = 0; i < UFO.optionalAttrObj.length; i++) {
			if (typeof FO[UFO.optionalAttrObj[i]] != "undefined" && FO[UFO.optionalAttrObj[i]] != "") {
				objAttrHTML += ' ' + UFO.optionalAttrObj[i] + '="' + FO[UFO.optionalAttrObj[i]] + '"';
			}
		}
		for (var i = 0; i < UFO.optionalAttrParams.length; i++) {
			if (typeof FO[UFO.optionalAttrParams[i]] != "undefined" && FO[UFO.optionalAttrParams[i]] != "") {
				embHTML += ' ' + UFO.optionalAttrParams[i] + '="' + FO[UFO.optionalAttrParams[i]] + '"';
				objParamHTML += '<param name="' + UFO.optionalAttrParams[i] + '" value="' + FO[UFO.optionalAttrParams[i]] + '" />';
			}
		}
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			var foHTML = '<embed type="application/x-shockwave-flash" src="' + FO.movie + '" width="' + FO.width + '" height="' + FO.height + '" name="' + FO.vname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"';
			foHTML += embHTML;
			foHTML += '></embed>';
		}
		else {
			var foHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + objAttrHTML + ' width="' + FO.width + '" height="' + FO.height + '" id="' + FO.vid + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + FO.majorversion + ',0,' + FO.build + ',0">';
			foHTML += '<param name="movie" value="' + FO.movie + '" />';
			foHTML += objParamHTML;
			foHTML += '</object>';
		}
		el.innerHTML = foHTML;
	},

	addLoadEvent: function(fn) {
		if (window.addEventListener) {
			window.addEventListener("load", fn, false);
		}
		else if (document.addEventListener) {
			document.addEventListener("load", fn, false);
		}
		else if (window.attachEvent) {
			window.attachEvent("onload", fn);
		}
		else if (typeof window.onload == "function") {
			var fnOld = window.onload;
			window.onload = function(){
				fnOld();
				fn();
			};
		}
		else {
			window.onload = fn;
		}
	}
};
//////////////////////////////////////////////////////////////////////////////////////////
//GOOGLE ANALYTiCS
//////////////////////////////////////////////////////////////////////////////////////////
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
	var pageTracker = _gat._getTracker("UA-10319541-1");
	pageTracker._trackPageview();
} catch(err) {}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// HTTP Request para classes em Ajax
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function requestHTTP() {
	
	try { http = new ActiveXObject("Msxml2.XMLHTTP"); }  
	catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); }  
	catch (e) { try { http = new XMLHttpRequest(); }
	catch (e) { http = false; }}}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONTATO
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function(){
	$("#assunto").click(function () {
		document.getElementById("select").style.width = (document.getElementById("assunto").offsetWidth-3) + "px";	
		if ($("#select").is(":hidden")) {
			$("#select").slideDown("slow");
		}
		else {
			$("#select").slideUp("slow");
		}
	});
	$("input").click(function () {
		$("#select").slideUp("slow");
	});
	$("textarea").click(function () {
		$("#select").slideUp("slow");
	});
});	
function highlightin(id) {
	document.getElementById(id).style.backgroundColor="#baffaf";
}
function highlightout(id) {
	document.getElementById(id).style.backgroundColor="#FFFFFF";
}
function selectValue(value) {
	document.formContact.assunto.value = value;
	document.getElementById("label").innerHTML = value;

}
function sendMail(frm, value) {

	var nome = frm.nome.value;
	var email = frm.email.value;
	var telefone = frm.telefone.value;
	var assunto = frm.assunto.value;
	var msg = frm.msg.value;
	
	var retorno = true;
	var resposta = "";

	var at="@";
	var dot=".";
	var lat =  email.indexOf(at);
	var lstr = email.length;
	var ldot = email.indexOf(dot);

	document.getElementById("resultado").innerHTML = "<img src='../images/layout/loading.gif' width='20' height='20' border='0' align='middle' /> Enviando..."

	if(nome == "" || nome == " " || nome.length < 3) {
		document.getElementById("nome").style.backgroundColor = "#fff0f0";
		document.getElementById("wnome").style.display = "block";
		retorno = false;
	}
	else {
		document.getElementById("nome").style.backgroundColor = "#ffffff";
		document.getElementById("wnome").style.display = "none";
	}
	if (email.indexOf(at)==-1 || 
		email.indexOf(at)==0 || 
		email.indexOf(at)==lstr ||
		email.indexOf(dot)==-1 || 
		email.indexOf(dot)==0 || 
		email.indexOf(dot)==lstr ||
		email.indexOf(at,(lat+1))!=-1 ||
		email.substring(lat-1,lat)==dot || 
		email.substring(lat+1,lat+2)==dot ||
		email.indexOf(dot,(lat+2))==-1 ||
		email.indexOf(" ")!=-1
		){
		document.getElementById("email").style.backgroundColor = "#fff0f0";
		document.getElementById("wemail").style.display = "block";
		retorno = false;
	}
	else {
		document.getElementById("email").style.backgroundColor = "#ffffff";
		document.getElementById("wemail").style.display = "none";
	}
	if(msg == "" || msg == " " || msg.length < 3) {
		document.getElementById("msg").style.backgroundColor = "#fff0f0";
		document.getElementById("wmsg").style.display = "block";
		retorno = false;
	}
	else {
		document.getElementById("msg").style.backgroundColor = "#ffffff";
		document.getElementById("wmsg").style.display = "none";
	}
	if(retorno == true) {
		
		requestHTTP();
		http.open('GET', "enviaMail.php?nome="+nome+"&email="+email+"&telefone="+telefone+"&assunto="+assunto+"&msg="+msg, true);
		http.onreadystatechange = AjaxResult;
		http.send(null);	
		
		function AjaxResult()	{
			if (http.readyState == 4) {
				if(http.status == 200) {
					results = http.responseText;
					document.getElementById("resultado").innerHTML = results;
					frm.nome.value = "";
					frm.email.value = "";
					frm.telefone.value = "";
					frm.assunto.value = "";
					frm.msg.value = "";
					document.getElementById("label").innerHTML = value;
				}
			}
		}
	}
	else {
		document.getElementById("resultado").innerHTML = '<img src="../images/layout/erro.gif" width="15" height="15" border="0" align="middle" /> <span style="color: #990000; font-weight: bold">Erro no preenchimento do formulário.</span>';
	}
	return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PORTFOLIO
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
scrollStep=1

timerLeft=""
timerRight=""

function toLeft(id){
  document.getElementById(id).scrollLeft=0
}

function scrollDivLeft(id){
  clearTimeout(timerRight) 
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10)
}

function scrollDivRight(id){
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10)
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}

function highlightOver(id) { document.getElementById(id).style.borderColor = "#0ea925"; }
function highlightOut(id) { document.getElementById(id).style.borderColor = "#CCCCCC"; }

function showpic(id) {
	
	document.getElementById("containerFoto").innerHTML = "<img src='../images/layout/loading.gif' width='32' height='32' border='0' style='margin-top: 120px' />"
	
	requestHTTP();
	http.open('GET', "imagePortfolio.php?id="+id, true);
	http.onreadystatechange = AjaxResult;
	http.send(null);	
		
	function AjaxResult()	{
		if (http.readyState == 4) {
			if(http.status == 200) {
				results = http.responseText;
				document.getElementById("containerFoto").innerHTML = results;
			}
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NOTICIAS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function contract(id) {
	document.getElementById(id+"_contract").style.display = "none";
	document.getElementById(id+"_expand").style.display = "inline";
	$(document).ready(function(){
		$("#"+id).slideUp("slow");
	});	
	
	
}
function expand(id) {
	document.getElementById(id+"_contract").style.display = "inline";
	document.getElementById(id+"_expand").style.display = "none";
	$(document).ready(function(){
		$("#"+id).slideDown("slow");
	});	
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IR PARA UMA URL DIFERENTE
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function goto(url) {
	window.location.href=url;
}