$contadorDebug = 0;
function debugar($msg){
	$('#debug').html($contadorDebug+": "+$msg+"<br/>"+$('#debug').html());		
	$contadorDebug++;
}

(function($) {
    if ($.browser.mozilla) {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).css({
                    'MozUserSelect' : 'none'
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).css({
                    'MozUserSelect' : ''
                });
            });
        };
    } else if ($.browser.msie) {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).bind('selectstart.disableTextSelect', function() {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).unbind('selectstart.disableTextSelect');
            });
        };
    } else {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).bind('mousedown.disableTextSelect', function() {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).unbind('mousedown.disableTextSelect');
            });
        };
    }
})(jQuery);


jQuery.fn.carroselFotos = function(options) {

	var o = jQuery.extend({
		anterior : "botaoAnterior",
		proximo : "botaoProximo",
		tempo : 10,
		pixelMecher: 5
	}, options);	
	
	var $contador = 0;
	var $totalFotos = 0;	
	var $w = 0;
	var $ID = this;
	var $offset = parseInt($(this).offset().left);
	var $left = getLeft(this);
	var $wOri = $(this).width();
	var $resto = 0;
	var $interval = null;
	
	$(this).find("li").each(function(){
		$totalFotos++;
		$w += $(this).innerWidth();
	});	
	
	$(this).width($w);	

	function anterior(){
	
		$o = getLeft($ID);
		$l = $o + o.pixelMecher;
				
		if($l > 0){
			$($ID).css("left","0px");
			clearInterval($interval);			
			return;
		}
					
		$($ID).css("left",$l+"px");

	}	
	
	$('#'+o.anterior).css("cursor","pointer").mouseover(function(){
			anterior();
			$interval = setInterval(anterior,o.tempo);
	})
											.mouseout(function(){
												
			clearInterval($interval);											
	});	
	
	
	function proximo(){

		$o = getLeft($ID);
		$l = $o - o.pixelMecher;
		$wF = $w - Math.abs($l);

		$resto = $wOri - Math.abs($wF);					
		if($resto > 0){
			$l = $l + $resto;
			$($ID).css("left",$l+"px");
			clearInterval($interval);			
			return;
		}
					
		$($ID).css("left",$l+"px");

	}	
	
	$('#'+o.proximo).css("cursor","pointer").mouseover(function(){
			proximo();
			$interval = setInterval(proximo,o.tempo);
	})
											.mouseout(function(){
												
			clearInterval($interval);											
	});
	
	
	

	
	function getLeft($it){
		$l = parseInt($($it).css("left").replace("px",""));
		return $l;
	}
	
	function isAnimating($it){
		if($($it).filter(":animated").length){return false;}
		return true
	}
	
}

$(document).ready(function() {
	
/*	$("body").css("display", "none");

    $("body").fadeIn(2000);
    
	$("a.transition").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("body").fadeOut(1000, redirectPage);		
	});
		
	function redirectPage() {
		window.location = linkLocation;
	}*/
	
	$("a").click(function(event){
		if($(this).hasClass("nao")){return;}		
		event.preventDefault();
		changePage(this.href);
	});	
	
});

function changePage($href,$time){
	if($time == undefined){$time = 1000;}
	
	$h = $(window).height();
	$w = $(window).width();

	var $div = $('<div></div>').css({'width':$w,'height':$h,'position':'absolute','top':'0px','left':'0px','background-color':'#FFFFFF','display':'none','z-index':9999999});
	$div.appendTo('body');
	$div.fadeIn($time,function(){
		window.location = $href;		
	});
	
}

