$(function(){

    var backgroundColors = Array(
        "#d76204",
        "#b53333",
        "#563577",
        "#2b882b",
        "#437fc9",
        "#222222",
        "#03938b",
        "#339303",
        "#927800",
        "#255569",
        "#682222",
        "#68410f",
        "#727108",
        "#6f6e30",
        "#4c5c46",
        "#3e494f",
        "#3d496b",
        "#433654",
        "#306266",
        "#34397a",
        "#4a2897",
        "#5c3b61",
        "#631e3d",
        "#967100"
    );
    
    var totalColors = backgroundColors.length;
    var randomColorPick = Math.floor(Math.random()*totalColors);
        
    $("body").css("background-color", backgroundColors[randomColorPick]);
    
    
    
    $("#submit")
        .data("state","closed")
        .click(function(){
    
            if ($(this).data("state") == "closed") {
            
                $("#lyric, #demo-area").slideUp(500, function() {
                
                    $("#submit-lyric-area").slideDown(500);
                    $("#submit").data("state","open");
                
                });
            
            } else {
            
                $("#submit-lyric-area").slideUp(500, function() {
                
                    $("#lyric").slideDown(500);
                    $("#submit").data("state","closed");
                
                });
            
            }
            
            return false;
        
    });
    
    $("#view-demo-button")
        .data("state","closed")
        .click(function(){
    
            if ($(this).data("state") == "closed") {
            
                $("#lyric, #submit-lyric-area").slideUp(500, function() {
                
                    $("#demo-area").slideDown(500);
                    $("#view-demo-button").data("state","open");
                
                });
            
            } else {
            
                $("#demo-area").slideUp(500, function() {
                
                    $("#lyric").slideDown(500);
                    $("#view-demo-button").data("state","closed");
                
                });
            
            }
            
            return false;
        
    });
        
    $("#lyric_text").charCounter(160, {
		format: "(%1)",
		container: "#lyric-character-counter"
	});
	
	$("#flag-button").click(function() {
	
	   var theID = $(this).attr("rel");
	   
	   $("#flag-image").attr("src", "/images/flag_on.png");
	   
	   $.ajax({
			type: "GET",
			url: "/lyrics/flag/" + theID
		});	   
	   	   
	   return false;
	
	});
	
    /* $("#another").click(function(){
	
	
		$("#lyric").load("/ #lyric", {}, function(){
			
			
		});
		
		return false;
		
	}); */

});