$(function(){
	
	/**
	 * DEFAULTS
	 **/
	
	// Alert/Flash Message
	setTimeout(hideAlert,4000);
	$("#alert-message").click(function(){
	    hideAlert();
	});
	function hideAlert(){
	    if ($("#alert-message")[0]) { $("#alert-message").slideUp('fast'); }
	}
	
	// END
	
	// Dropdown Nav Main
	$(".sub-nav").hide();
	
	$("ul#nav-main > li").hover(function(){
        $('div:first',this).css("display", "block");
        
    }, function(){	
        $('div:first',this).css("display", "none");
    });
    
	//hack ie for z-index
    var zIndexNumber = 1000;
    $('div').each(function() {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
    });
    
    /* Values Patterns Forms */
	$('form.values-hide input[type="text"], form.values-hide input[type="password"], ').each(function(index) {
		var valor_previous = $(this).val();
		$(this).focusin(function() {
			var self = $(this);
			var valor = self.val();
			if(valor == valor_previous){
				self.val("");
			}

		}).focusout(function() {
			var valor = $(this).val();
			if(valor == ''){
				$(this).val(valor_previous);
			}
		});
	});
	/* End Values Patterns Forms */
	
	/* Twitter */
	$(".tweet").tweet({
		join_text: "auto",
		username: "portomusical",
		avatar_size: 40,
		count: 3,
		auto_join_text_default: "", 
		auto_join_text_ed: "we",
		auto_join_text_ing: "we were",
		auto_join_text_reply: "we replied",
		auto_join_text_url: "we were checking out",
		loading_text: "loading tweets..."
	});
    /* End Twitter */
  	var val = $("#form-newsletter").jcheck({language: 'pt-br'});
    val.validates("name", "address_city", {presence: true});
    val.validates("email", {format: {"with": "email", message: "Utilize um e-mail válido."}});
    
    
  	var v = $("#form-contact").jcheck({language: 'pt-br'});
    v.validates("name", "message", {presence: true});
    v.validates("email", {format: {"with": "email", message: "Utilize um e-mail válido."}});
    
    /* Target Blank */ 
	$('.target-blank').click(function(){
        $(this).attr('target', '_blank').click();
        return false;
    });
    /* End Target Blank */
    
});
