var cnav, originalColor;

var funDialog, content;

$(document).ready( function(){ 
   mouseposition = {x: $(window).width() /2, y: $(window).height() /2 };

   //originalColor = $("body").css("background-color"); 
   originalColor = "#000";

   //debug.log( "ready:" );
   //debug.log( originalColor );


   $(document).mousemove( function(event) { 
      mouseposition = {x: event.pageX, y: event.pageY};  
   } );

   /* Three.js */
   init();
   animate();

   // Adding timeout so things get position'd properly.
   /* 
   window.setTimeout( function() { 
      var responder = $("<div></div>") 
          .attr("id", "responsecontainer" ) 
          .append( "<div>Hello</div>" ) 
          .appendTo( $("body") )
          .position( { 
            my: "left bottom",
            at: "left top",
            of: "#dycommand" 
          });
   
      cnav = new ConsoleNav( "#dycommand", "#responsecontainer" );   

   }, 10 );
   */
	$("#command").focus();
   content = new basicdialog( 'main', $('#main') );    

}); 

function fun(){
  if( typeof funDialog == 'undefined' ) { 
      funDialog = new basicdialog( 'funDialog' );
      funDialog.content( "Fun:<br /><a href='javascript:color()'>color</a><br /><a href='javascript:pretty()'>pretty</a><br /><a href='javascript:log()'>log</a>" );
  }    
  
  if( funDialog.hidden )
  { 
      funDialog.show();
  } else { 
      funDialog.hide();
  } 
}

function pretty(){ 
		//this.response( "Why thank you! You are pretty too!" );
      logResponder( "Pretty Animation." ); 
		var jqBody = $('body');
		jqBody.animate( { backgroundColor: '#F99' }, 500, 
                         function(){
                              //debug.log( "Fadeout:");
                              //debug.log( originalColor );
                              jqBody.animate( { backgroundColor: originalColor } , 1000)
                                    .dequeue();
                         })
            .dequeue();

}

function color(){

      var color_3d = Math.random() * 0xFFFFFF;

      //this.response( "How about this color?" );
      logResponder( "New Logo Color: 0x" + (Math.floor(color_3d)).toString(16) );
      material_solid.color.setHex(color_3d);
      material_wire2.color.setHex(color_3d);


}

var logDialog;
var logResponder = function(){ };
function log (){ 

  if( typeof logDialog == 'undefined' ) { 
      logDialog = new basicdialog( 'logDialog' );
      logDialog.content( $("<div id='logResponder'></div>") );
      logResponder = new Responder( '#logResponder', 3, 100 );
  }    

  if( logDialog.hidden )
  { 
      logDialog.show();
  } else { 
      logDialog.hide();
  } 
}

var resumeDialog;
function resume(){ 

  if( typeof resumeDialog == 'undefined' ) { 
      resumeDialog = new basicdialog( 'resumeDialog', $('#resumeDialog') );
      $('#resumeDialog .close').click( function(e){ resumeDialog.hide() } );
  }    

  if( resumeDialog.hidden )
  { 
      resumeDialog.show();
  } else { 
      resumeDialog.hide();
  } 
}

