// ************************************************
// *
// *	on DOM ready

jQuery.noConflict();
$j = jQuery;
$j().ready(function(){
  $j('#alrt').css('opacity',0).show();   // this should probably be done in the css.
  // if #wrap is present we're in the forum. because of the way phpbb3 handles templates the page initially renders without styles. this looks like shit so hide it for a second.
  window.setTimeout("$j('#wrap').css({display:'block'});",400);

  //alrt('Under Construction.');
  
  $j('.header .banner .nav li').click(
		function(){
      window.location = $j(this).find('a')[0].href;
      return false;
		}
  );
  
  // update the footer tweets
  $j.jsonp(
    {
      url: "http://search.twitter.com/search.json",
      data: 'q=citeupcom',
      callback: "callback",
      callbackParameter: "callback",
      success: function( json ) {
        
        var tweets  = json;
        var $tweets = $j( '.tweets' );
        for( var i=0; i<(tweets.results.length<4?tweets.results.length:4); i++ ){
          var tweet = tweets.results[i];
          var html  = '<div class="tweet">';
          html += '<img height="50" src="'+tweet.profile_image_url+'" class="profile-img">';
          html += '<p><span class="from"><a target="_blank" href="http://twitter.com/'+tweet.from_user+'">'+tweet.from_user+'</a></span>: '+tweet.text+'</p>';
          var myDate = new Date( tweet.created_at );
          var time_str = myDate.toLocaleString();
          html += '<span class="time">'+time_str+'</span>';
          html += '</div><div class="clear"></div>';
          $tweets.append( html );
          //dbug.log( tweet );
        }
      }
    }
  );
  
  // make sure the three columns in the footer are the same height
  var colheight = 0;
  $j('.footer .sections li').not('.footer .sections li ul li').each(
    function()
    {
      if( $j(this).height() > colheight ) colheight = $j(this).height();
    }
  )
  $j('.footer .sections li').not('.footer .sections li ul li').height( colheight+'px' );
  
  /*
  // clean the rss feed timestamps
  $j('.footer .sections li ul li .time').each(
    function()
    {
      var arr   = $j(this).html().split('T');
      var date  = arr[0];
      var time  = arr[1].split('-')[0];
      $j(this).html( date+' '+time );
    }
  )
  */
  
});
// ------------------------------------------------




// ************************************************
// *
// *	custom alerts

var tymer;function alrt( msg ){
  if( $j('body').find('#alrt').length ){
    $j('body').find('#alrt').remove();
    clearTimeout( tymer );
  }
  var bw = $j('body').width();
  $j('body').append( '<div id="alrt"></div>' );
  var aw = $j('#alrt').width();
  var ml = ((bw - aw)/2);
  $j('#alrt').css({marginLeft:ml+'px'});
  var str = '<p>';
      str += msg;
      str += '</p>';
  $j('#alrt').html( str );
  $j('#alrt').append( '<a class="close" onclick="$j(\'#alrt\').remove(); clearTimeout( tymer );">&nbsp;</a>' );
  $j('#alrt').css({opacity:0,display:"block"});
  $j('#alrt').animate({ opacity: 0.95}, 700 );  
  tymer = window.setTimeout("$j('#alrt').animate({opacity: 0}, 1500, function(){ $j(this).remove() } )",4000);
}
// ------------------------------------------------




// ************************************************
// *
// *	dbug.log functionality


dbug = {
	firebug: false, debug: false, log: function(msg) {},
	enable: function() { if(this.firebug) this.debug = true; dbug.log = console.debug; dbug.log('enabling dbug');	},
	disable: function(){ if(this.firebug) this.debug = false; dbug.log = function(){}; }
}
if (typeof console != "undefined") { // safari, firebug
	if (typeof console.debug != "undefined") { // firebug
		dbug.firebug = true; 
    dbug.enable();
    //if( window.location.href.indexOf("debug=true")>0 ) dbug.enable();
	}
}
// ------------------------------------------------




