	$(document).ready(function(){    
		$('#monteProjeto').click(function() {
			$('#containerOrcamento').slideToggle('slow');
		});

		$('#botaoFechar').click(function() {
			$('#containerOrcamento').slideUp('slow');
		});
		
		//Validação Orçamento
		$('#formularioOrcamento input[type="text"]').focus(function() {
			if (this.value == this.defaultValue){
        		this.value = '';
    		}
        	if(this.value != this.defaultValue){
	    		this.select();
        	}
		});
		$('#formularioOrcamento input[type="text"]').blur(function() {
			if ($.trim(this.value == '')){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});

		$('#formularioOrcamento #txtProjeto').focus(function() {
			if (this.value == this.defaultValue){
        		this.value = '';
    		}
        	if(this.value != this.defaultValue){
	    		this.select();
        	}
		});
		$('#formularioOrcamento #txtProjeto').blur(function() {
			if ($.trim(this.value == '')){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});
		
		$("a[rel^='prettyPhoto']").prettyPhoto({
			social_tools: false	
		});	

		//Twitter
		$.jTwitter('iseecomunicacao', 2, function(data){
			$('#tweets').empty();
			$.each(data, function(i, post){
				$('#tweets').append(
					  '<div class="tweet"><p>'+linkify(post.text)+'</p></div>'
					//+ '<div class="autorTweet left"><a href="http://www.twitter.com/'+post.user.screen_name+'" target="_blank">@' + post.user.screen_name + '</a></div>'  
					//+ '<div class="dataTweet right">' + relative_time(post.created_at) + '</div>'
				);
			});
		});
		
		//Transforma link do Twitter
		function linkify(inputText) {
			var replaceText, replacePattern1, replacePattern2, replacePattern3;
		
			//URLs: http://, https://, ftp://
			replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
			replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
		
			//URLs: "www."
			replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
			replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
		
			//mailto:
			replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
			replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
		
			return replacedText
		}
		
		//Transforma data do post no Twitter					
    	function relative_time(time_value) {
    	  var values = time_value.split(" ");
    	  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
    	  var parsed_date = Date.parse(time_value);
    	  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
    	  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
    	  delta = delta + (relative_to.getTimezoneOffset() * 60);
    	  
    	  var r = '';
    	  if (delta < 60) {
    		r = '1 minuto atr&aacute;s';
    	  } else if(delta < 120) {
    		r = 'alguns minutos atr&aacute;s';
    	  } else if(delta < (45*60)) {
    		r = (parseInt(delta / 60)).toString() + ' minutos atr&aacute;s';
    	  } else if(delta < (90*60)) {
    		r = 'hora atr&aacute;s';
    	  } else if(delta < (24*60*60)) {
    		r = '' + (parseInt(delta / 3600)).toString() + ' horas atr&aacute;s';
    	  } else if(delta < (48*60*60)) {
    		r = '1 dia atr&aacute;s';
    	  } else {
    		r = (parseInt(delta / 86400)).toString() + ' dias atr&aacute;s';
    	  }
    	  
    	  return r;
    	}
				
		$('#mycarousel').jcarousel({
			scroll: 1		
		});
		
		$("#sliderPortfolio").easySlider({
			auto: true,
			continuous: true,
			numeric: true,
			speed: 1200
		});
		
		$("a.anchorLink").anchorAnimate();
		
		//When page loads...
			$(".tab_content").hide(); //Hide all content
			$("ul.tabs li:first").addClass("active").show(); //Activate first tab
			$(".tab_content:first").show(); //Show first tab content
		
			//On Click Event
			$("ul.tabs li").click(function() {
		
				$("ul.tabs li").removeClass("active"); //Remove any "active" class
				$(this).addClass("active"); //Add "active" class to selected tab
				$(".tab_content").hide(); //Hide all tab content
		
				var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
				$(activeTab).fadeIn(); //Fade in the active ID content
				return false;
			});
		
			$("ul.linksCategorias li").click(function() {
				

				$("ul.tabs li").removeClass("active"); //Remove any "active" class
				$(this).addClass("active"); //Add "active" class to selected tab
				$(".tab_content").hide(); //Hide all tab content
		
				var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
				$(activeTab).fadeIn(); //Fade in the active ID content

   				var destination = $(activeTab).offset().top;
   				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-400}, 500 );
   
   				return false;
			});

	});
	
$(function() {
	//scrollpane parts
	var scrollPane = $( "#listaTrabRecente" ),
		scrollContent = $( "#listaTrabRecenteConteudo" );
	
	//build slider
	var scrollbar = $(".scroll-bar").slider({
		slide: function( event, ui ) {
			if ( scrollContent.width() > scrollPane.width() ) {
				scrollContent.css( "margin-left", Math.round(
					ui.value / 100 * ( scrollPane.width() - scrollContent.width() )
				) + "px" );
			} else {
				scrollContent.css( "margin-left", 0 );
			}
		}
	});
	
	//append icon to handle
	var handleHelper = scrollbar.find( ".ui-slider-handle" )
	.mousedown(function() {
		scrollbar.width( handleHelper.width() );
	})
	.mouseup(function() {
		scrollbar.width( "100%" );
	})
	//.append( "<span class='ui-icon ui-icon-grip-dotted-vertical'></span>" )
	.wrap( "<div class='ui-handle-helper-parent'></div>" ).parent();
	
	//change overflow to hidden now that slider handles the scrolling
	scrollPane.css( "overflow", "hidden" );
	
	//size scrollbar and handle proportionally to scroll distance
	function sizeScrollbar() {
		var remainder = scrollContent.width() - scrollPane.width();
		var proportion = remainder / scrollContent.width();
		//var handleSize = scrollPane.width() - ( proportion * scrollPane.width() );
		var handleSize = scrollPane.width() - ( 590 );
		scrollbar.find( ".ui-slider-handle" ).css({
			width: handleSize,
			"margin-left": -handleSize / 2
		});
		handleHelper.width( "" ).width( scrollbar.width() - handleSize );
	}
	
	//reset slider value based on scroll content position
	function resetValue() {
		var remainder = scrollPane.width() - scrollContent.width();
		var leftVal = scrollContent.css( "margin-left" ) === "auto" ? 0 :
			parseInt( scrollContent.css( "margin-left" ) );
		var percentage = Math.round( leftVal / remainder * 100 );
		scrollbar.slider( "value", percentage );
	}
	
	//if the slider is 100% and window gets larger, reveal content
	function reflowContent() {
			var showing = scrollContent.width() + parseInt( scrollContent.css( "margin-left" ), 100 );
			var gap = scrollPane.width() - showing;
			if ( gap > 0 ) {
				scrollContent.css( "margin-left", parseInt( scrollContent.css( "margin-left" ), 10 ) + gap );
			}
	}
	
	//change handle position on window resize
	$( window ).resize(function() {
		resetValue();
		sizeScrollbar();
		reflowContent();
	});
	//init scrollbar size
	setTimeout( sizeScrollbar, 10 );//safari wants a timeout
});

//Anchor
jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}
