		  
	$(document).ready(function(){ 
	
		// Document ready
		
		/*
		ypos = 0;
		ypos = $('#navigation').offset().top;
		
$(window).scroll(function () { 
      scroll = $(window).scrollTop();
      if (scroll > ypos-27) {
      	$('#navigation').addClass('stick');
      } else {
      	$('#navigation').removeClass('stick');
      }
      
    });
    
    */
    
    
    
    
    	// Create
    	
    	
    	$('#create_controls select').change(updatePreview);
    	$('#create_controls textarea').bind('keyup', updatePreview);
    	
    	$('#template img').load(function() {
  			$('#template #updating').fadeOut('fast');
		});
    	
    	function updatePreview() 
    	{
    	
    		
    		form = $('#create_controls');
    		img = $('#template img');
    		
    		$('#template #updating').fadeIn('fast');
    		
    		slug		 	= form.find('input[name="slug"]').val();
    		top_caption 	= form.find('fieldset#top textarea[name="top_caption"]').val();
    		top_size 		= form.find('fieldset#top select[name="top_size"]').val();
    		bottom_caption 	= form.find('fieldset#bottom textarea[name="bottom_caption"]').val();
    		bottom_size 	= form.find('fieldset#bottom select[name="bottom_size"]').val();
    		width			= img.attr('width');

    		
    		url = "preview/?slug="+slug+"&top_caption="+top_caption+"&top_size="+top_size+"&bottom_caption="+bottom_caption+"&bottom_size="+bottom_size+"&width="+width;
    		

    		img.attr('src', url);
    		
    	}
    	
    	
    	$('#captioner_submit').click(function(){
    		//event.preventDefault();
    		lolCheck = $.trim($('#lol_check').val()).toUpperCase();
    		if (lolCheck == 'LOL')
    		{
    			return true;
    		}
    		else
    		{
    			$('#lol_instructions').animate({color:"#F33381"},250);
    			$('#lol_instructions').animate({color:"#FFFFFF"},250);
    			return false;
    		}
    	});
    	
    	
    	
    	////
    	
    	
    	
    	
    	
    
   		 // Menu stuff
		
	    $('ul.sub').parent().addClass('drop');
	    
	    $('ul#navigation li').hover(
	    
	    	function() 
	    	{
	    		
	    		if ($(this).hasClass('drop')) 
	    		{
	    			$(this).addClass('active');
	    			$(this).find('ul.sub').css('display', 'block');
	    			$(this).addClass('open');
	    		}
	    	
	    	
	    	}
	    	,
	    	
	    	function() 
	    	{
	    		
	    		if ($(this).hasClass('drop')) 
	    		{
	    			$(this).removeClass('active');
	    			$(this).find('ul.sub').css('display', 'none');
	    			$(this).removeClass('open');
	    		}
	    	
	    	}
	    	
	    );




		////// Votes
		
		$('.votes a').click(function(e) 
		{
		
			e.preventDefault();
			
			anchor = $(this);
			url = $(this).attr('href');
			
			
			$.get(url, function(data, url) {

				anchor.parent().find('.count').html($.trim(data));
				
			});

		});
    
    
			    
	});
	
