$(document).ready(function() {
	if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i))) {
		framework.props.touchDevice	= true;
	} else {
		framework.props.touchDevice	= false;
	}
	
	$("#container #header #header-right ul#social-links>li")
		.hover(	function() {
					$(this).find("em").stop(true, true).animate({opacity: "show", top: "-60"}, "slow");
				}, 
				function() {
					$(this).find("em").animate({opacity: "hide", top: "-70"}, "fast");
				});
		
	switch (framework.id.toLowerCase()) {
		case "home" : 
			var objElements					= $(".dataset");
			if ((objElements) && (objElements.length)) {
				for (var intCounter = 0; intCounter < objElements.length; intCounter++) {
					if (!$(objElements[intCounter]).hasClass("hidden")) {
						var strThisID				= $(objElements[intCounter]).attr("id");
						
						if ((strThisID) && (strThisID.length) && (strThisID.indexOf("-") > -1)) {
							intCurRaceID				= parseInt(strThisID.substr(strThisID.indexOf("-") + 1));
							
							if (!isNaN(intCurRaceID)) {
								framework.props.curRace		= intCurRaceID;
								break;
							}
						}
					}
				}
			}
			
			$("#leaderboard h3 strong a").bind("click", framework.fn.switchMark);
			$("#races-menu-wrap>ul#races-menu>li").bind("click", framework.fn.switchRace);
			$("#chart-header li a").bind("click", framework.fn.sortResults); 
			$("#standings-button").bind("click", framework.fn.showStandings);
			
			if (framework.props.touchDevice) {
				$("#whats-happening>a").css("display", "block").bind("click", framework.fn.showAllUpdates);
				$("div.toplinks").bind("click", function() { if (!$(this).hasClass("hover")) { $(this).addClass("hover"); } else { $(this).removeClass("hover"); }});
			} else {
				$("div.toplinks").bind("mouseover", function() { if (!$(this).hasClass("hover")) { $(this).addClass("hover"); } });
				$("div.toplinks").bind("mouseout", function() { if ($(this).hasClass("hover")) { $(this).removeClass("hover"); } });
			}
			
			$("#leaderboard-chart ul.chart-data>li>ol>li.name").live("click", framework.fn.showLeaderboardGraph);
			$("#standings ul.standings-data>li>ol>li.name").bind("click", framework.fn.showStandingsGraph);
			
			framework.fn.updateWHHeight();
			break;
			
		case "submit-event" : 
			$("#frmEvent").bind(	"submit", 
									function() {
										if (framework.validation.validate(	{
																				fields:	[
																							{id: "strEventDate", type: framework.validation.formTypes.blank, message: "- Please enter the date(s) of this event."}, 
																							{id: "strEventName", type: framework.validation.formTypes.blank, message: "- Please enter the name of this event."}, 
																							{id: "txtEventLocation", type: framework.validation.formTypes.blank, message: "- Please enter the location of this event."}
																						]
																			})) {
											return true;
										} else {
											return false;
										}
									});
			break;
	}
});
