$.fn.extend({ // hack usado para que nao de bronca nos browsers que nao sejam o IE6, porque a extensao so e carregada no IE6
	pngFix: function() {}
})


function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}


runsIRF = function(){
	// sIFR
	if(typeof sIFR == "function"){
    	sIFR.replaceElement("#navigation li", named({sFlashSrc: "./humanist512bt_roman.swf", sColor: "#333333", sLinkColor: "#333333", sHoverColor:"#0099ff", sCase: "upper", sWmode: "transparent"}));
		sIFR.replaceElement("h1", named({sFlashSrc: "./humanist512bt_light.swf", sColor: "#0099ff", sWmode: "transparent"}));
	};
}


navigationAjax = function(){
	jQuery("#navigation a").each(function(){
		jQuery(this).attr("href", "#"+jQuery(this).attr("href"))
	}).address(function() {  
		return $(this).attr('href').replace(/^#/, '');
	})
	
	
	jQuery.address.change(function(event){
		if (event.path != "/") {
			jQuery.ajax({
				type: "GET",
				url: event.path + "?frame=null",
				cache: true,
				dataType: "html",
				complete: function(res, status){
					$.address.value(event.path);
					if ( status == "success" || status == "notmodified" ){
						var pageLoaded = jQuery("<div/>").append(res.responseText.replace(/<script(.|\s)*?\/script>/g, "")) ; // Create a dummy div to hold the results and inject the contents of the document in, removing the scripts to avoid any 'Permission Denied' errors in IE
						jQuery("#temp").html(pageLoaded.find("#container .center"));
						var newContentHeight = jQuery("#temp").height();
	
						jQuery("#container").fadeOut('normal', function(){
							jQuery("#container").html(jQuery("#temp").html()); // Replaces the content
							jQuery("#container").fadeIn()
							
							jQuery("#navigation a").each(function(){
								if (jQuery(this).attr("href").substr(1) == event.path.substr(1)) {
									jQuery(this).addClass("active");
									jQuery.address.title(jQuery(this).text() + " - Pedro Passos Coelho")
								} else {
									jQuery(this).removeClass("active");
								}
							});
							
							runsIRF();
	
						});
					}
				}
			});
		}
	})
}


var apresentacaoHover = false;
var x = 0;

tickerApresentacoesRun = function(obj, nElm){
	if(!apresentacaoHover){
		$("li", obj).fadeOut("slow");
		if (x >= nElm) {
			x = 0;
		} 
		$("li:eq("+x+")", obj).fadeIn("slow");
		x++;
	}
}

tickerApresentacoes = function(obj){
	nElm = $("li", obj).size();
	if (nElm > 1) {
		$("li", obj).fadeOut(1).hover(function(){
			apresentacaoHover = true;
		}, function(){
			apresentacaoHover = false;
		})
		eval('tickerApresentacoesRun("'+obj+'",'+nElm+')');
		setInterval('tickerApresentacoesRun("'+obj+'",'+nElm+')',7000)
	}
}


youtubeIDextract = function(url) { 
  var youtube_id;
  youtube_id = url.replace(/^[^v]+v.(.{11}).*/,"$1");
  return youtube_id;
}