//--------------------------------------------------------------------------------
//core.js
//--------------------------------------------------------------------------------
//document init functions
var loc;
//support for urls without hash tags
if(window.location.toString().indexOf("?id")>-1 && window.location.toString().indexOf("#") == -1 ){
	loc = window.location.toString().split("?id");
	var newLoc = loc.join("#?id");
	window.location.replace(newLoc);
}

$(document).ready(function() {
	//get the requested presentation ID from the URL and pass it into the flashVars
	var _presID = $.address.parameter("id");
	
	//if we are on this url "[enter url below]" then show the intro
	//all other urls the flash is embedded on will not show the intro
	var introAllowedURL = "http://www.myrangeresources.com/";

	//10/25 update
	//checks for an approved URL or a parameter in the address with a value of intro=1
	if(window.location.toString().toLowerCase() == introAllowedURL.toLowerCase() || $.address.parameter("intro") == 1){
		_showIntro = true;
	}else{
		_showIntro = false;
	}
	
	
	
	//this array stores an object that consists of a string to match within the current url and the 
	//appropriate xml to load into the flash if that string is found.  For example:
	//url:"/community" would match to http://www.myrangeresources.com/community.aspx and therefore load
	//an xml file.  Complete urls would also work.  Note: Attempting to match a /range in the array before
	//a /rangeresources would result in the /range entry picking up and the /rangeresources entry being 
	//ignored.  Make sure your array pushes are in a logical order if not using whole urls.
	
	var _xml = "";
	
	var urlArr = new Array();
	urlArr.push({url:"/community.aspx",xmlToLoad:"/development/swf/xml/videoFred.xml"});
	urlArr.push({url:"/community_careers.aspx",xmlToLoad:"/development/swf/xml/videoFred.xml"});
	urlArr.push({url:"/community_lease.aspx",xmlToLoad:"/development/swf/xml/videoFred.xml"});
	urlArr.push({url:"/community_nonprofit.aspx",xmlToLoad:"/development/swf/xml/videoFred.xml"});
	urlArr.push({url:"/community_nonprofit_subs.aspx",xmlToLoad:"/development/swf/xml/videoFred.xml"});
	urlArr.push({url:"/community_smallbusiness.aspx",xmlToLoad:"/development/swf/xml/videoFred.xml"});
	urlArr.push({url:"/natural",xmlToLoad:"/development/swf/xml/videoDavid.xml"});
	urlArr.push({url:"/natural_domestic",xmlToLoad:"/development/swf/xml/videoDavid.xml"});
	urlArr.push({url:"/natural_naturalgas",xmlToLoad:"/development/swf/xml/videoDavid.xml"});
	urlArr.push({url:"/learn",xmlToLoad:"/development/swf/xml/videoBob.xml"});
	urlArr.push({url:"/learn_drilling",xmlToLoad:"/development/swf/xml/videoBob.xml"});
	urlArr.push({url:"/learn_production",xmlToLoad:"/development/swf/xml/videoBob.xml"});
	urlArr.push({url:"/learn_reclaim",xmlToLoad:"/development/swf/xml/videoBob.xml"});
	urlArr.push({url:"/environ",xmlToLoad:"/development/swf/xml/videoMary.xml"});
	urlArr.push({url:"/environ_safety",xmlToLoad:"/development/swf/xml/videoMary.xml"});
	urlArr.push({url:"/environ_water",xmlToLoad:"/development/swf/xml/videoMary.xml"});
	urlArr.push({url:"/environ_clean",xmlToLoad:"/development/swf/xml/videoMary.xml"});
	urlArr.push({url:"/range",xmlToLoad:"/development/swf/xml/videoAlbie.xml"});
	urlArr.push({url:"/range_care",xmlToLoad:"/development/swf/xml/videoAlbie.xml"});
	
	for(i=0;i<urlArr.length;i++){
		if(window.location.toString().indexOf(urlArr[i].url)>-1){
			_xml = urlArr[i].xmlToLoad;
			//alert("load " + _xml);
			break;
		}
	}
	
   //generate a cache kill var to keep browsers from loading the same swf 
   var cacheKill = Math.round(9999*Math.random()) + new Date().getTime();
   //write flash
   swfobject.embedSWF('/development/swf/rangeResources.swf?id='+cacheKill, 'container', '900', '366', '9.0.45','/development/swf/expressinstall.swf', 
					  {presID:_presID,
					   showIntro:_showIntro,
					   useXML:_xml}, 
					  {menu: 'false', wmode: 'opaque', base:'/development/swf/'}, {id: 'website', name: 'website'});
});

//dom reference to the flash instance
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}else {
		return document[movieName];
	}
}
//--------------------------------------------------------------------------------


//--------------------------------------------------------------------------------
//google related code - functions called from Flash via ExternalInterface
//--------------------------------------------------------------------------------
//10/25 update
function flashShare($s){
	switch($s){
		case "facebook":
			//someone shared via facebook
			//UNCOMMENT THIS ONCE IN PAGE WITH _gaq CODE
			_gaq.push(['_trackPageview', '/Share/Facebook/']); 
			break;
		case "twitter":
			//someone shared via twitter
			//YOU CAN PLACE ANY _gaq CODE HERE AS WELL
			break;
		case "form":
			//someone shared via the email form
			//UNCOMMENT THIS ONCE IN PAGE WITH _gaq CODE
			_gaq.push(['_trackPageview', '/Share/Friend/']); 
			break;
	}
}
//--------------------------------------------------------------------------------


//--------------------------------------------------------------------------------
//jquery address params and events
//--------------------------------------------------------------------------------
$.address.strict(false);

//jquery address external event handler (browser refres, address change, back, forward, etc.)
$.address.externalChange(function(event) { 
	//get te requested presentation ID from the URL
	var _presID = $.address.parameter("id");
	//check if flash has exposed the extLoadPres function
	if(thisMovie("website").extLoadPres != undefined){
		//request flash to load the presID
		document.getElementById("website").extLoadPres(_presID,true);
	}
});
//--------------------------------------------------------------------------------



//--------------------------------------------------------------------------------
//functions called by flash via externalInterface
//--------------------------------------------------------------------------------
//called by flash to set the current _presID
function setCurrentLocation($presID){
	$.address.parameter("id",$presID);
}

//called by flash to set the current page title
function setLocationTitle(s){
	$.address.title("Range Resources - " + s);
}
//--------------------------------------------------------------------------------



//--------------------------------------------------------------------------------
//utility functions
//--------------------------------------------------------------------------------
//launch a pop-up window
function openWindow($s){
	var winName = Math.round(9999*Math.random()) + new Date().getTime();
    var winNew = window.open($s,winName,"toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=700,left=200,top=100");
        if(!winNew) {
            return "false";
        } else {
            return "true";
        }
}
//--------------------------------------------------------------------------------
