$("document").ready(function(){

	/************************************/
	/**********MENU ANIMATIONS***********/
	/************************************/
	
	$("#main-menu li:not('.selected') a").hover(function(){
		$(this).stop().animate({color:"#FFF"}, 150);
	},function(){
		$(this).stop().animate({color:"#ABB6BB"}, 150);
	});
	
	/************************************/
	/*************HERO SCRIPT************/
	/************************************/
	
	var HERO_ANIMATION_SPEED = 700;
	var HERO_EASING = 'easeOutQuint';
	var DISTANCE = $("#hero .hero_image img").outerWidth(true);
	var slider = $("#hero .hero_image .slider");
	
	slider.css("width", ($("#hero .hero_image img").length * $("#hero .hero_image img").width()));
	
	$("#hero .wrapper .hero_image").hover(function(){
		if($(this).find("input[type='image']").length === 0){
			var btn_left = $("<input id='btn_left' type='image' src='css/images/ico_left_arrow.png' />");
			var btn_right = $("<input id='btn_right' type='image' src='css/images/ico_right_arrow.png' />");
			var btn_zoom = $("<input  id='btn_zoom' type='image' src='css/images/ico_zoom.png' />");
			$(this).append(btn_left);
			$(this).append(btn_right);
		}
		if($.browser.msie){
			$(this).find("#btn_left, #btn_right, #btn_zoom").css("opacity", "0").stop().animate({"opacity": "0.7"}, 200);
		}else{
			$(this).find("#btn_left, #btn_right, #btn_zoom").css("opacity", "0").stop().animate({"opacity": "1"}, 200);
		}
	},function(){
		$("#hero .wrapper #btn_left," +
			"#hero .wrapper #btn_right").stop().animate({"opacity": "0"}, 200, function(){
			$(this).remove();
		});
	});
	
	$("#hero #btn_left").live("click", function(){
		if(!slider.is(":animated")){
			var leftPosition = parseInt(slider.css("margin-left").replace("px"));
			if(leftPosition < 0){
				slider.animate({"margin-left": (leftPosition + DISTANCE)}, HERO_ANIMATION_SPEED, HERO_EASING);
			}else{
				slider.animate({"margin-left": ((slider.width() - DISTANCE) * (-1))}, HERO_ANIMATION_SPEED + 800, HERO_EASING);
			}
		}
	});
	
	$("#hero #btn_right").live('click', function(){
		if(!slider.is(":animated")){
			var leftPosition = parseInt(slider.css("margin-left").replace("px"));
			if((leftPosition * (-1)) + DISTANCE < slider.width()){
				slider.animate({"margin-left": ((DISTANCE * (-1)) + leftPosition)}, HERO_ANIMATION_SPEED, HERO_EASING);
			}else{
				slider.animate({"margin-left": 0}, HERO_ANIMATION_SPEED + 800, HERO_EASING);
			}
		}
	});
	
	$("#hero .hero_image #btn_zoom").live('click', function(){
		throwOverlay();
	});
	
	/************************************/
	/*************FORMULÁRIO*************/
	/************************************/
	
	$("form input[type='submit']").css({"opacity": "0"});
	
	$("form").hover(function(){
		var button = $(this).find("input[type='submit']");
		button.stop().animate({"opacity":"1"}, 200);
	},function(){
		var button = $(this).find("input[type='submit']");
		button.stop().animate({"opacity":"0"}, 200);
	});
	
	$("form input[type='text'], form textarea").each(function(){
		if(typeof($(this).attr("value")) != "undefined"){
			$(this).data("placeholder", $(this).attr("value"));
		}else{
			$(this).data("placeholder", $(this).text());
		}
	});
	
	$("form input[type='text'], form textarea").focus(function(){
		if($(this).val() === $(this).data("placeholder")){
			$(this).val("");
			$(this).css({"color":"#202020"});
		}
	});
	$("form input[type='text'], form textarea").blur(function(){
		if($(this).val().length === 0){
			$(this).val($(this).data("placeholder"));
			$(this).css({"color":"#808080"});
		}
	});
	
	/************************************/
	/***********MISC FUNCTIONS***********/
	/************************************/
	
	function throwOverlay(time, opacity, callback){
	
		if(typeof(time) != "number")
			time = 500;
			
		if(typeof(opacity) != "number")
			opacity = 0.7;
		
		if(typeof(callback) != "function")
			callback = function(){};
		
		if($("#overlay").length === 0){
			$("body").append("<div id='overlay'></div>");
			$("#overlay").css("opacity", 0);
			$("#overlay").animate({"opacity": opacity}, time, callback);
		}
	}
	function removeOverlay(time, opacity, callback){
		if(typeof(time != "integer"))
			time = 100;
			
		if(typeof(opacity != "float"))
			opacity = 0.75;
		
		$("#overlay").animate({"opacity": "0"}, time, function(){
			$(this).remove();
		});
	}
	
});
