$.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

$.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

var soundEmbed = null;

function soundPlay(which)
    {
    if (!soundEmbed)
        {
        soundEmbed = document.createElement('embed');
        soundEmbed.setAttribute('src', '/beta/assets/files/'+which+'.mp3');
        soundEmbed.setAttribute('hidden', true);
        soundEmbed.setAttribute('autostart', true);
        }
    else
        {
        document.body.removeChild(soundEmbed);
        soundEmbed.removed = true;
        soundEmbed = null;
        soundEmbed = document.createElement('embed');
        soundEmbed.setAttribute('src', '/beta/assets/files/'+which+'.mp3');
        soundEmbed.setAttribute('hidden', true);
        soundEmbed.setAttribute('autostart', true);
        }
    soundEmbed.removed = false;
    document.body.appendChild(soundEmbed);
    }

var $jq = jQuery.noConflict();
$jq(document).ready(function($){  
  $(window).load(function(){
  
	  if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	  {
		   $('#login').css({
		   position: 'absolute',
		   left: '-100px',
		   textAlign: 'center'
		   });
	  };
	   
	  var refresh;
	  var repeat;
  
	  flashA = $.timer(30000,function(){
		  soundPlay('lightningbolt');
		  $('#bolt').fadeIn(100, function(){
			  $('#bolt').fadeOut(200, function(){
				  $('#bolt').fadeIn(100, function(){
					flashB = $.timer(300,function(){
					  $('#bolt').fadeOut(800).pngFix({blankgif: '/beta/assets/images/blank.gif'});
					});
				  }).pngFix({blankgif: '/beta/assets/images/blank.gif'});
			  }).pngFix({blankgif: '/beta/assets/images/blank.gif'});
		  }).pngFix({blankgif: '/beta/assets/images/blank.gif'});
	  });
  
	  function wiggleStart(){
		  refresh = setInterval(function() {
			 $('#spider').addClass('walk');
			 spiderWiggle = $.timer(100,function(){
			   $('#spider').removeClass('walk');
			 });
		  }, 200);
	  }
	  
	  function wiggleStop(){
		  clearInterval(refresh);
		  $('#spider').removeClass('walk');
	  }
  
	  spiderMove = $.timer(15000,function(){
		  wiggleStart();
		  $('#spider').show().animate({ 
			  top: "+=200px",
			  left: "-=20px"
		  }, 700, function(){
			  wiggleStop();
			  spiderPause = $.timer(1000,function(){
			  wiggleStart();
			  $('#spider').show().animate({ 
				  top: "-=200px",
				  left: "+=50px"
				  }, 300, function(){
					  wiggleStop();
					  $('#spider').hide();
					  $('#spider').css('left','32px');
				  });
			  });
		  });
	  
		  repeat = setInterval(function() {
			  wiggleStart();
			  $('#spider').show().animate({ 
				  top: "+=200px",
				  left: "-=20px"
			  }, 700, function(){
				  wiggleStop();
				  spiderPause = $.timer(1000,function(){
				  wiggleStart();
				  $('#spider').show().animate({ 
					  top: "-=200px",
					  left: "+=50px"
					  }, 300, function(){
						  wiggleStop();
						  $('#spider').hide();
						  $('#spider').css('left','32px');
					  });
				  });
			  });
		  }, 45000);
	  });
  
  	  var started = null;
  
	  $('#tix ul').hover(
	  function(){
	  started = 1;
	  $(this).animate({
		marginTop: '-=60'
		}, 200)
	  },
	  function(){
		if(started == 1){
		  $(this).animate({
			marginTop: '+=60'
			}, 400)
		}
		started = null;
	  });
	  
  });
});
