var temp;
jQuery(document).ready(function() {
	if(document.location.href.indexOf("myprofile") != -1){
		jQuery("#popover2").html('<div id="popHeader"><div class="left"><img src="/thezone/Portals/2/ModuleSkins/popOver/protegeShoesHeader.gif"/></div><div class="right"><a href="javascript:popover2();"><img src="/thezone/Portals/2/ModuleSkins/popOver/close.gif"/></a></div></div><div id="popContainer"><div class="corner"><img src="/thezone/Portals/2/ModuleSkins/popOver/corner.gif"/></div><img src="/thezone/Portals/2/ModuleSkins/popOver/chooseProtege.gif"/><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/a3h_playoff.png"/><input type="radio" name="shoe" value="A3H Playoff"/> A3H Playoff</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/a3h_slide.png"/><input type="radio" name="shoe" value="A3H Slide"/> A3H Slide</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/aspire.png"/><input type="radio" name="shoe" value="Aspire"/> Aspire</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/bronx.png"/><input type="radio" name="shoe" value="Bronx"/> Bronx</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/coolout.png"/><input type="radio" name="shoe" value="Coolout"/> Coolout</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/coupz.png"/><input type="radio" name="shoe" value="Coupz"/> Coupz</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/drills.png"/><input type="radio" name="shoe" value="Drills"/> Drills</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/headliners.png"/><input type="radio" name="shoe" value="Headliners"/> Headliners</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/hustle.png"/><input type="radio" name="shoe" value="Hustle"/> Hustle</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/LS.png"/><input type="radio" name="shoe" value="LS"/> LS</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/protege_2.png"/><input type="radio" name="shoe" value="Protege 2"/> Protege 2</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/source.png"/><input type="radio" name="shoe" value="Source"/> Source</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/stack_slide.png"/><input type="radio" name="shoe" value="Stack Slide"/> Stack Slide</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/stackjack.png"/><input type="radio" name="shoe" value="Stackjack"/> Stackjack</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/stackjack_playoff.png"/><input type="radio" name="shoe" value="Stackjack playoff"/> Stackjack Playoff</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/tripples.png"/><input type="radio" name="shoe" value="Tripples"/> Tripples</div><div class = "shoeSelection"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoes/twinz.png"/><input type="radio" name="shoe" value="Twinz"/> Twinz</div><div class = "shoeSaveButton"><a href="javascript:saveShoeSelection();"><img src="/thezone/Portals/2/ModuleSkins/popOver/shoeSave.gif"/></a></div></div>');
	
		temp = jQuery(".favoriteShoeCell input").val();
		jQuery(".shoeSelection input").each(function(){
			if (jQuery(this).val() == temp){
				jQuery(this).attr("checked","checked");
			}
		});
	
		jQuery(".shoeSelection").click(function() {
			jQuery(this).find("input").attr("checked","checked");
		});
	}
	
	jQuery("#dither").click(function(e) {
		jQuery("#dither").css({ display: "none" });
		jQuery("#popover").css({ display: "none" });
		jQuery("#popover2").css({ display: "none" });
	//	jQuery("#flash_content").show();
		e.stopPropagation();
	});
	
});

function popover(popWidth) {
	if(jQuery("#popover").css("display") != "none") {
		jQuery("#dither").css({ display: "none" });
		jQuery("#popover").css({ display: "none" });
	} else {
		if (popWidth != undefined)	{jQuery("#popover").width(popWidth);var newMargin = -(popWidth / 2);jQuery("#popover").css("margin-left", newMargin);}
		jQuery("#dither").css({ display: "block", height: jQuery(document).height() }).fadeTo(350, 0.85);
		jQuery("#popover").css({ display: "block"});
		// In the case that the the login scrim was open prior, alter the depth
		var ditherIndex = jQuery("#dither").css("z-index");
		jQuery("#LoginBase").css("z-index", (ditherIndex - 1));
		jQuery("#popover").css({ top: "80px" });
		
	}
}

function leavepopover(url) {
	$("#linkout").attr("href",url);
	popover(520);
}

//$(function () {leavepopover("http://google.com");});

function popover2() {
	if(jQuery("#popover2").css("display") != "none") {
		jQuery("#dither").css({ display: "none" });
		jQuery("#popover2").css({ display: "none" });
	} else {
		
		jQuery("#dither").css({ display: "block", height: jQuery(document).height() }).fadeTo(350, 0.85);
		jQuery("#popover2").css({ display: "block" }).fadeTo(350, 0.9);
		// In the case that the the login scrim was open prior, alter the depth
		var ditherIndex = jQuery("#dither").css("z-index");
		jQuery("#LoginBase").css("z-index", (ditherIndex - 1));
	}
}

function saveShoeSelection(){
	jQuery("#popContainer input").each(function(){
			if (jQuery(this).attr("checked")){
				temp = jQuery(this).val();
				tempLink = temp.toLowerCase();
				tempLink = tempLink.replace(" ", "_");
				jQuery(".favoriteShoeCell .currentRegVal").html(temp + '<br/><a target="_blank" href="' + shoeLinks[tempLink] + '">BUY</a>');
				jQuery(".favoriteShoeCell input").val(temp);
				temp = temp.toLowerCase();
				temp = temp.replace(" ", "_");
				temp = "/thezone/Portals/2/ModuleSkins/popOver/shoes/"+temp+".png";
				jQuery("#displayShoe").html('<img src="'+ temp +'"/>');
				jQuery(".favoriteShoeCell .editButton").hide().after('<a class="saveButton" href="javascript:submitChanges();" style="display: block;">save</a>');
			}
	});
	popover2();
}