$(document).ready(function() {
  if (parent != self)
      top.location.href = document.location.href;
  $("#noJS").css('display', 'none');
  $("#bar").css('display', 'block'); 
  $("#mainframe").css('display', 'block');

  $('.gremlins').each(function() {
         $(this).mouseover(function() {
         $(this).css('display', 'none');
         show_gremlin();
      });
  });
  show_gremlin();

  $('#shortlink').focus(function() {
    $(this).select();
  });
  
  $('#pulltab').click(function() {
	if($('#bar').css('left') == '-300px') {
		$('#bar').animate({ left: '0px' }, 200);
		pos=1;
	}
	else {
		$('#bar').animate({ left: '-300px' }, 200);
	}
  });
  
  $('#bar-title').click(function() {
	  top.location.href = 'http://therebegremlins.com';
  });
  $('#bar-gremlin').click(function() {
	  top.location.href = 'http://therebegremlins.com';
  });
  
  $('#bar-gremlinize').click(function() {
	  top.location.href = 'http://therebegremlins.com/' + $('#urlfield').val();
  });
  
  $('#bar-tweet').click(function() {
	  top.location.href = 'http://twitter.com/home?status=' + $('#shortlink').val();
  });
  
  $('#bar-killall').click(function() { 
	  url = new String(window.location);
	  top.location.href = 'http://' + target;
  });

});

function show_gremlin() {
  var gremlinNo = '#gremlin' + Math.floor(Math.random()*6);
  $(gremlinNo).css('position', 'absolute');
  $(gremlinNo).css('top', Math.floor(Math.random()*($(window).height()-300)));
  $(gremlinNo).css('left', Math.floor(Math.random()*($(window).width()-300)));
  $(gremlinNo).css('display', 'block');
}
