//
// GA LOTTERY SITE JQUERY FILE
//
// This is the full, uncompressed version of the site JS file.  Please minify and SAVE AS site.jquery.js before publishing.
// Also, please be sure to save & commit the master file (this file) so we can track changes.
//

var win=null;
function printIt(printThis)
{
	win = window.open();
	self.focus();
	win.document.open();
	win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
	win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
	win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
	win.document.write(printThis);
	win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
	win.document.close();
	win.print(); 
	win.close();
}


$(function() {

	function beforeTrans() { /* next image loaded, change sidebar */
		var theImgNum = $(this).children().attr('class');
		$('#flashright a').removeClass('active');
		$('#flashright a.' + theImgNum).addClass('active');
		$('#flashright a').animate({backgroundPosition:"(-347 0)"}, {duration:500});
		$('#flashright a.' + theImgNum).animate({backgroundPosition:"(0 0)"}, {duration:500});
	};

	//noflash cycle
	if ($('#noflash').length) { // implies *not* zero
		$('#flashleft a:nth-child(1) img').addClass('one');
		$('#flashright a:nth-child(1)').addClass('one');
		$('#flashleft a:nth-child(2) img').addClass('two');
		$('#flashright a:nth-child(2)').addClass('two');
		$('#flashleft a:nth-child(3) img').addClass('three');
		$('#flashright a:nth-child(3)').addClass('three');
		$('#flashleft a:nth-child(4) img').addClass('four');
		$('#flashright a:nth-child(4)').addClass('four');

		$('#flashleft').cycle({ 
				fx:		 'cover',
			    before:   beforeTrans,
    			timeout:  5000 
		 });
		 
		$('#flashright a.one').click(function(){ $('#flashleft').cycle(0); return false; });
		$('#flashright a.two').click(function(){ $('#flashleft').cycle(1); return false; });
		$('#flashright a.three').click(function(){ $('#flashleft').cycle(2); return false; });
		$('#flashright a.four').click(function(){ $('#flashleft').cycle(3); return false; });		 
	}
  
	
  	// when hovering over 'games'
	$('#nav .itemgames').hover(function() { //itemgames = games li class
 		$('#nav-drop').css("display", "block");
 		$('#nav .itemgames').addClass('navdrop'); 
 		return false;
 	}, function(){
 		$('#nav-drop').css("display", "none");
 		$('#nav .itemgames').removeClass('navdrop'); 
 	}); 
 	
	// when hovering over the 'games' drop down
	$('#nav-drop').hover(function() {
 		$('#nav-drop').css("display", "block");
 		$('#nav .itemgames').addClass('navdrop'); 
 		return false;
 	}, function(){
 		$('#nav-drop').css("display", "none");
 		$('#nav .itemgames').removeClass('navdrop'); 
 	});
 	
 	// display & hide home popup
 	$('.i_logo').hover(function(){
 		$('#home-popup').css("display", "block");
 		return false;
 		}, function(){
 		$('#home-popup').css("display", "none");
 	});
	
	// clears search box
	$('#wheretoplay').focus(function(){
		if(this.value=='Where to play (enter zip code)'){
			this.value='';
		}
	});
	
	// puts message back if no data...
	$('#wheretoplay').blur(function(){
		if ( this.value == '' || this.value == null )
			this.value = 'Where to play (enter zip code)';
	});
	
	// hover for featured games on home page
		$('.banneritem_gamebox, .winners-wrap').hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			});
						
    // setup ul.tabs to work as tabs for each div directly under div.panes 
    $("ul.tabs").tabs("div.panes > div"); 

	// stripes for tables
  	$("#top-prizes-table tr:even").addClass("odd");
  	$("#ending-games-table tr:even").addClass("odd");


	// lotterybar
	if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
		//is ie6
	}else{
		var page = $('body').attr("id");
		 if (page == ('home')) {
			 $('#lotterybar').css("display", "block");
			 $('.numbers').addClass('active');
		 };		
	}
	
	$('#lotterybar-min a').click(function() {
		if($(this).hasClass('active')){ //if the current button is already clicked
		$('#lotterybar').slideToggle(); //slide down
	    $('#lotterybar-min a').removeClass('active'); //remove the active class
		return false;	
	}else if($('#lotterybar-min a').hasClass('active')){ //if any button is already clicked, leave the bar up
		currentUp = $(this).attr("id"); //finds the lb attribute that relates to the id of the lotterybar sidebar
		$("#lotterybar-left ul").css("display", "none"); //hides all sidebar items
		$("#"+currentUp+"-show").css("display", "block"); //shows current sidebar
		$('#lotterybar-min a').removeClass('active'); //remove the active class from everything
		$(this).addClass('active'); //adds the active class to the clicked item
		return false;
	}else{ //animate the opening
		currentUp = $(this).attr("id"); //finds the ld attribute that relates to the id of the lotterybar sidebar
		$("#lotterybar-left ul").css("display", "none"); //hides all sidebar items
		$("#"+currentUp+"-show").css("display", "block"); //shows current sidebar
		if($(this).attr('class')=='info'){ //ie6 fix - if the bar is down by default, hide items that need to be hidden.
    		$('#lotterybar-left, #lottery-numbers-box').css("display", "none");
    		$('#lotterybar-right').addClass('helpbox');
		}
	    $('#lotterybar').slideToggle(); //slide up
	    $('#lotterybar-min a').removeClass('active'); //remove 'active' from everything
    	$(this).addClass('active'); //adds active class to the clicked item
    	return false;
	}
	
    });
    
    // hide and show for each lottery bar section
    $('.numbers').click(function(){
    	$('.show-right').css("display", "none");
    	$('#lotterybar-right').removeClass('helpbox');    	
    	$('#lottery-numbers-box, #lotterybar-left').css("display", "block");
    	
    });
    $('.info').click(function(){
    	$('.show-right, #lotterybar-left').css("display", "none");
    	$('#lotterybar-right').addClass('helpbox');
    	$('#player-info-box').css("display", "block");
    });
    $('.club').click(function(){
    	$('#lotterybar-left').css('display', 'block');
    	$('#lotterybar-right').removeClass('helpbox');    	    	
    	var _sDiv = 'div#players-club-box';
    	var _sRel = $('div#players-club-box-logged-in').attr('rel');
   		if ( _sRel ) {
   			_sDiv += '-logged-in';
   			$('#players-club-user-name').html(_sRel);
		}
    	$('.show-right').css("display", "none");
		$(_sDiv).css("display", "block");
		$('.close a').css("color", "#fff");
    });
    
   // close button function
	$('.close a').click(function() {
		$('#lotterybar').slideToggle(); //slide down
	    $('#lotterybar-min a').removeClass('active'); //remove the active class
	});
    
	// lottery clicks disabled
	$('#lotterybar-min a , .close a').click(function(){
		return false;
	});


	// Jackpot slideshow text in header
	if($('.jackpot-scroll').length>0) {
	    $('.jackpot-scroll').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}

	//tooltip for games hover
	$('#games #interior-left-content .game').hover(function(){
  		var pos = $(this).offset();  //finds the position of the item
  		var width = $(this).width(); //finds the width of the item
		var theTitle = $("a", this).attr("title"); //find the title
  		var theLink = $("a", this).attr("href"); //find the url
  		var popText = $("div.game-pop", this).html();
  		var posLeft = (212 - width) * .4; 
  		$("#tool-tip").css( { "left": (pos.left - posLeft) + "px", "top":(pos.top - 100) + "px", "display" : "block" } );
		$("#tool-tip").html("<h2>"+ theTitle + "</h2><p>" + popText + "</p><p class=\"hidie\"><a href=\"" + theLink + "\">View Game</a>");
	}, function(){
		$('#tool-tip').css("display", "none");	
	});
		
	// main tool tip code
	$('#tool-tip').hover(function(){
		$(this).css("display", "block");
	}, function(){
		$(this).css("display", "none");
	});

	//newsfeed 
	
	if($('#newsfeed-scroll').length>0) {
	    $('#newsfeed-scroll').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	};
	
	//**************************************************************************************
	// Instant Tickets App needs

	if($('#detailtext').length>0) {
		$("#detailtext a.odds").fancybox();
	}
	
	$('#instantheader ul li a').click(function(){ // sidebar filter
		$('#loading').show();
		$('#instantheader ul li a').removeClass('current');		
		$('#gamelist ul li a').removeClass('current');		
		
		theprice = $(this).attr('class');
		landingpage = $(this).attr('href');
		
		$(this).addClass('current');
		$('#gamecontainer').load(landingpage+'?ajax=1 #gamecontent', function(){
			$('#loading').hide();
			
			$('a.landingpage').click(function(){
				$('#loading').show();	
				thelink = $(this).attr('href');
				$('#gamecontainer').load(thelink + '?ajax=1 #gamecontent', function(){
					$('#loading').hide();		
					$("#detailtext a.odds").fancybox(); //enables fancybox
				}); //loads the link & only the '#gamecontent' div				
				return false;		
			});
			
		}); //landing page url scheme
		
		if(theprice == 'all') {
			$('#gamelist ul li').show();
		} else {
			$('#gamelist ul li').hide();
			$('#gamelist ul li.' + theprice).show();
		}
		return false;
	});	

	$('#gamelist ul li a').click(function(){ // loads the game in the right pane
		$('#loading').show();	
		thelink = $(this).attr('href');
		$('#gamelist ul li a').removeClass('current');
		$(this).addClass('current');
		$('#gamecontainer').load(thelink + '?ajax=1 #gamecontent', function(){
			$('#loading').hide();		
			$("#detailtext a.odds").fancybox(); //enables fancybox
		}); //loads the link & only the '#gamecontent' div
		return false;
	});
	
	$('a.landingpage').click(function(){
		$('#loading').show();	
		thelink = $(this).attr('href');
		$('#gamecontainer').load(thelink + '?ajax=1 #gamecontent', function(){
			$('#loading').hide();
			$("#detailtext a.odds").fancybox(); //enables fancybox
		}); //loads the link & only the '#gamecontent' div
		return false;		
	});
	


	// End Instant Tickets
	//**************************************************************************************
});
