$(function(){
			$('#slider').simpleslider();
			
			// Ad revolver.. client side, make a server side version.
			/*if(Math.round(Math.random()*10)>5){
				$('#whacklink').attr('href', 'http://features.peta2.com/zombies/Default.aspx?c=zom270zgb0611');
				$('#whackLarge').attr('src', '/images/ads/peta-270x125_02.gif');
			}
			
			if(Math.round(Math.random()*10)>5){
				$('#whacklinks').attr('href', 'http://features.peta2.com/zombies/Default.aspx?c=zom125zga0611');
				$('#whackSmall').attr('src', '/images/ads/peta-125x125_02.gif');
			}*/
			
			//Corners... really JS corners? Fix this eventually.
			$('.content-header').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
			$('.content-box').corner("round 5px").parent().css('padding', '1px').corner("round 5px");
			$('#slider-wrapper').corner("round 5px");
			$('#login-box').corner("round 5px");	
			$('#container-footer').corner("bottom round 10px");
			$('#inner-footer').corner("round 10px");
			$('.info').corner("round 5px");
			$('.header').corner("round 5px");
			$('#infect').corner("round 5px");		
			
			// dynamic rating system
			$('.info .outer-rating').mousemove(function(e){
						var x = e.pageX - $(this).offset().left,
							rating = Math.round(x / 20) * 20;
						 $(this).children('.temp-rating').width(rating);
			});
			
			$('.info .outer-rating').hover(function(){
				var currentRating = $(this).children('.inner-rating'),
					tempRater = $(this).children('.inner-rating').clone();
					
				tempRater.addClass('temp-rating').appendTo($(this));
				currentRating.hide();
			},function(){
				$('.temp-rating').remove();
				 $(this).children('.inner-rating').show();
			});
			
			$('.outer-rating').click(function(){
				var rating = Math.round($(this).children('.temp-rating').width()/20),
					game = $(this).attr('data-game'),
					title = $(this).attr('data-title');
					
				$.ajax({
					type: "POST",
					url: "/inc/getgames.php?field=rate",
					data: "score="+rating+"&game=" + game + "&title=" + title,
					async: false,
					success: function(result) {
						if(result !== ''){
							$('.inner-rating').width(result * 20);
							$('.score').hide().text('Score ' + result).fadeIn();
							$('.msg').text('Thank you for rating this item');
						}
						$('.temp-rating').remove();
						$('.inner-rating').fadeIn();
					},
					error: function(result) {
					alert(result);
						// error error!
					}
				});
			});
			
			
			// Play area and register stuff
				var playArea = $('#playarea'),
					register = $('#register');
				
				playArea.jqm({ajax: '/inc/showgame.php?g=' + $('a.playGame').attr('id'), trigger: 'a.playGame',
						target: $('#playarea div#hiddendiv'),
						modal: true,
						overlay: 90,
						onShow: function(h) {
						/* callback executed when a trigger click. Show notice */
						h.w.css('opacity',1).fadeIn( ); 
							// Ajax time
							$(document).everyTime(60000,function(i){
								jQuery.ajax({
								  url: "/inc/getgames.php?field=stillplaying&gid=" + $('a.playGame').attr('id'),
								  cache: false,
								  success: function(html){
									// Do nothing right now
								  }
								})
							})


						},

						onHide: function(h) {
						h.w.fadeOut("slow",function() { if(h.o) h.o.remove(); });
						jQuery.get('/inc/getgames.php?field=stillplaying&gid='+ 0);
						$(document).stopTime();
						}


				});
				// Horizontal center
				playArea.css({marginLeft : (playArea.width()/2)*(-1)});
				
				// Help link for users that cant see the games
				$('#playarea').delegate('#gameHelper', 'click', function(){
					var gameContent = $('.gameObject');
					playArea.jqmHide();
					$('.playGame').replaceWith(gameContent);	
					
					$(document).everyTime(60000,function(i){
						jQuery.ajax({
						  url: "/inc/getgames.php?field=stillplaying&gid=" + $('a.playGame').attr('id'),
						  cache: false,
						  success: function(html){
							// Do nothing right now
						  }
						})
					})
				});
				
				register.jqm({ajax: '/register.php', trigger: 'a.registerlink',
								target: $('#register div#registerhidden'),
								modal: true,
								overlay: 80,
								onShow: function(h) {
								/* callback executed when a trigger click. Show notice */
								h.w.css('opacity',1).fadeIn( ); 
								},
								
								onHide: function(h) {
									h.w.fadeOut("slow",function() { if(h.o) h.o.remove(); });
								}
				});
				
				// Horizontall center
				register.css({marginLeft : (register.width()/2)*(-1)});

});
	
