var $= jQuery.noConflict();

(function($) {
	var imgList = [];
	$.extend({
		preload: function(imgArr, option) {
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push($("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);

function vai() {
	$("#s").attr("style", "background:none;")
}



$('document').ready(function() {
	
	$('a[href*=#topo]').click(function() {
	
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
		&& location.hostname == this.hostname) {
		
			var $target = $(this.hash);
			
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
			if ($target.length) {
			
				var targetOffset = $target.offset().top;
				
				$('html,body').animate({scrollTop: targetOffset}, 700);
					
				return false;
				
			}
			
		}
		
	});
	
	
	
	/*
	$(".lista_streetstyle li").hover(
		function () {
			$(this+" .streetstyle_cover").show();
		}, 
		function () {
			$(this+" .streetstyle_cover").fadeOut(200);
		}
	);
	*/
	
	/*
	$('#social ul.lista_lado li').hover(
		function () {
			$("."+$(this).attr("class")+" .retratil").show();
			$("#s").attr("value", "");
			setTimeout("vai()", 150);
			
			$(this).animate({width: '148px'}, 150, 'easeInOutExpo');
		}, 
		function () {
			$("."+$(this).attr("class")+" .retratil").hide();
			$("#s").attr("value", "Busca");
			$("#s").attr("style", "background:#000;")
			
			$(this).animate({width: '24px'}, 150);
		}
	);
	
	$('#social').hover(
		function () {
			$(this).attr("style", "width:300px;");
		}, 
		function () {
			$(this).animate({width: '150px'}, 150);
			
			$("#s").attr("value", "Busca");
			$("#s").attr("style", "background:#000;")
			//$(this).attr("style", "width:150px;");
		}
	);
	*/
	
	$("#social ul li a").hover(
	  function () {
	    $("#social_tip").html($(this).attr("title"));
	    $("#social_tip").fadeIn(50);
	  },
	  function () {
	    
	  }
	);
	
	$("#social").hover(
	  function () {
	    
	  },
	  function () {
	    $("#social_tip").fadeOut(50);
	  }
	);
	
	$("form#searchform").submit(function() {
      if ($("input:first").val() != "Busca") {
        return true;
      }
      else return false;
    });

	
	$("#newsletter_area .newsletter_area_fecha, #social a.ico_newsletter, .rodape_newsletter a").click( function() {
		
		if ( $("#newsletter_area").is(".fechado") ) {
			$("#newsletter_area").fadeIn(200);
			$("#newsletter_area").removeClass("fechado");
			$("#nome").focus();
		}
		else {
			$("#newsletter_area").fadeOut(200);
			$("#newsletter_area").addClass("fechado");
		}

	});
	
	$("#newsletterform select#id_uf").change( function() {
		
		$("#cidade_area").html("Carregando...");
		
		var home_url= $("#home_url").val();
		
		$.get(home_url +'ajax', {chamada: "mudaCidade", id_uf: $(this).val() },
	
		function(retorno) {
			
			$("#cidade_area").html(retorno);
		});

	});
	
	
	
	$("#conteudo .lista_lado li a.ico_facebook, #conteudo .lista_lado li a.ico_twitter").click( function() {
		
		window.open($(this).attr("href"), "share", "height=400,width=700,scrollbars=no,status=yes,top=300,left=400");
		
		return false;
	});
	
	$("#sidebar .sidebar_widgets h2 a").click( function() {
		
		if ( $("#tit-"+$(this).attr("id")+"-link").is(".fechado") ) {
   			$("#list-"+$(this).attr("id")).slideDown(400, 'easeOutQuart');
			$("#tit-"+$(this).attr("id")+"-link").attr("class", "aberto");
		}
		else {
			$("#list-"+$(this).attr("id")+"").slideUp(400, 'easeOutQuart');
			$("#tit-"+$(this).attr("id")+"-link").attr("class", "fechado");
		}
		
		return false;
	});
	
	$("#item_lista_newsletter a").click( function() {
		
		if ( $("#item_lista_newsletter").is(".fechado") ) {
			$(".formulario_newsletter").slideRight(200);
			$("#item_lista_newsletter").attr("class", "aberto");
		}
		else {
			$(".formulario_newsletter").slideLeft(200);
			$("#item_lista_newsletter").attr("class", "fechado");
		}
		
		return false;
	});
	
	$(".formulario_busca button").click( function() {
		
		if ( $("#item_lista_newsletter").is(".aberto") ) {
			$(".formulario_newsletter").slideLeft();
			$("#item_lista_newsletter").attr("class", "fechado");
			return false;
		}	
		
	});
	
});

function mostraUnconventional(i) {
	$(".unconventional_galeria_bloco").hide();
	$("#unconventional_"+i).fadeIn(200);
}


jQuery.fn.extend({
  slideRight: function() {
    return this.each(function() {
      jQuery(this).animate({width: 'show'}, 300, 'easeInOutExpo');
    });
  },
  slideLeft: function() {
    return this.each(function() {
      jQuery(this).animate({width: 'hide'}, 300, 'easeInOutExpo');
    });
  },
  slideToggleWidth: function() {
    return this.each(function() {
      var el = jQuery(this);
      if (el.css('display') == 'none') {
        el.slideRight();
      } else {
        el.slideLeft();
      }
    });
  }
});
