
var isFirstLoad = true;

function verifyValidHash() {
	var isValidHash = false;
	var regions = ['asia', 'ce_europe_mideast_africa', 'latin_america', 'north_america', 'western_europe'];
	//trim hash
	var _hash = document.location.hash.substr(2);
	$.each(regions, function() {
		if(!isValidHash && (_hash == this)) {
			isValidHash = true;
		}
	});
	return isValidHash;
}

//swf will call this function and pass region ID
function loadWorldwideContent(region) {	
	if ($('body').hasClass(region) && isFirstLoad) {
		isFirstLoad = false;
		return;
	}
	var $target = $('.worldwide-nav a[rel='+ region +']');
	//build include path
	var href = $target.attr('href');
	var ipath = '_' + href;
	//construct include path from full URL
	if (href.lastIndexOf('/') !== -1) {
		ipath = href.substring(0,href.lastIndexOf('/')+1) + '_' + href.substring(href.lastIndexOf('/')+1);
	}
	//need to apply sIFR to new content
	function sIFRize() {
		//init sifr
		sIFR.replace(frutiger_medium, {
			selector: '.content-subtitle',
			css: '.sIFR-root { color: #0046AC; } .sIFR-root a { color: #00A0DE; text-decoration: none; } .sIFR-root a:hover { color: #444444; text-decoration: underline; }',
			wmode: 'transparent'
		});
		sIFR.replace(frutiger_heavy, {
			selector: '.content-title',
			css: '.sIFR-root { color: #444444; } .sIFR-root a { color: #0046AD; text-decoration: none; } .sIFR-root a:hover { color: #444444; text-decoration: underline; }',
			wmode: 'transparent'
		});					
	}
	
	//do transitions
	if(isFirstLoad && document.location.hash !== '') {
		if (verifyValidHash()) {
			//swf address load content with nothing fancy
			$('#worldwide-ops-content').empty().load(ipath, function() {
				sIFRize();
			});
		}
		isFirstLoad = false;
		return;			
	}
	//set nav state
	function updateNav() {
		var $items = $('#section-navigation .active-box li').removeClass('current');
		$items.find('a[href*="'+ region +'"]').parent().addClass('current');
	}	
	//fancy transition	
	$('#worldwide-ops-content').slideUp('slow',function() {
		$(this).load(ipath, function() {
			$(this).slideDown('slow',function() {
				sIFRize();
				updateNav();
			});
		});
	});
	isFirstLoad = false;
}

