Cufon.replace('#menu li');
Cufon.replace('#blogname');
Cufon.replace('#mapa li');
Cufon.replace('.title');
Cufon.replace('.cufon');
Cufon.replace('#cotacaotitle');
Cufon.replace('#selictitle');
Cufon.replace('.leiamais #lmtxt');
Cufon.replace('#bb-center a');
Cufon.replace('#content-right h2');
Cufon.replace('#content-right h3');
Cufon.replace('.proxima #pgnexttxt');
Cufon.replace('#entre-contato');
Cufon.replace("#sharing td");

//Cufon.replace('.anterior #pgprevtxt');
var a = 0;
function changeBG() {
	if (a == 0) {
		document.body.style.backgroundImage = "url('http://constantinpt-br/wp-content/themes/constantin/images/home.png')";
		a = 1;
	} else {
		document.body.style.backgroundImage = "url('http://constantinpt-br/wp-content/themes/constantin/images/bg-home.png')";
		a = 0;
	}
}

function submitSearch() {
	return false;
}

function winWidth() {
	var myWidth = 0, myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		// Non-IE
		myWidth = window.innerWidth;
	} else if (document.documentElement
			&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if (document.body
			&& (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}

$(document).ready(function(){
	
	$("#telefone").click(function(event){
		$("#telefone-box").fadeIn();
		$("#email-box").fadeOut();
		$("#sharing").fadeOut();
		event.stopPropagation();
	});
	$("#email").click(function(event){
		$("#email-box").fadeIn();
		$("#telefone-box").fadeOut();
		$("#sharing").fadeOut();
		event.stopPropagation();
	});
	$("#bb-share").click(function(event){
		$("#sharing").fadeIn();
		$("#telefone-box").fadeOut();
		$("#email-box").fadeOut();
		event.stopPropagation();
	});
	
	$("#sharing").click(function(event){
		event.stopPropagation();
	});
	$("#telefone-box").click(function(event){
		event.stopPropagation();
	});
	$("#email-box").click(function(event){
		event.stopPropagation();
	});
	
	$("#shareclose").click(function(event){
		$("#sharing").fadeOut();
		event.stopPropagation();
	});
	
	$("#sharesend").click(function() {
		error = false;
		if(!$("#sharing form").validate().element("input[name=seunome]")){
			error = true;
		}
		if(!$("#sharing form").validate().element("input[name=amigonome]")){
			error = true;
		}
		if(!$("#sharing form").validate().element("input[name=seuemail]")){
			error = true;
		}
		if(!$("#sharing form").validate().element("input[name=amigoemail]")){
			error = true;
		}
		if(!error){
			sendPost();
		}
	});
	function sendPost(){
		var data = 	'seunome='		+	$("input[name=seunome]").val()+
					'&seuemail='	+	$("input[name=seuemail]").val()+
					'&amigonome='	+	$("input[name=amigonome]").val()+
					'&amigoemail='	+	$("input[name=amigoemail]").val()+
					'&url='			+	$("input[type=hidden]").val()+
					'&lang='		+	$("input[name=lang]").val();
		
		$.ajax({
				type	: "POST",
				url		: "/ajaxmail.php",
				data	: data,
				success	: function(result){
							console.log(result);
							}
			});
	}
	
	
	$("body").click(function(event){
		$("#sharing").fadeOut();
		$("#telefone-box").fadeOut();
		$("#email-box").fadeOut();
		event.stopPropagation();
	});
	
	$(".leiamais,.proxima,.anterior").each(function(){
	    $(this).click(function(){
	        location.href = $(this).children('#lmtxt, #pgnexttxt, #pgprevtxt').children('a').attr('href');
	    });
	});
	
	function getDomain(url) {
	    if(typeof(url) == 'string') {
	        pattern = /:\/\/(.[^/]+)/;
	        if(pattern.test(url)){;
	            return url.match(pattern)[1];
	        }else {
	            return false;
	        }
	    }
	}
	$('a').each(function(a,b){
	    domain = getDomain(b.href);
	    if(domain != false && document.domain !=  domain) {
	            $(b).click(function(){
	                _gaq.push(['_link', b.href]);
	                return false;
	            })
	    }
	})
	
});
