function attachNavEvents(parent, myClass) {
    jQuery(parent + " ." + myClass).mouseover(function() {
        jQuery(this).before('<div class="top-nav-' + myClass + '"></div>');
        jQuery(".top-nav-" + myClass).css({display:"none"}).fadeIn(200);
    }).mouseout(function() {
        jQuery(".top-nav-" + myClass).fadeOut(200, function() {
            jQuery(this).remove();
        });
    });
}

jQuery(function(){
	jQuery(".top-nav").children("li").each(function() {
	    var current = "top-nav current-" + (jQuery(this).attr("class"));
	    var parentClass = jQuery(".top-nav").attr("class");
	    if (parentClass != current) {
	        jQuery(this).children("a").css({backgroundImage:"none"});
	    }
	});
    jQuery.ajax({
        type: "POST",
        url: "/quotes",
        dataType:"html",
        data:{'type':'ajax'},
        success: function(data){
            function Quotes(quote_array){
                quotelist = quote_array;
                index = 0;
                function next(){
                    var quote = quotelist[index];
                    if (index == quotelist.length - 1){index=0;}
                    else{index++;}
                    return quote;
                }
                function rotate(){
                    jQuery('#quotator').animate({opacity:0}).queue(function(){
                        jQuery(this).html(next());
                        jQuery(this).dequeue();
                       }).animate({opacity:1});
                }
                this.timer = function(){
                    rotate();
                    setInterval(rotate, 4000);
                }
            };
            var quote_list = [];
            jQuery(data).each(function(){
                if (this.tagName == 'p' || this.tagName =='P'){quote_list.push(jQuery(this).text());}
            });
            var quotes = new Quotes(quote_list);
            jQuery(".whatsnew").prepend("<div id='quotator'></div><hr/>");
            quotes.timer();
        }
    });
	attachNavEvents(".top-nav", "twr");
	attachNavEvents(".top-nav", "sign-up");
	jQuery(".subtext").removeClass().hide().parent().hover(
		function(){$(this).children("span").stop(true, true).css({textIndent:"-500px"}).show().animate({textIndent:"0px"});},
		function(){$(this).children("span").fadeOut();});
});