jQuery(document).ready(function() {
    
    jQuery(".product:even").addClass("even");
    
    jQuery(".payment:last").addClass("last");
    
    jQuery("img[rel]").overlay({ 
          expose: { 
              color: '#000', 
              loadSpeed: 200, 
              opacity: 0.7
          }
    });
    
    //setTimeout(hideFlashes, 3000);
    
    jQuery("#btn_videos img").click(function() {
        jQuery("#videos").show("slow");
        jQuery("#btn_videos").hide("slow");
    });
    
    jQuery("#btn_hide_videos img").click(function() {
        jQuery("#videos").hide("slow");
        jQuery("#btn_videos").show("slow");
    });
    
    jQuery("#tooltips img[title]").tooltip('#tooltip');
    
    jQuery("#newsletter_input").focus(function() {
        if (jQuery(this).val() == "Seu e-mail...") {
            jQuery(this).val("");
        }
    });
    
    jQuery("#newsletter_input").blur(function() {
        if (jQuery(this).val() == "") {
            jQuery(this).val("Seu e-mail...");
        }
    });
    
    jQuery("#select_tag ul").hide();
    
    jQuery("#select_tag").hover(
        function() {
            jQuery("#select_tag ul").show("fast");
        },
        
        function() {
            jQuery("#select_tag ul").hide("fast");
        }
    );
    
    jQuery("#order_extended_warranty").click(function() {
        if (jQuery("#order_extended_warranty").is(':checked')) {
            jQuery("#order_extended_warranty_duration_12").attr('disabled', false);
            jQuery("#order_extended_warranty_duration_24").attr('disabled', false);
            jQuery("#order_extended_warranty_duration_12").attr('checked', true);
        }
        else {
            jQuery("#order_extended_warranty_duration_12").attr('checked', false);
            jQuery("#order_extended_warranty_duration_24").attr('checked', false);
            jQuery("#order_extended_warranty_duration_12").attr('disabled', true);
            jQuery("#order_extended_warranty_duration_24").attr('disabled', true);
        }
    });
    
});

var hideFlashes = function() {
    jQuery('#notice').fadeOut(8000);
}

function mascaraCpf(caixa, e) {
	if (e.keyCode != 8) {

		var obj = document.getElementById(caixa);
	
		if (obj.value.length == 3 || obj.value.length == 7) {
			obj.value += '.';
		}
	
		if (obj.value.length == 11) {
			obj.value += '-';
		}
	}
}

function mascaraCC(caixa, e) {
	if (e.keyCode != 8) {

		var obj = document.getElementById(caixa);
	
		if (obj.value.length == 4 || obj.value.length == 9 || obj.value.length == 14) {
			obj.value += '-';
		}
	}
}

function mascaraCnpj(caixa, e) {
	if (e.keyCode != 8) {

		var obj = document.getElementById(caixa);

		if (obj.value.length == 2 || obj.value.length == 6) {
			obj.value += '.';
		}

		if (obj.value.length == 10) {
			obj.value += '/';
		}
		
		if (obj.value.length == 15) {
			obj.value += '-';
		}
	}
}

function mascaraTel(caixa, e) {
	if (e.keyCode != 8) {

		var obj = document.getElementById(caixa);
	
		if (obj.value.length == 0) {
			obj.value += '(';
		}
		
		if (obj.value.length == 3) {
			obj.value += ')';
		}
		
		if (obj.value.length == 4) {
			obj.value += ' ';
		}
	
		if (obj.value.length == 9) {
			obj.value += '-';
		}
	}
}

function mascaraCep(caixa, e) {
	if (e.keyCode != 8) {

		var obj = document.getElementById(caixa);
	
		if (obj.value.length == 5) {
			obj.value += '-';
		}
	}
}

function mascaraSite(caixa) {
	var obj = document.getElementById(caixa);

	if (obj.value.length == 0) {
		obj.value = 'http://www.';
	}
}

function resetSite(caixa) {
	var obj = document.getElementById(caixa);

	if (obj.value == 'http://www.') {
		obj.value = '';
	}
}

function semLetras(e) {
	key = e.keyCode;
	if (!((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || key == 8 || key == 9 || key == 13 || key == 46|| key == 37 || key == 39)) {
		return false;
	}
}

// Início da Função FormataReais
function FormataReais(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '-0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
		return true;
		key = String.fromCharCode(whichCode); // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) return false; // Chave inválida
	len = fld.value.length;
	for(i = 0; i < len; i++)
	if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	
	if (len > 2) {
		aux2 = '';
		
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
		
			aux2 += aux.charAt(i);
			j++;
		}
	
		fld.value = '';
		len2 = aux2.length;
	
		for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	
	return false;
}

/////////////////////////// Kill IE 6! //////////////////////////

function $_freedom_(b)
{
	var i, a,c;
	if(arguments.length > 1){c = new Array(); for(i=0; i<arguments.length; i++) c.push(arguments[i]);}
	if(b instanceof Array){ c = b; }
	if(c instanceof Array){ a = new Array(); for(i=0; i<c.length; i++) a[i] = document.getElementById(c[i]);}
	else a = document.getElementById(b);
	return a;
}
function $_freedom_remove(a) { if(a && a.parentNode) a.parentNode.removeChild(a); }
function _freedom_addEvent(a, b, c, d, e)
{
	if(!a) return false;
	var f;
	if(typeof e != "undefined")
	{	
		if ( typeof(e) != 'string' ){ var g = []; for ( var i = 0; i < e.length; i++ ) g.push(e[i]); f = function(e) { c.apply(a,[e].concat(g)); };}
		else f = function(e) { c.apply(a, [e].concat(e)); };
	}
	else f = c;
	if (a.addEventListener){ addEventListener(b, f, d); return true; }
	else{ if (a.attachEvent) return a.attachEvent('on' + b, f); else a['on' + b] = f; }
};
function _freedom_getObjPosition(a)
{
	var b, c; a = $_freedom_(a); b = a.offsetLeft; c = a.offsetTop; var body = document.getElementsByTagName('body')[0];
	while (a.offsetParent && a!=body){ b += a.offsetParent.offsetLeft; c += a.offsetParent.offsetTop; a = a.offsetParent;}
	return {x: b, y:c};
}


var crossbrowser_BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; }
			else if (dataProp) return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ string: navigator.userAgent, subString: "Chrome", identity: "Chrome" },
		{  string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" },
		{ string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" },
		{ prop: window.opera, identity: "Opera" },
		{ string: navigator.vendor, subString: "iCab", identity: "iCab" },
		{ string: navigator.vendor, subString: "KDE", identity: "Konqueror" },
		{ string: navigator.userAgent, subString: "Firefox", identity: "Firefox" },
		{ string: navigator.vendor, subString: "Camino", identity: "Camino" },
		{ string: navigator.userAgent, subString: "Netscape", identity: "Netscape" },
		{ string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" },
		{ string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" },
		{ string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" }
	],
	dataOS : [
		{ string: navigator.platform, subString: "Win", identity: "Windows" },
		{ string: navigator.platform, subString: "Mac", identity: "Mac" },
		{ string: navigator.platform, subString: "Linux", identity: "Linux" }
	]

};

crossbrowser_BrowserDetect.init();
function crossbrowser_down()
{
	var step = 1;
	var timeStep = 20;
	if(_freedom_getObjPosition("crossbrowser").y+step < 0) 
	{
		$_freedom_("crossbrowser").style.top = (_freedom_getObjPosition("crossbrowser").y+step)+"px";
		setTimeout("crossbrowser_down()", timeStep);
	}
}

crossbrowser_showed = false;

function crossbrowser_show(){
	if(!crossbrowser_showed &&  (crossbrowser_BrowserDetect.browser == "Internet Explorer" || crossbrowser_BrowserDetect.browser == "Explorer") && crossbrowser_BrowserDetect.version <= "6")
	{
		var stats = document.createElement("img");
		stats.setAttribute("src",crossbrowser_stats);
		stats.style.display = "none";
		document.body.appendChild(stats);
		
		var iframe = document.createElement("iframe");
		iframe.setAttribute("frameBorder","0");
		iframe.setAttribute("id","crossbrowser");
		iframe.setAttribute("scrolling","no");
		iframe.style.height = "31px";
		iframe.style.position = "absolute";
		iframe.style.width = "100%";
		iframe.style.top = "-40px";
		iframe.style.left = "0px";
		iframe.style.border = "0px solid #000";
		
		document.body.appendChild(iframe);
		var doc = iframe.document;
		if(iframe.contentDocument) doc = iframe.contentDocument; // For NS6
		else if(iframe.contentWindow) doc = iframe.contentWindow.document; // For IE5.5 and IE6
	
		doc.open();
		doc.writeln(crossbrowser_iframe);
		doc.close();
		crossbrowser_down();
		crossbrowser_showed = true;
		
	}
}

function crossbrowser_hide(){
	$_freedom_remove($_freedom_("crossbrowser"));
}

_freedom_addEvent(window, "load", crossbrowser_show);
crossbrowser_iframe = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><body style="margin:0px; padding:0px; overflow:hidden; height:30px;"><div id="crossbrowser" style="height:30px;background:#F5FAFF;position:absolute;width:100%;left:0px;text-align:left;border-bottom:1px solid #AAAEB2;"><ul style="width:800px; margin:0 auto;padding:1px 0;list-style:none;"><li style="margin:3px 0 0 0;float:left;font:bold 16px Arial, Helvetica, sans-serif;color:#666;" title="Atualize seu navegador">Atualize seu navegador</li><li style="margin:3px 100px 0 8px;float:left;font:9px Arial, Helvetica, sans-serif;" title="Seguran&ccedil;a para voc&ecirc;, liberdade aos desenvolvedores">Mais seguran&ccedil;a para voc&ecirc;,<br />mais liberdade aos desenvolvedores</li><li style="float:right;margin: 0 0 0 10px;"><a href="javascript:window.parent.crossbrowser_hide();" style="margin:7px 0 0 0;display:block;width:14px;height:14px;background:url(http://imasters.uol.com.br/crossbrowser/sprBarratopo.png) 0px -41px no-repeat;text-indent:-9999px;" title="Fechar">Fechar</a></li><li style="float:right;margin-left:10px;"><a target="_blank" href="http://imasters.uol.com.br/crossbrowser/pt-br/" style="margin:4px 0 0 0;padding:4px;display:block;font:bold 9px Arial, Helvetica, sans-serif;text-decoration:none;color:#666;" title="Fa&ccedil;a parte da campanha">Fa&ccedil;a parte da campanha</a></li><li style="float:left;padding:2px 0 0 0;font-weight:bold;color:#690"><small style="font:10px Arial, Helvetica, sans-serif;">Baixe agora!</small></li><li style="float:left;"><a target="_blank" href="http://www.mozilla.com/" title="Mozilla Firefox" style="margin:0 0 0 12px;display:block;width:26px;height:26px;background: url(http://imasters.uol.com.br/crossbrowser/img/sprBarratopo.png) -62px -5px no-repeat;text-indent:-9999px;">Mozilla Firefox</a></li><li style="float:left;margin-left:2px;"><a target="_blank" href="http://www.google.com/chrome" title="Google Chrome" style="margin:4px 0 0 4px;display:block;width:19px;height:19px;background:url(http://imasters.uol.com.br/crossbrowser/sprBarratopo.png) -125px -8px no-repeat;text-indent:-9999px;">Google Chrome</a></li><li style="float:left;margin-left:2px;"><a target="_blank" href="http://www.apple.com/safari/download/" title="Apple Safari" style="margin:4px 0 0 4px;display:block;width:19px;height:19px;background:url(http://imasters.uol.com.br/crossbrowser/sprBarratopo.png) -96px -9px no-repeat;text-indent:-9999px;">Safari</a></li><li style="float:left;margin-left:2px;"><a target="_blank" href="http://www.opera.com/download/" title="Opera" style="margin:4px 0 0 4px;display:block;width:22px;height:18px;background:url(http://imasters.uol.com.br/crossbrowser/sprBarratopo.png) -151px -8px no-repeat;text-indent:-9999px;">Opera</a></li><li style="float:left;margin-left:2px;"><a target="_blank" href="http://www.microsoft.com/windows/internet-explorer/" title="Internet Explorer 8" style="margin:4px 0 0 4px;display:block;width:21px;height:20px;background:url(http://imasters.uol.com.br/crossbrowser/sprBarratopo.png) -180px -7px no-repeat;text-indent:-9999px;">Internet Explorer</a></li></ul></div></body></html>';
crossbrowser_stats = 'http://imasters.uol.com.br/crossbrowser/stats.gif?l=pt-br&ua='+navigator.userAgent+'&ref='+window.location+'&p=1'; 
