$(function(){
	$("a[href='/players-club/sign-up']").click(function()
	{		
		loadModal("720","/layout/set/modal"+$(this).attr("href"));
		return false;
	});
	
	
	$("#top-slides").cycle(
	{
		fx: "fade",
		speed: 800,
		timeout: 5000,
		pager: "#slides-nav"
	});
	
	$("#sidebar .module").cycle("scrollHorz");
	
	/*$("ul#nav ul").each(function(){		
		y_pos = "-" + (($(this).height() / 2)-1) + "px";
		$(this).css("top", y_pos);
	});*/
	
	$("ul#nav li:not(ul#nav ul li)").hover(function()
	{	
		$(".subnav", $(this)).show();
		if ($.browser.msie && Number($.browser.version.substr(0, 1)) < 8){
			offset = $(this).offset();
			parentOffset = $(this).offsetParent().offset();
			$(".subnav", $(this)).css({"top": eval((offset.top - parentOffset.top)-10)+"px"})
		} else {
			$(".subnav", $(this)).css({"top": "-10px"})
			
		}
	},function()
	{
		$(".subnav", $(this)).hide();
	});
	
	// Begin text resize, integer values used as percentages
	$("p#text-size").data("size", 100);
	smallest = 80;
	largest = 120;
	$("a#text-smaller").click(function()
	{
		size = parseInt($("p#text-size").data("size")) - 10;
		if (size <= smallest) // if we've reached the second decrease form normal
			$(this).css("visibility", "hidden");
		if (size <= largest) // if we're decreasing from the maximun
			$("a#text-larger").css("visibility", "visible");
		$("p#text-size").data("size", (size));
		$("#main").css("font-size", (size + "%"));
		return false;
	});
	$("a#text-larger").click(function()
	{
		size = parseInt($("p#text-size").data("size")) + 10;
		if (size >= largest) // if we've reached the second increase from normal
			$(this).css("visibility", "hidden");
		if (size >= smallest) // if we're increasing from the minimum
			$("a#text-smaller").css("visibility", "visible");
		$("p#text-size").data("size", (size));
		$("#main").css("font-size", (size + "%"));
		return false;
	});
	$("form.newsletter input.input-text").data("label", $("form.newsletter input.input-text").val());
	$("form.newsletter input.input-text").focus(function()
	{
		($(this).val() == $(this).data("label")) ? $(this).val("") : null;
	}).blur(function()
	{
		($(this).val() == "") ? $(this).val($(this).data("label")) : null;
	});
	
	
	/***
	 * Generic functions that come out of the box
	 */
	
	/*E-mail Exclusives Input Clear*/
	$("input[name=EMAIL]").focus(function()
	{
		$(this).val("");		
		$(this).blur(function()
		{
			if($(this).val()=="")
				$(this).val("Enter email here");
		});
	});
	
	/*Lightbox Event Handler*/
	if($("a.lightbox").length>0){
		$("a.lightbox").lightBox({
			imageBtnPrev 	: assets+'images/lightbox-btn-prev.gif',
			imageBtnNext 	: assets+'images/lightbox-btn-next.gif',
			imageBtnClose	: assets+'images/lightbox-btn-close.gif',
			imageLoading   	: assets+'images/lightbox-ico-loading.gif',
			fixedNavigation	: true
		});
	}
	
	/*Datepicker Event Handler*/
	$("a.datepickeropen").click(function(){		
		$("#sitewrapper").after('<div id="datepicker">&nbsp;</div>');
		$("#datepicker").css({'display':'none','position':'absolute','z-index':'100','left':$(this).offset().left,'top':$(this).offset().top});
				
		var opts;
		var arr = $(this).attr("rel").split("_");
		
		switch(arr[0])
		{
			case "text":
				opts = {					
					dateFormat:'m-d-yy',					
					onSelect: function(dateText){						
						$("."+arr[1]).val(dateText);									
						$("#datepicker").remove();
					}
				}
			break;
		}
		
		$("#datepicker").datepicker(opts);
		$("#datepicker").toggle();
		
		return false;
	});
	

	
	
	
	
	/**
	 * End Generic Functions
	 */
	
	

});



function loadModal(mWidth,mURL)
{
	$("#sitewrapper").after('<div id="overlay">&nbsp;</div><div id="modal"><div id="modal-content"><img src="'+assets+'images/spinner.gif"></div></div>');
	$("#overlay").css({width:$("body").width(),height:$(document).height()}).show();
	$("#modal").css({"top":($(document).scrollTop()+100),"left":($(window).width()/2)-(mWidth/2)});
	$("#modal").animate({"width":mWidth,"height":"50px"},250,function(){			
		$("#modal-content").load(mURL,function(){
			$("#modal").animate({"height":$("#modal-content").outerHeight(true)},500,function(){
				$("#overlay").css({height:$(document).height()});				
			});			

			$("#overlay, #modal-content p.close a").click(function(){
				$("#modal").animate({"height":"50px"},500,function(){
					$("#modal-content").html("&nbsp");
					$("#modal").animate({"width":"0px","height":"0px"},500,function(){
						$("#modal").remove();
						$("#overlay").remove();
					});
				});
				return false;
			});
		});
	});
}
