$(document).ready(function() {
    $('#navigation ul li:last a').css('padding-right', '0px');
    
    Cufon.replace('#splasher h1, #boxes h2, #submenu h2, #content h1, #content h2, #content h3');
    
    $('#submenu ul li:not(.active)').hover(function(){
        $(this).addClass('active');
    }, function(){
        $(this).removeClass('active');
    });
  $references = $('<div id="references"></div>');

  $('#boxes .layer .column-3 p').each(function(i){
    if(i % 2 && i != 0)
    {
      $ref = $('<div class="reference hidden"></div>');
      $(this).prev('p').appendTo($ref);
      $(this).appendTo($ref);
  
      $ref.appendTo($references);
    }
  });
  
  $recents = $('<div id="recents"></div>');
  
  $('#boxes .layer .column-2 a').each(function(i){
      $recent = $('<div class="recent hidden"></div>');
      $(this).attr('target','new').find('img').css({'margin-left':'-30px','margin-top':'-20px'}).end().appendTo($recent);  
   
      $recent.appendTo($recents);
  });
  
  $recents.find('.recent:eq('+Math.floor(Math.random()*$recents.find('.recent').size())+')').removeClass('hidden').end().appendTo($('#boxes .layer .column-2'));
  
  $references.find('.reference:eq('+Math.floor(Math.random()*$references.find('.reference').size())+')').removeClass('hidden').end().appendTo($('#boxes .layer .column-3'));
  $('#boxes .column-2 p').css('margin','0px');
  
  
  var hyphenatorSettings = {
    doframes: false,
    onhyphenationdonecallback: function() {
      $facebookLike = ('<iframe class="donthyphenate" src="http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FEcome%2F38815799356&amp;send=false&amp;layout=standard&amp;width=250&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=lucida+grande&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:80px;" allowTransparency="true"></iframe>');
      $('#footer-wrapper').append($facebookLike);
    }
  };
  Hyphenator.config(hyphenatorSettings);
  Hyphenator.run();
	
	
	$('a.dialog').click(function(){
		var url = $(this).attr('href');
		
		$.post(url+'?disableLayout=true', {}, function(response){
			
			$overlay = createOverlay();
			$dialog = createDialog();
			
			$dialog.find('#dialog > #dialog-content').html(response).end().find('#closeDialog').click(function(){ $overlay.remove(); $dialog.remove(); return false; });
			
			$overlay.click(function(){ $overlay.remove(); $dialog.remove(); });
			    
			$dialog.appendTo('body');
			$overlay.appendTo('body');
			
								
			$('#dialog').find('form').live('submit',function(){
			
				$.post(url+"?disableLayout=true", $(this).serialize(), function(r){
					$dialog.find('#dialog-content').html(r);
				});			
				
				return false;
			});

		});	
		return false;
	});
	
	function createOverlay()
	{
		$overlay = $('<div id="overlay"></div>');
		return $overlay;
	}
	
	function createDialog()
	{
		$dialog = $('<div id="dialog-wrapper"><div id="dialog"><a id="closeDialog" href="#"></a><div id="dialog-content"></div></div></div>');
		return $dialog;
	}
});

