jQuery(document).ready(function() {

	 setTimeout(function(){
		$('div#partner-popup-bg').fadeIn();
		$('div#partner-popup').fadeIn();
	}, 1000*30);
	
	$("#close-partner").click(
		function(){
			$('div#partner-popup').fadeOut();
			$('div#partner-popup-bg').fadeOut();
		}
	);
	
	$('#winners').cycle({
		fx: 'fade',
		timeout: 3000
	});
	
	$('.latestwinnersbox').cycle({
		fx: 'fade',
		timeout: 3000
	});
	
	$('#gamenews').cycle({
		fx: 'fade',
		timeout: 4000
	});
	
	$('div#rightbox').localScroll();
	
	$('div#particles').click(
		function() {
			window.location = "index.php";
		}
	);
	
	$('img#subpagedownloadbutton').hover(
		function() {
			$(this).stop().animate({ width:178, marginLeft:-5, marginTop:-2 }, 200);
		}
		,
		function() {
			$(this).stop().animate({ width:168, marginLeft:0, marginTop:0 }, 200);
		}
	);

	
	$("#gamesmenu a").click(
		function() {
			$.ajax({
				url : "games-gamecategory.php?game_category=" + $(this).attr("rel"),
				success : function (data) {
					$("#gamesinfo").fadeOut(100, function() { $(this).html(data).fadeIn(); } );
					$("#gamesinfo").trigger("update");
				}
			});
		}
	);
	
	$.ajax({
				url : "games-gamecategory.php?game_category=videoslots",
				success : function (data) {
					$("#gamesinfo").fadeOut(100, function() { $(this).html(data).fadeIn(); } );
					$("#gamesinfo").trigger("update");
				}
			});
	
	$("a.gamesidlink").live('click', function() {
			$.ajax({
				url : "games-gameinfo.php?game_id="+$(this).attr("rel"),
				success : function (data) {
					$("#gamesinfo").fadeOut(100, function(){ $(this).html(data).fadeIn(); } );
					$("#gamesinfo").trigger("update");
				}
			});
		}
	);
	
	$("ul#vipclasses li").hover(
		function(){
			var selector = $(this).attr("id");
			selector = selector.substr(3,3);
			$("div#vs_" + selector).fadeIn(300);
			$("div#vi_" + selector).show();
		}
		,
		function(){
			var selector = $(this).attr("id");
			selector = selector.substr(3,3);
			$("div#vs_" + selector).fadeOut(300);
			$("div#vi_" + selector).hide();
		}
	);
	
	$("span.promoreadmore").hover(
		function() {
			$(this).parent().parent().children(".promotooltip").fadeIn();
		}
		,
		function() {
			$(this).parent().parent().children(".promotooltip").fadeOut();
		}
	);
	
	$("div#floatingbox").floating();
	$("div#leftboxes").floating({
		targetX:"left"
	});
	
	$("div#closefloatingbox").click(
		function() {
			$("div#floatingbox").fadeOut();
		}
	);
	
	$("#instantplaybutton").popupWindow({ 		
		centerScreen: 1,
		width: 1000,
		scrollbars: 1
	});

	$("#downloadbottom").hover(
		function(){
			$(this).stop().animate({ 'width':'344px', 'margin-left':'-10px' });
		}
		,
		function(){
			$(this).stop().animate({ 'width':'324px', 'margin-left':'0px' });
		}
	);
	
	function trim(s) {
    s = s.replace(/(^\s*)|(\s*$)/gi,"");
   	s = s.replace(/[ ]{2,}/gi," ");
   	s = s.replace(/\n /,"\n");
   	return s;
  }
  
  function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
		
				$.ajax({
		      type: "GET",
      		url: "/public/jackpot-total",
      		success: function(xml) {
      		  xml = trim(xml);
      			xmlDoc = jQuery.parseXML(xml);
      			major = jQuery(xmlDoc).find('jackpot-total').attr('value');
            major = (major.replace(",",""));
            major = (major.replace(",",""));
            major = parseFloat(major);
            console.log(major);
            setInterval(function(){
              major = major + Math.random() * 2;
              //console.log(major);
              jQuery("#jackpot_ticker").html("$ " + addCommas(major.toFixed(2)));
              jQuery("#subpage_jackpot").html("$ " + addCommas(major.toFixed(2)));
            },1000);
    		  }
	      });
	
});	

