// JavaScript Document
function redirectOnFlash(destinationUrl)
{
	
	if(swfobject.hasFlashPlayerVersion("9.0.0")==true)
	{
		//The user has flash so they should be redirected away from this page
		
		//console.debug(pageName);
		
		var pathArray = location.pathname.split('/');
		var fileName = pathArray[pathArray.length-1];
		var eventName = pathArray[pathArray.length-2];
		var pageName = fileName.substring(0, fileName.lastIndexOf("."));		
		
		location.replace(destinationUrl)
		//location.replace("http://" + location.host + "/ufc_events/event_page.html#/fight/" + pageName);
		//console.debug("http://" + location.host + "/event_page.html#/" + eventName + "/fight/" + pageName);	

	}
}


// urlSuffix is what comes after ufc.com with no ending slash.
// Schedule All page would be "schedule/all" for http://www.ufc.com/schedule/all/
function verifyRegion(urlSuffix, countryCode, selectedScheduleRegion){		        
	if (google.loader.ClientLocation){
		// Get Geolocation details
		var cl = google.loader.ClientLocation;
		var geoRegion = cl.address.region;
		var geoCountry = cl.address.country_code;
		var geoCity = cl.address.city;
		
		if (urlSuffix.indexOf("homePage") > 0) {
			// Create the redirect url if it's needed
			var url = window.location.toString();
			var controllerUrl = urlSuffix;
			var scheduleIndex = url.indexOf(controllerUrl);

			//If geo location doesn't match selected schedule region. do Ajax call
			if (selectedScheduleRegion != geoCountry && countryCode == "") {
				$.get(urlSuffix + '?countryCode=' + geoCountry, function(data) {
					//Logic for Schedule section on homepage.
					if (urlSuffix.indexOf("\schedule") > 0) {
						$('#div-schedule-container').remove();
						$('#schedule-placeholder').after(data);
						
						$('#schedule-region-selector').mouseover(function() {
							$('#dd-schedule-regions').css("display", "block");
						});
						$('#schedule-region-selector').mouseout(function() {
							$('#dd-schedule-regions').css("display", "none");
						});
					}
					
					//Logic for featured schedule (Upcoming)
					if (urlSuffix.indexOf("\featuredSchedule") > 0) {
						$('#div-schFeatured-container').remove();
						$('#schFeatured-placeholder').after(data);
					}
				});
			}
			
			return;
		}
		else {
			// Redirect the page if the selected schedule region does not match the geo 
			// location country AND if only a country code does not exist in the url bar.
			if (selectedScheduleRegion != geoCountry) {
				// Create the redirect url if it's needed
				var url = window.location.toString();
				var controllerUrl = "schedule";
				var scheduleIndex = url.indexOf(controllerUrl);
	
				var redirectUrl = url.substring(0,scheduleIndex) + urlSuffix + "/" + geoCountry;
				window.location = redirectUrl;
			}
		}
	}
}
