$(document).ready(function(){
	
	if (!$('body').hasClass('static')){
		$('#clipWrap').prepend('<div id="gallery"><a id="galleryToggle" href="#TBD">open gallery</a><div id="galleryContent"></div></div>');
		$('#galleryToggle').toggle(
			function() {
				$(this).blur();
				$('#gallery').animate({'height':'210px'},1000,null,function(){
					$('#galleryContent').load('/names/show.php',null,function(){
						$('#galleryContent').fadeIn('slow',function(){
							$('#galleryToggle').addClass('open');
						});
						placeNameHere.init();
						pageTracker._trackPageview('/names/show.php');
					})
				});
			},
			function() {
				$(this).blur();
				$('#galleryContent').fadeOut('slow',function(){
					$('#galleryContent').empty();
					$('#gallery').animate({'height':'70px'},1000,null,function(){
						$('#galleryToggle').removeClass('open');
					});
				});
			}
		);
	}
	if ($('body').hasClass('outdated')){
		$('#clipWrap').prepend('<div id="outdated"><p>NOTE: Some contents of this page may be outdated. Please use caution before resuing code samples or installing downloads.</p></div>');
	}
});


var placeNameHere = {
	form : null,
	init : function() {
		placeNameHere.form = $('#placeNameForm');
		if (placeNameHere.form) {
			placeNameHere.form.bind('submit',function(){
				if ($.trim($('#fname').attr('value')) != '') {
					var newName = $.trim($('#fname').attr('value'));
					var action = placeNameHere.form.attr('action');
					placeNameHere.form.parent().fadeOut();
					$.getJSON(action, {'fname' : newName}, function(data) {
						if (data.error) {
							placeNameHere.form.parent().fadeIn();
						} else {
							$('#galleryContent').append('<div id="newName" style=" display:none; position:absolute; left:12%; top:4%; color:#d50000; font-size:92px; z-index:1;">'+data.result+'</div>')
							$('#newName').fadeIn();
							pageTracker._trackPageview(action);
						}
					});
				}
				return false;
			});
		}
	},
	handle : function() {
		
	}
}

function initColumn() {
	var room = $("body").width() - 70 - 700 - 70;
	if (room >= 210) {
		$(("body")).addClass("multicol");
	} else {
		$(("body")).removeClass("multicol");
	}
}
$(document).ready(initColumn);
$(window).resize(initColumn);