$(function(){

    var attachNavEvents = function(parent, myClass) {
        jQuery(parent + " ." + myClass).hover(function() {
            jQuery(this).before('<div class="nav-' + myClass + '" style="display:none"></div>');
            jQuery("div.nav-" + myClass).fadeIn(300);
        },function() {
            jQuery("div.nav-" + myClass).fadeOut(300, function() {
                jQuery(this).remove();
            });
        });
    };
    var current = jQuery("#nav").attr("class").substr(8);
	jQuery("#nav > li:not(." + current + ") > a").css({backgroundImage:"none"});
	attachNavEvents("#nav", "home");
	attachNavEvents("#nav", "blog");
	attachNavEvents("#nav", "studio");
	attachNavEvents("#nav", "tour");
	attachNavEvents("#nav", "music");
	attachNavEvents("#nav", "about");
	attachNavEvents("#nav", "and-friend");
	attachNavEvents("#nav", "contact");
    
    jQuery("#banner")
        .after("<div id='signup'><div class='message'>Find out about upcoming shows and special events. No spam, guaranteed.</div><form method='post' action='/maillist/' id='signupdropdown'><label for='email' class='email'>email:</label><input type='text' name='email' class='email' /><button type='submit'>Sign me up!</button></form><a href='#' class='close'>close [x]</a><div class='errors hide'></div></div>")
        .children("a")
        .click(function(){
            var el = jQuery("#signup");
            if(parseInt(el.css("top"), 10) < 0){
                el.animate({
                    top:0
                });
                jQuery("#signup .email").focus();
            }
            else{
                el.animate({
                    top:'-200px'
                });
            }
            return false;
        });
    
    jQuery("#signup .close").click(function(){
        jQuery("#signup").animate({
            top:'-200px'
        });
        return false;
    });
    jQuery("#signupdropdown").validate({
		rules:{
			email:{required: true, email:true}
		},
        messages:{
            email:{
                required: "we need your email!",
                email: "that email doesn't look quite right..."
            }
        },
		errorPlacement: function(error, element) {
			jQuery("#signup div.errors").html(error).show();
		}
	});
    jQuery("#signupform").validate({
		rules:{
			email:{required: true, email:true}
		},
        messages:{
            email:{
                required: "we need your email!",
                email: "that email doesn't look quite right..."
            }
        },
		errorPlacement: function(error, element) {
			jQuery("#main div.errors").html(error).show();
		}
	});
    
    jQuery("#player").click(function(){
        var newwindow = window.open('/player',"name","height=345,width=450,location=no,resizeable=no,menubar=no,status=no,toolbar=no");
        if (window.focus) {newwindow.focus();}
        return false;
    });
});
