$(function() {
	
	
	
	//FIX's//////////////////////////////////////////
	
	$(document).pngFix();
	
	if($.browser.msie && $.browser.version=="6.0" || $.browser.msie && $.browser.version=="7.0"){
		$("#SliderNavContainer").css("margin-top",0+"px");
	};
	
	
	
	
	//HOMEPAGE SUBMISSION
	var origValue = $("#indexDropdown").val();
	$("#sendGame").attr('value', origValue);
	
	$("#indexDropdown").change(function(){ 
		var selectValue = $(this).val();
		$("#sendGame").attr('value', selectValue);
	}); 
	
	
	
	//SLIDER/////////////////////////////////////////////////////
	
	var hideAll = function(){$("#indexSlider .slide, .sliderCounterContainer").hide();};
	
	var startSlider = function(){
		$("#indexSlider #slide1").show();
		$("#indexSlider #contain1").show();
	};
	
	hideAll();
	startSlider();
	
	
	
	//NAV SLIDER//////////////////////////////////////////////////
	
	$("#SliderNavContainer").jSlide({			  
	  width: 459,
	  height: 52,
	  items: 3,
	  previous: ".leftArrowAnchor",
	  next: ".rightArrowAnchor",
	  easing: "swing",
	  loop: true,
	  speed: 800,
	  direction: 'horizontal'
	});
	
	
	//LIST OF SLIDES TO ANIMATE///////////////////////////////////
	
	if($.browser.msie){
		$("#indexSlider #s1").live('click', function(e){
			hideAll();
			$("#indexSlider #slide1, #indexSlider #contain1").show();
			return false;
		});
		
		$("#indexSlider #s2").live('click', function(e){
			hideAll();
			$("#indexSlider #slide2, #indexSlider #contain2").show();
			return false;
		});
		
		$("#indexSlider #s3").live('click', function(e){
			hideAll();
			$("#indexSlider #slide3, #indexSlider #contain3").show();	
			return false;
		});
		
		$("#indexSlider #s4").live('click', function(e){
			hideAll();
			$("#indexSlider #slide4, #indexSlider #contain4").show();
			return false;
		});
		
		$("#indexSlider #s5").live('click', function(e){
			hideAll();
			$("#indexSlider #slide5, #indexSlider #contain5").show();
			return false;
		});
		
		$("#indexSlider #s6").live('click', function(e){
			hideAll();
			$("#indexSlider #slide6, #indexSlider #contain6").show();
			return false;
		});
		
		$("#indexSlider #s7").live('click', function(e){
			hideAll();
			$("#indexSlider #slide7, #indexSlider #contain7").show();
			return false;
		});

	}else{
		$("#indexSlider #s1").live('click', function(e){
			$("#indexSlider .slide, .sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide1, #indexSlider #contain1").stop().show().animate({opacity: 1},500);
			});
			return false;
		});
		
		$("#indexSlider #s2").live('click', function(e){
			$("#indexSlider .slide,.sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide2, #indexSlider #contain2").stop().show().animate({opacity: 1},500);
			});
			return false;
		});
		
		$("#indexSlider #s3").live('click', function(e){
			$("#indexSlider .slide, .sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide3, #indexSlider #contain3").stop().show().animate({opacity: 1},500);	
			});
			return false;
		});
		
		$("#indexSlider #s4").live('click', function(e){
			$("#indexSlider .slide, .sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide4, #indexSlider #contain4").stop().show().animate({opacity: 1},500);
			});
			return false;
		});
		
		$("#indexSlider #s5").live('click', function(e){
			$("#indexSlider .slide, .sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide5, #indexSlider #contain5").stop().show().animate({opacity: 1},500);
			});
			return false;
		});
		
		$("#indexSlider #s6").live('click', function(e){
			$("#indexSlider .slide, .sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide6, #indexSlider #contain6").stop().show().animate({opacity: 1},500);
			});
			return false;
		});
		
		$("#indexSlider #s7").live('click', function(e){
			$("#indexSlider .slide, .sliderCounterContainer").stop().animate({opacity: 0},500, function(e){
				hideAll();
				$("#indexSlider #slide7, #indexSlider #contain7").stop().show().animate({opacity: 1},500);
			});
			return false;
		});
	}
	
	
	
	
	//HOW TO PLAY TABS//////////////////////////////////////////////////
	
	
	$("#htOne").live('click', function(e){
									   
		$("#htTwo").removeClass('howToSelected');
		$(this).addClass('howToSelected roundCorners');
		
		//Clear div and add data
		$("#howToPlayMain").empty();
		$("<ul><li><h3>Step 1</h3><h4>Select a <span>PRIZE</span></h4></li><li><h3>Step 2</h3><h4>Enter your <span>GUESS</span></h4></li><li><h3>Step 3</h3><h4>Lowest &amp; <span>UNIQUE</span> guess <span>WINS</span></h4></li></ul><p id='htpOnline'><img src='/images/howToPlayOnline.jpg' width='900' height='178' alt='How To Play Online' /></p><p id='htpCreateProfile'><a href='/createprofile.html'>CLICK HERE TO PLAY GRANDPRIZE.COM ONLINE<a/> (No purchase necessary)</p><span class='clear'></span>").appendTo("#howToPlayMain")
		
		return false;
	
	});
	
	$("#htTwo").live('click', function(e){
									   
		$("#htOne").removeClass('howToSelected');
		$(this).addClass('howToSelected roundCorners');
		
		//Clear div and add data
		$("#howToPlayMain").empty();
		$("<ul><li><h3>Step 1</h3><h4>Text <span>PRIZES</span> to <span>41729</span> for a list of current games</h4></li><li><h3>Step 2</h3><h4>Text the designated <span>KEYWORD</span> &amp; your <span>GUESS</span> to <span>41729</span></h4></li><li><h3>Step 3</h3><h4>Receive txt msg with games status</h4></li><span class='clear'></span></ul><p id='htpPhones'><img src='/images/htpPhones.jpg' alt='' width='806' height='304' /></p>").appendTo("#howToPlayMain")
		
		return false;
		
	});
		
		
	
	//GAMES ROW STRIPING//////////////////////////////////////////////////
		
	$('#gamesContainer #gMain table tr').filter(':odd').addClass('rowStripe');
	
	
	
	//GAMES MODAL PANEL//////////////////////////////////////////////////
	 
		// Error Checking
		var success = $("#submissionMessage").text();
		
		if(success==""){
			$("#submissionMessage").hide();
		}else{
		}
		
		$('#gamesContainer .LV_invalid, #gamesContainer #submissionMessage').delay(2000).fadeOut(1200);
		
		
		
		// Functionality
		$("input").focus(function(){
			$(this).next("span").css('display','block').delay(1500).fadeOut(1000);
		});
	
	 
	 
		var initializeGames = function(){$("#overlay, .modal").stop().hide();}
		initializeGames();
		
		
		$(".play a").live('click', function(){
											
			var gameInstance = $(this).attr("name");
			var modalNumber = "#modal"+gameInstance;

			
			if($.browser.msie && $.browser.version=="6.0"){
				$("#overlay").css({opacity: 0, position: 'absolute', height: $(window).height(), width: $(window).width()}).show().animate({opacity:.4},1000);
			}else{
				$("#overlay").css({opacity: 0}).show().animate({opacity:.4},1000);
			}
			$(modalNumber).css({opacity: 0, top:$(window).height()/2 - $('.modal').height()/2, left:$(window).width()/2 - $('.modal').width()/2}).show().animate({opacity:1}, 500, function(){
				
			});
			
			return false;
			
		});
		
		$("#overlay, .modalClose a").live("click", function(e){
				
			$(".modal").animate({opacity:0}, 1000, function(e){
				$(this).hide();
			});
				
			$("#overlay").animate({opacity:0}, 1000, function(e){
				$(this).hide(); 
			});		
			
		});
		
		
		
		


			
	//ACCOUNT PROFILE TABS////////////////////////////////////////////////
	
	var accountInitialize = function(){$("#changePassword, #messageSettings").stop().hide();}
	
	accountInitialize();
	
	
	$("#proOne").live('click', function(e){
									   
		$("#proTwo, #proThree").removeClass('profileSelected');
		$(this).addClass('profileSelected roundCorners');
		
		$("#changePassword, #messageSettings").stop().hide();
		$("#profile").stop().show();
		
		return false;
		
	});
	
	$("#proTwo").live('click', function(e){
									   
		$("#proOne, #proThree").removeClass('profileSelected');
		$(this).addClass('profileSelected roundCorners');
		
		$("#profile, #messageSettings").stop().hide();
		$("#changePassword").stop().show();
		
		return false;
		
	});
	
	$("#proThree").live('click', function(e){
									   
		$("#proOne, #proTwo").removeClass('profileSelected');
		$(this).addClass('profileSelected roundCorners');
		
		$("#profile, #changePassword").stop().hide();
		$("#messageSettings").stop().show();
		
		return false;
		
	});
	
	
	
	//LOGOUT RELOCATE////////////////////////////////////////////////
		
	var logoutURL = window.location.href.substr(window.location.href.lastIndexOf("/"));
	var logName = "/logout.html";
	
	if(logoutURL===logName){location.href='/index.html';}
	
	
	
	

}); //END OF DOM READY/////////////////////////////////////////
