window.StateManager = EXANIMO.managers.StateManager;

StateManager.stateChangeHandler = function(e)
{
	try {
		curtfjContentTracker.tfjChangeMosaicTab(curtfjContentTracker.getReverseStateHash(e.id),curtfjContentTracker.getStateUrl(e.id));
		if(e.id.toLowerCase() == "tfjstcvideo") {
			tfjTriggerVideo(1);
			if (tfjMpActiveId && tfjMpActiveId != 'tfjMpVideo') {
				if ($('tfjMpVideo')) {
					tfjToggleMP('tfjMpVideo');
				}
			}
		} else {
			if (tfjMpActiveId && tfjMpActiveId != 'tfjMpStory') {
				if ($('tfjMpStory')) {
					tfjToggleMP('tfjMpStory');
				}
			}
			if (typeof tfjPlayer != "undefined") {
				tfjPlaylistManager.getInstance().MOSUnload();
			}
		}
	} catch(e) {};
}  

function swapAd (type) {
	if (typeof tfjad_refreshAds == 'function') { 
		tfjad_refreshAds(type);
	}
}

var tfjMosaicDetect= true;
var tfjDefaultTab = null;
var tfjAnimateTabs = true;
var tfjCurrTime = new Date();
var tfjStoryPublishTime = new Date();
var tfjDefaultAdsLoaded = false;
var tfjDefault180AdsLoaded = false;
var tfjDefault336AdsLoaded = false;
pagetypeTS = "mosaic";


/* _____________________________________________________ Story font widget */

var tfj_FONT_COOKIE_NAME = "tfjFont";
var tfj_FONT_COOKIE_PATH = "/";
var tfj_FONT_COOKIE_DOMAIN = tfjCurrDomain;
var tfj_FONT_COOKIE = allCookies[ tfj_FONT_COOKIE_NAME ] || null;
var tfj_CSS_TITLE = tfj_FONT_COOKIE ? tfj_FONT_COOKIE : null;



function setActiveStyleSheet(tfj_CSS_TITLE) {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == tfj_CSS_TITLE) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}


Event.observe(window, 'unload', function(e) {
  if (getActiveStyleSheet() != null) {
  	if (getActiveStyleSheet() != tfj_FONT_COOKIE) {
	  	tfj_setCookie( tfj_FONT_COOKIE_NAME, getActiveStyleSheet(), 24*31, tfj_FONT_COOKIE_PATH, tfj_FONT_COOKIE_DOMAIN, '');
	}
  } else {
  	tfj_killCookie( tfj_FONT_COOKIE_NAME, tfj_FONT_COOKIE_PATH, tfj_FONT_COOKIE_DOMAIN );
  }
});


setActiveStyleSheet(tfj_CSS_TITLE);

Event.observe(window, 'load', function() {
	if ($('tfjTabNav')) {
		StateManager.initialize();	
		tfjSetClickability(curtfjContentTracker.tfjActiveTab);
	} else {
		tfjSetClickability('tfjTxtCmpnt');	
		if (typeof tfjDefaultTab == 'string') {
			tfj_omniture.Load.fetchConfigNoTab(tfjDefaultTab);
		} else {
			tfj_omniture.Load.fetchConfig('tfjTxtCmpnt');
		}
	}
});

function tfjLoadTab(url) {

	var contentDivs = $$('div#tfjHighLightTrigger div.tfjContentContainer');

	for (var i = 0; i < contentDivs.length; i++) {						document.getElementById(contentDivs[i].id).setAttribute('style','display:none');
	}

	var tfjSTCComponent = (location.hash != "") ? location.hash : '#'+tfjDefaultTab;
		switch(tfjSTCComponent.toLowerCase()) {
			case '#tfjstctext':
curtfjContentTracker.tfjInitialTabLoad('tfjTxtCmpnt','article.html');
			break;
			case '#tfjstcvideo':
curtfjContentTracker.tfjInitialTabLoad('tfjVideoCmpnt','videos.html');
			break;
			case '#tfjstcphoto':
curtfjContentTracker.tfjInitialTabLoad('tfjPhotoCmpnt','photos.html');
			break;
			case '#tfjstcother1':
curtfjContentTracker.tfjInitialTabLoad('otherTab1','other1.html');
			break;
			case '#tfjstcother2':
curtfjContentTracker.tfjInitialTabLoad('otherTab2','other2.html');
			break;
			
			default:
curtfjContentTracker.tfjInitialTabLoad('tfjTxtCmpnt','article.html');			
		}	
}

var defaultVideo = "";

function tfj_changeMosaicTab(component,url,scroll,startVideo) {
	if(startVideo!=null){
		defaultVideo = startVideo;
	}else{
		defaultVideo = "";
	}
	if (typeof(curtfjContentTracker) != "undefined") {
		if (scroll) {
			scrollTo(0,0);
		}
		StateManager.setState(curtfjContentTracker.getStateHash(component));
		tfj_omniture.Load.fetchConfig(component);
	} else {
 		return false;
	}
}


function tfjTabStripLinks() {
	var links = $$('div#tfjTabNav a');
	for (var i = 0; i <links.length; i++ ) {
		var href = links[i].getAttribute("href").toString().split('#');
		links[i].setAttribute("href","#"+href[1]);
		if (tfj.detectBrowser.isSafari()) {
			var currOnclick = links[i].getAttribute("onclick");
			currOnclick = currOnclick.replace('return false','return true');
			links[i].setAttribute("onclick",currOnclick);
		}
		
			if (tfj.detectBrowser.isIE6()) { //ugly hacks to make tab animation almost bearable in IE 6

		var ieTabBG = document.createElement("img");
		ieTabBG.setAttribute("src", "http://i.l.tfj.net/tfj/.element/img/2.0/mosaic/tabs/bg_tab.gif");			
		ieTabBG.setAttribute("width", "123");		
		ieTabBG.setAttribute("height", "23");		
		ieTabBG.className = "tabDefaultBG";

		var leftCornerFirst = document.createElement("img");
		leftCornerFirst.setAttribute("src", "http://i.l.tfj.net/tfj/.element/img/2.0/mosaic/tabs/bg_tab_current_first.gif");		
		leftCornerFirst.setAttribute("border", "0");		
		leftCornerFirst.setAttribute("width", "10");		
		leftCornerFirst.setAttribute("height", "29");		
		leftCornerFirst.className = "leftCornerFirst";				
			
		var leftCorner = document.createElement("img");
		leftCorner.setAttribute("src", "http://i.l.tfj.net/tfj/.element/img/2.0/mosaic/tabs/bg_tab_current_left.gif");		
		leftCorner.setAttribute("border", "0");		
		leftCorner.setAttribute("width", "10");		
		leftCorner.setAttribute("height", "29");		
		leftCorner.className = "leftCorner";		
		
		var rightCorner = document.createElement("img");
		rightCorner.setAttribute("src", "http://i.l.tfj.net/tfj/.element/img/2.0/mosaic/tabs/bg_tab_current_right.gif");		
		rightCorner.setAttribute("border", "0");		
		rightCorner.setAttribute("width", "10");		
		rightCorner.setAttribute("height", "29");		
		rightCorner.className = "rightCorner";		

		var rightMostCorner = document.createElement("img");
		rightMostCorner.setAttribute("src", "http://i.l.tfj.net/tfj/.element/img/2.0/mosaic/tabs/bg_tab_current_last_ie.gif");		
		rightMostCorner.setAttribute("border", "0");		
		rightMostCorner.setAttribute("width", "12");		
		rightMostCorner.setAttribute("height", "29");		
		rightMostCorner.className = "rightCornerLast";

				links[i].parentNode.insertBefore(ieTabBG,links[i]);
				links[i].appendChild(leftCornerFirst);
				links[i].appendChild(leftCorner);
				links[i].appendChild(rightCorner);
				links[i].appendChild(rightMostCorner);
			}
	}
}

var tfjContentTracker = Class.create();

tfjContentTracker.prototype = {
	initialize: function(objName) {	
		this.tfjTxtCmpnt = false //has been loaded, is current tab;
		this.tfjVideoCmpnt = false;
		this.tfjPhotoCmpnt = false;
		this.otherTab1 = false;
		this.otherTab2 = false;
		this.tfjActiveTab = 'tfjTxtCmpnt';
		this.tfjActiveTabName='tfjMosaic_tab1';
		this.tfjPrevActiveTabName='tfjMosaic_tab1';		
		this.objName= objName;
	},
	setObjName: function(objName){
		this.objName = objName;
	},
	setValue: function(id,value) {
		switch(id) {
			case 'tfjTxtCmpnt':
				this.tfjTxtCmpnt = value;			
			break;
			case 'tfjVideoCmpnt':
				this.tfjVideoCmpnt = value;
			break;
			case 'tfjPhotoCmpnt':
				this.tfjPhotoCmpnt = value;
			break;
			case 'otherTab1':
				this.otherTab1 = value;
			break;
			case 'otherTab2':
				this.otherTab2 = value;
			break;
		}
	},
	setActiveTab: function(id){
		this.tfjActiveTab = id;
		switch(id) {
			case 'tfjTxtCmpnt':
				this.tfjActiveTabName = 'tfjMosaic_tab1';	
			break;
			case 'tfjVideoCmpnt':
				this.tfjActiveTabName = 'tfjMosaic_tab2';
			break;
			case 'tfjPhotoCmpnt':
				this.tfjActiveTabName = 'tfjMosaic_tab3';
			break;
			case 'otherTab1':
				this.tfjActiveTabName = 'tfjMosaic_tab4';
			break;
			case 'otherTab2':
				this.tfjActiveTabName = 'tfjMosaic_tab5';
			break;
		}
	},
	setPrevActiveTab: function(id) {
		this.tfjPrevActiveTab = id;		
		switch(id) {
			case 'tfjTxtCmpnt':
				this.tfjPrevActiveTabName = 'tfjMosaic_tab1';			
			break;
			case 'tfjVideoCmpnt':
				this.tfjPrevActiveTabName = 'tfjMosaic_tab2';
			break;
			case 'tfjPhotoCmpnt':
				this.tfjPrevActiveTabName = 'tfjMosaic_tab3';
			break;
			case 'otherTab1':
				this.tfjPrevActiveTabName = 'tfjMosaic_tab4';
			break;
			case 'otherTab2':
				this.tfjPrevActiveTabName = 'tfjMosaic_tab5';
			break;
		}
	
	},
	getStateHash: function(id){
	
		switch(id) {
			case 'tfjTxtCmpnt':
				return 'tfjSTCText';
			break;
			case 'tfjVideoCmpnt':
				return 'tfjSTCVideo';
			break;
			case 'tfjPhotoCmpnt':
				return 'tfjSTCPhoto';
			break;
			case 'otherTab1':
				return 'tfjSTCOther1';
			break;
			case 'otherTab2':
				return 'tfjSTCOther2';
			break;
			default:
				return 'tfjSTCText';
		}
	},
	getReverseStateHash: function(id){
	
		switch(id) {
			case 'tfjSTCText':
				return 'tfjTxtCmpnt';
			break;
			case 'tfjSTCVideo':
				return 'tfjVideoCmpnt';
			break;
			case 'tfjSTCPhoto':
				return 'tfjPhotoCmpnt';
			break;
			case 'tfjSTCOther1':
				return 'otherTab1';
			break;
			case 'tfjSTCOther2':
				return 'otherTab2';
			break;
			default:
				return 'tfjTxtCmpnt';

		}
	},	
	getStateUrl: function(id){
	
		switch(id) {
			case 'tfjSTCText':
				return 'article.html';
			break;
			case 'tfjSTCVideo':
				return 'videos.html';
			break;
			case 'tfjSTCPhoto':
				return 'photos.html';
			break;
			case 'tfjSTCOther1':
				return 'other1.html';
			break;
			case 'tfjSTCOther2':
				return 'other2.html';
			break;
			default:
				return 'article.html';
		}
	},
	tfjChangeAd: function(id,story) {
		if (tfjDefault336AdsLoaded || !$('tfjDefault336Space')) {
			if (id == 'tfjVideoCmpnt') {		
				swapAd('video');
			} else {
				swapAd('article');
			}
			if (story) {
				if (id == 'tfjTxtCmpnt') {
					curtfjContentTracker.tfjChangeStoryAd(id,1);
				} else {
					curtfjContentTracker.tfjChangeStoryAd(id);
				}
			}
		} else {
			curtfjContentTracker.tfjChangeStoryAd(id,1);
		}
	},
	tfjChangeStoryAd: function(id,initial) {
		if (initial) {
			if (id != 'tfjVideoCmpnt') {
				//fetch 336
				if ($('tfjDefault336Space') && typeof tfjDefault336Ad != 'undefined' && !tfjDefault336AdsLoaded) {
					tfjUpdateAdInDiv('tfjDefault336Space',tfjDefault336Ad);
					tfjDefault336AdsLoaded = true;
				}
			}
			//fetch 180
			if ($('tfjDefault180Space') && typeof tfjDefault180Ad != 'undefined') {
				if (id == 'tfjTxtCmpnt') {
					tfjUpdateAdInDiv('tfjDefault180Space',tfjDefault180Ad);
					tfjDefault180AdsLoaded = true;
				} else {
					tfjFindAdInsertSpot(id); //update 180x150
				}
			}
		} else {
			tfjFindAdInsertSpot(id); //update 180x150
		}
		curtfjContentTracker.tfjChangeContextualAd(id);
	},
	tfjChangeContextualAd: function(id) {
			//fetch contextual ad
			if ($('tfjDefaultContSpace')) {
				switch(id) {
					case 'tfjPhotoCmpnt':
						if (typeof tfjPhotoContAd != "undefined") {
							tfjUpdateAdInDiv('tfjDefaultContSpace',tfjPhotoContAd);
						}
					break;
					case 'tfjVideoCmpnt':
						if (typeof tfjVideoContAd != "undefined") {
							tfjUpdateAdInDiv('tfjDefaultContSpace',tfjVideoContAd);
						}
					break;
					case 'otherTab1':
						if (typeof otherTab1ContAd != "undefined") {
							tfjUpdateAdInDiv('tfjDefaultContSpace',otherTab1ContAd);
						}
					break;
					case 'otherTab2':
						if (typeof otherTab2ContAd != "undefined") {
							tfjUpdateAdInDiv('tfjDefaultContSpace',otherTab2ContAd);
						}
					break;
					default:
						if (typeof tfjDefaultContAd != "undefined") {
							tfjUpdateAdInDiv('tfjDefaultContSpace',tfjDefaultContAd);
						}
				}
			}
	},
	tfjChangeMosaicTab: function(id,path){
			var objVal = eval(this.objName+'.'+id);//eval('curtfjContentTracker.'+id);
		if (!objVal && id != curtfjContentTracker.tfjActiveTab) {  //if the content hasn't been loaded before
			Element.hide(id);	
			curtfjContentTracker.setValue(id,true);
			curtfjContentTracker.setPrevActiveTab(curtfjContentTracker.tfjActiveTab);
			curtfjContentTracker.setActiveTab(id);
			if(id != 'tfjTxtCmpnt') {
				new Ajax.Updater({success: id}, path,
					{
						onComplete:function() {
						if (tfjAnimateTabs) {	
							curtfjContentTracker.tfjAnimateTab();
						} else {	
							curtfjContentTracker.tfjChangeMosaicDisplay();
						}
							curtfjContentTracker.tfjChangeAd(id,1);
						},
						method:'get',
						evalScripts:true,
						asynchronous:true
					}
				);
			} else {
						if (tfjAnimateTabs) {	
							curtfjContentTracker.tfjAnimateTab();
						} else {	
							curtfjContentTracker.tfjChangeMosaicDisplay();
						}
							curtfjContentTracker.tfjChangeAd(id,1);

			}
		} else if(id != curtfjContentTracker.tfjActiveTab)  { //check for active tab, fade it out if it's not the tab clicked, fade requested tab in
			curtfjContentTracker.setPrevActiveTab(curtfjContentTracker.tfjActiveTab);		
			curtfjContentTracker.setActiveTab(id);			
						if (tfjAnimateTabs) {	
							curtfjContentTracker.tfjAnimateTab();
						} else {	
							curtfjContentTracker.tfjChangeMosaicDisplay();
						}							
							curtfjContentTracker.tfjChangeAd(id,1);

		}
		
		tfjSetClickability(id); //change clickURL and PartnerID for clickability buttons
	},
	tfjAnimateTab: function() {
	var tfjFPS = ( tfj.detectBrowser.isIE6() ) ? 1 : 1;
	var myTrack = "";
	var widthDiff;
				new Effect.Scale( curtfjContentTracker.tfjActiveTabName , 181, 
					{
						fps:30,
						duration:.25,
						scaleY:false,
						scaleContent:false,
						scaleFrom:100,
						scaleMode:
							{
								originalWidth: 123
							},
						afterUpdate: function(obj) {
						widthDiff = Math.round($(obj.element.id).offsetWidth - 123);
						
						$(curtfjContentTracker.tfjPrevActiveTabName).style.width = Math.round(223 - widthDiff)+"px";
						if (widthDiff == 100) {
$(curtfjContentTracker.tfjPrevActiveTabName).className = '';						
						}
						
						myTrack += $(obj.element.id).offsetWidth;
							//$('tfjTimeStamp').innerHTML = myTrack;
							
						},
						beforeStart: function(obj) 
							{
								if ((curtfjContentTracker.tfjPrevActiveTab == 'otherTab1' || curtfjContentTracker.tfjPrevActiveTab == 'otherTab2') && tfj.detectBrowser.isIE()) {
									switch(curtfjContentTracker.tfjPrevActiveTab) {
										case 'otherTab1':
											if (document.getElementById('tfj_other1ContentSWF')) { 	
											tfj_unloadFlashMovie('tfj_other1ContentSWF');
											}
										break;
										case 'otherTab2':
											if (document.getElementById('tfj_other2ContentSWF')) { 	
											tfj_unloadFlashMovie('tfj_other2ContentSWF');
											}
										break;
									}
								}
								Element.hide(curtfjContentTracker.tfjPrevActiveTab);							
								$(obj.element.id).className = tfjCheckTab(obj.element.id);
								
							},
						afterFinish:function(obj)
							{
								$(curtfjContentTracker.tfjActiveTab).style.display = 'block';
								
								if ((curtfjContentTracker.tfjActiveTab == 'otherTab1' || curtfjContentTracker.tfjActiveTab == 'otherTab2') && tfj.detectBrowser.isIE()) {
								
									switch(curtfjContentTracker.tfjActiveTab) {
										case 'otherTab1':
											if (document.getElementById('tfj_other1ContentSWF')) { 	
											tfj_loadFlashMovie('tfj_other1ContentSWF');
											}
										break;
										case 'otherTab2':
											if (document.getElementById('tfj_other2ContentSWF')) { 	
											tfj_loadFlashMovie('tfj_other2ContentSWF');
											}
										break;
									}
								
								
								}
								
								
								if( $(obj.element).id == "tfjMosaic_tab2") {
									tfjToggleMPMod('tfjVideos');
								}else {
									tfjToggleMPMod('tfjStories');
								}
						}
					}
				);					
	},
	tfjInitialTabLoad: function(id,path){
			var objVal = eval(this.objName+'.'+id);//eval('curtfjContentTracker.'+id); if this returns true, don't want XHR
			Element.hide(id);	
			curtfjContentTracker.setValue(id,true);
			curtfjContentTracker.setPrevActiveTab(curtfjContentTracker.tfjActiveTab);
			curtfjContentTracker.setActiveTab(id);

			if(id != 'tfjTxtCmpnt' && !objVal) {
				new Ajax.Updater({success: id}, path,
					{
						onComplete:function() {
							curtfjContentTracker.tfjChangeMosaicDisplay();
							Event.observe(window, 'load', function() {
								curtfjContentTracker.tfjChangeAd(id,1);
							});
						},
						method:'get',
						evalScripts:true,
						asynchronous:true
					}
				);
			} else {
				curtfjContentTracker.tfjChangeMosaicDisplay();
				
				Event.observe(window, 'load', function() {
					curtfjContentTracker.tfjChangeAd(id,1);
				});
			}
Event.observe(window, 'load', function() {
		tfj_omniture.Load.fetchConfig(id);
});
		
	},
	tfjChangeMosaicDisplay: function() {
		$(curtfjContentTracker.tfjPrevActiveTabName).className = '';					
		Element.hide(curtfjContentTracker.tfjPrevActiveTab);
		$(curtfjContentTracker.tfjActiveTabName).className = tfjCheckTab(curtfjContentTracker.tfjActiveTabName);
		$(curtfjContentTracker.tfjPrevActiveTabName).style.width = '123px';
		$(curtfjContentTracker.tfjActiveTabName).style.width = '223px';
		$(curtfjContentTracker.tfjActiveTab).style.display = 'block';

if (curtfjContentTracker.tfjActiveTab == "tfjVideoCmpnt") {		
	tfjTriggerVideo();
}
		
	}
}


function tfjTriggerVideo(tabClick) {

vidString = 'Default';
	if (tfjDefaultTab == null || tfjDefaultTab != 'tfjSTCVideo')
		vidString = 'NonDefault';

	if (typeof videoJsonUrls != "undefined") {
		if (videoJsonUrls.length < 2) {
			vidString = 'Single'+vidString;
		} else {
			vidString = 'Multi'+vidString;
		}
	}

if (tabClick) {
	if(defaultVideo == ""){
		tfjPlaylistManager.getInstance('mos').MOSCLoadFromArray(videoJsonUrls);
	}else{
		tfjPlaylistManager.getInstance('mos').MOSCLoadFromArray(videoJsonUrls, defaultVideo);
	}
} else {
	Event.observe(window, 'load', function() {
		if(defaultVideo == ""){
			tfjPlaylistManager.getInstance('mos').MOSCLoadFromArray(videoJsonUrls);
		}else{
			tfjPlaylistManager.getInstance('mos').MOSCLoadFromArray(videoJsonUrls, defaultVideo);
		}
	});
}

}

function inittfjContentTracker() {
	curtfjContentTracker = new tfjContentTracker('curtfjContentTracker');
}

function tfjToggleMPMod(el) {
	//accordion(document.getElementById(el).getElementsByTagName('h3')[0]);
}


function setPartnerID (id) { //for clickability
	var tfjPID;
	var tfjIsIntl = (location.hostname.indexOf('edition.') > -1) ? true : false;
		switch(id) {
			case 'tfjTxtCmpnt':
				tfjPID = (tfjIsIntl) ? 212106 : 211911;
			break;
			case 'tfjVideoCmpnt':
				tfjPID = (tfjIsIntl) ? 205026 : 89487;
			break;
			case 'tfjPhotoCmpnt':
				tfjPID = (tfjIsIntl) ? 212111 : 211916;
			break;
			case 'otherTab1':
			case 'otherTab2':
				tfjPID = (tfjIsIntl) ? 212126 : 211921;
			break;
		}
			return tfjPID
	
	}

function findClickabilityPrintTop(startId)
{
	var snapshotBtn = document.getElementById(startId);
	for(var i=0;i<snapshotBtn.childNodes.length;i++)
	{
		if( (snapshotBtn.childNodes.item(i).nodeType==1) && (snapshotBtn.childNodes.item(i).nodeName=='DIV') && (snapshotBtn.childNodes.item(i).className=='tfjSnapShotHeader'))
		{
			var storyToolsContainerNode = snapshotBtn.childNodes.item(i);
			for(var x=0;x<storyToolsContainerNode.childNodes.length;x++)
			{
				if( (storyToolsContainerNode.childNodes.item(x).nodeType==1) && (storyToolsContainerNode.childNodes.item(x).nodeName=='DIV') && (storyToolsContainerNode.childNodes.item(x).className=='tfjStoryTools') )
				{
					var storyToolsNode = storyToolsContainerNode.childNodes.item(x);
					for(var y=0;y<storyToolsNode.childNodes.length;y++)
					{
						if( (storyToolsNode.childNodes.item(y).nodeType==1) && (storyToolsNode.childNodes.item(y).nodeName=='UL'))
						{
							var ULcontainer = storyToolsNode.childNodes.item(y);
							//now get the LIs
							for(var z=0;x<ULcontainer.childNodes.length;z++)
							{
								if((ULcontainer.childNodes.item(z).nodeType==1) && (ULcontainer.childNodes.item(z).nodeName=='LI') && (ULcontainer.childNodes.item(z).className=='tfjPrintThis'))
								{
									return ULcontainer.childNodes.item(z);
									z = ULcontainer.childNodes.length;
								}
							}
							y=storyToolsNode.childNodes.length;
						}	
					}
					x=storyToolsContainerNode.childNodes.length;
				}	
			}
			i=snapshotBtn.childNodes.length;
		}
	}

}

function findClickabilityPrintBot(startId)
{
	var snapshotBtn = document.getElementById(startId).parentNode;
	for(var i=0;i<snapshotBtn.childNodes.length;i++)
	{
		if( (snapshotBtn.childNodes.item(i).nodeType==1) && (snapshotBtn.childNodes.item(i).nodeName=='DIV') && (snapshotBtn.childNodes.item(i).className=='tfjStoryToolsFooter') )
		{
			var storyToolsContainerNode = snapshotBtn.childNodes.item(i);
			for(var x=0;x<storyToolsContainerNode.childNodes.length;x++)
			{
				if( (storyToolsContainerNode.childNodes.item(x).nodeType==1) && (storyToolsContainerNode.childNodes.item(x).nodeName=='DIV') && (storyToolsContainerNode.childNodes.item(x).className=='tfjStoryTools') )
				{
					var storyToolsNode = storyToolsContainerNode.childNodes.item(x);
					for(var t=0;t<storyToolsNode.childNodes.length;t++)
					{
						if( (storyToolsNode.childNodes.item(t).nodeType==1) && (storyToolsNode.childNodes.item(t).nodeName=='UL'))
						{
							var ULcontainer = storyToolsNode.childNodes.item(t);
							//now get the LIs
							for(var z=0;z<ULcontainer.childNodes.length;z++)
							{
								if((ULcontainer.childNodes.item(z).nodeType==1) && (ULcontainer.childNodes.item(z).nodeName=='LI') && (ULcontainer.childNodes.item(z).className=='tfjPrintThis'))
								{
									return ULcontainer.childNodes.item(z);
									z = ULcontainer.childNodes.length;
								}
							}
							t=storyToolsNode.childNodes.length;
						}
					}
					x= storyToolsContainerNode.childNodes.length;
				}	
			}
			i=snapshotBtn.childNodes.length;
		}	
	}

}

function tfjSetClickability(component) {
	var tfjPrintBtns = new Array();
	//get the top button
	tfjPrintBtns.push( findClickabilityPrintTop('tfjSnapShot') );
	tfjPrintBtns.push( findClickabilityPrintBot('tfjHighLightTrigger') );
	
	if (component.toLowerCase() != 'tfjtxtcmpnt') {
		for (var f = 0; f<tfjPrintBtns.length;f++) {
			if ($(tfjPrintBtns[f])) {
				$(tfjPrintBtns[f]).hide();
			}
		}
	} else {
		for (var f = 0; f<tfjPrintBtns.length;f++) {
			if ($(tfjPrintBtns[f])) {
				$(tfjPrintBtns[f]).show();
			}
		}
	}

	clickURL = window.location.href;		
partnerID = setPartnerID(component);
commonLoc="&fb=Y&url="+escape(getClickURL())+"&title="+escape(getClickTitle())+"&random="+Math.random()+"&partnerID="+partnerID+"&expire="+escape(getClickExpire());

}

function tfjCheckTab(tabID){
	var tabs = $$('div#tfjTabNav li');
	var firstTab = tabs[0]
	var lastTab = tabs[tabs.length - 1];
	if (tabID == firstTab.id) {
		$('tfjMainContent').className = "tfjFirstTabActive";
		return "currentLeft";
	} else if (tabID == lastTab.id) {
		$('tfjMainContent').className = "";
		return "currentRight";
	} else {
		$('tfjMainContent').className = "";
		return "current";
	}
}

//tfj namespace
var tfj = {};

tfj.detectBrowser = function() {
			var ua=navigator.userAgent.toLowerCase();
	return {
		init: function() {
		},
		isOpera: function() {
			if (ua.indexOf('opera')>-1) {
				return true;
			} else {
				return false;
			}
		},
		isSafari: function() {
			if (ua.indexOf('safari')>-1) {
				return true;
			} else {
				return false;
			}
		},
		isGecko: function() {
			if (!this.isOpera() && !this.isSafari() &&ua.indexOf('gecko')>-1) {
				return true;
			} else {
				return false;
			}
		},
		isIE: function() {
			if(!this.isOpera() && ua.indexOf('msie')>-1) {
				return true;
			} else {
				return false;
			}
		},
		isIE6: function() {
			if(this.isIE && ua.indexOf('msie 6.') > -1) {
				return true;
			} else {
				return false;
			}
		}		
	}
} ();


function tfj_changeImg(which,flag) {
	switch(which) {
		case "tfjImgChngrNxtBtn":
			switch (flag) {
				case 1:
					document.getElementById(which).src = "http://i.l.tfj.net/tfj/.element/img/2.0/global/pic_changer/next_over.gif"
				break;
				default:
					document.getElementById(which).src = "http://i.l.tfj.net/tfj/.element/img/2.0/global/pic_changer/next.gif"				
			}
		
		break;
		case "tfjImgChngrPrvsBtn":
			switch (flag) {
				case 1:
					document.getElementById(which).src = "http://i.l.tfj.net/tfj/.element/img/2.0/global/pic_changer/prev_over.gif"
				break;
				default:
					document.getElementById(which).src = "http://i.l.tfj.net/tfj/.element/img/2.0/global/pic_changer/prev.gif"				
			}		
		break;
		
		default:
	}
}


function tfj_imageChanger(id, url,numSlides,chngrPos) {
	this.id = id;
	this.url = url;
	this.chngrPos = chngrPos;
	this.numSlides = numSlides;
	this.currentSlidePos = 0;
	this.disabledNxtBtn = 'http://i.l.tfj.net/tfj/.element/img/2.0/content/in_the_news/right_gray_btn.gif';
	this.enabledNxtBtn = 'http://i.l.tfj.net/tfj/.element/img/2.0/global/pic_changer/next.gif';
	this.disabledPrvsBtn = 'http://i.l.tfj.net/tfj/.element/img/2.0/content/in_the_news/left_gray_btn.gif';
	this.enabledPrvsBtn = 'http://i.l.tfj.net/tfj/.element/img/2.0/global/pic_changer/prev.gif';
	this.nxtLnkNode;
	this.prvsLnkNode;
	this.nxtLnkActive = true;
	this.prvLnkActive = false;
	
	this.tfj_navChngInitLoad();
}

function tfj_navChngInitLoad() { //make initial http request

	var totalImg = this.numSlides + 1;
	var currentImg = this.currentSlidePos + 1;
	
			new Ajax.Updater({success: this.id}, this.url,
			{
				onComplete:function(obj) {
					$('tfjImgChngrLbl').innerHTML = currentImg + " of " + totalImg;
					tfj_ArticleChanger.tfj_navDisablePrvsBtn();
				},
				method:'get',
				evalScripts:true,
				asynchronous:true
				})
}
tfj_imageChanger.prototype.tfj_navChngInitLoad = tfj_navChngInitLoad;

function tfj_navChngFrwd() {
	if (this.currentSlidePos < this.numSlides) {
		this.currentSlidePos++;
	} else {
		this.currentSlidePos = 0;
	}
	this.url = 'imgChng/p'+this.chngrPos+'-'+this.currentSlidePos+'.exclude.html';
	this.tfj_navChngManage();
}
tfj_imageChanger.prototype.tfj_navChngFrwd = tfj_navChngFrwd;

function tfj_navChngBack() { //update pos, update url

	if (this.currentSlidePos > 0) {
		this.currentSlidePos--;
	} else {
		this.currentSlidePos = this.numSlides;
	}
	this.url = 'imgChng/p'+this.chngrPos+'-'+this.currentSlidePos+'.exclude.html';
	this.tfj_navChngManage();
}
tfj_imageChanger.prototype.tfj_navChngBack = tfj_navChngBack;

function tfj_navChngManage() { //make http request
	var url = this.url;
	var id = 'tfjImgChngrNested';
	var totalImg = this.numSlides + 1;
	var currentImg = this.currentSlidePos + 1;
	
	if(this.currentSlidePos == this.numSlides && this.nxtLnkActive) {
		this.tfj_navDisableNextBtn();
	} else {
		if (!this.nxtLnkActive) {
			this.tfj_navEnableNextBtn();
		}
	}
	
	if (this.currentSlidePos == 0) {
		this.tfj_navDisablePrvsBtn();
	} else {
		if (!this.prvsLnkActive) {
			this.tfj_navEnablePrvsBtn();
		}	
	}
	
new Effect.Opacity(id,
{
	duration:.5,
	from:1.0,
	to:0,

	afterFinish: function() {
		new Ajax.Updater({success: id}, url,
		{
			onComplete:function() {
						$('tfjImgChngrLbl').innerHTML = currentImg + " of " + totalImg;
			},
			method:'get',
			evalScripts:true,
			asynchronous:true
		})	
	}
})

}
tfj_imageChanger.prototype.tfj_navChngManage = tfj_navChngManage;

function tfj_navEnableNextBtn() {
var enabledBtn = this.enabledNxtBtn;
this.nxtLnkNode = $('tfjImgChngrNxtLbl').getElementsByTagName('a')[0];

	$('tfjImgChngrNxtBtn').src = enabledBtn;
	this.nxtLnkNode.onmouseout = function() {tfj_changeImg('tfjImgChngrNxtBtn')};
	this.nxtLnkNode.onmouseover = function() {tfj_changeImg('tfjImgChngrNxtBtn',1)};
	this.nxtLnkNode.style.cursor = 'pointer';
	this.nxtLnkNode.onclick = function() { tfj_ArticleChanger.tfj_navChngFrwd(); return false;};
	this.nxtLnkActive = true;
}
tfj_imageChanger.prototype.tfj_navEnableNextBtn = tfj_navEnableNextBtn;


function tfj_navDisableNextBtn() {
var disabledBtn = this.disabledNxtBtn;
this.nxtLnkNode = $('tfjImgChngrNxtLbl').getElementsByTagName('a')[0];

	$('tfjImgChngrNxtBtn').src = disabledBtn;
	this.nxtLnkNode.onmouseout = function() {$('tfjImgChngrNxtBtn').src = disabledBtn};
	this.nxtLnkNode.onmouseover = function() {};
	this.nxtLnkNode.style.cursor = 'default';
	this.nxtLnkNode.onclick = function() { return false;};
	this.nxtLnkActive = false;
}
tfj_imageChanger.prototype.tfj_navDisableNextBtn = tfj_navDisableNextBtn;

function tfj_navEnablePrvsBtn() {
var enabledBtn = this.enabledPrvsBtn;
this.prvsLnkNode = $('tfjImgChngrPrvsLbl').getElementsByTagName('a')[0];

	$('tfjImgChngrPrvsBtn').src = enabledBtn;
	this.prvsLnkNode.onmouseout = function() {tfj_changeImg('tfjImgChngrPrvsBtn')};
	this.prvsLnkNode.onmouseover = function() {tfj_changeImg('tfjImgChngrPrvsBtn',1)};
	this.prvsLnkNode.style.cursor = 'pointer';
	this.prvsLnkNode.onclick = function() { tfj_ArticleChanger.tfj_navChngBack(); return false;};
	this.prvsLnkActive = true;
}
tfj_imageChanger.prototype.tfj_navEnablePrvsBtn = tfj_navEnablePrvsBtn;


function tfj_navDisablePrvsBtn() {
var disabledBtn = this.disabledPrvsBtn;
this.prvsLnkNode = $('tfjImgChngrPrvsLbl').getElementsByTagName('a')[0];

	$('tfjImgChngrPrvsBtn').src = disabledBtn;
	this.prvsLnkNode.onmouseout = function() {$('tfjImgChngrPrvsBtn').src = disabledBtn};
	this.prvsLnkNode.onmouseover = function() {};
	this.prvsLnkNode.style.cursor = 'default';
	this.prvsLnkNode.onclick = function() { return false;};
	this.prvsLnkActive = false;
}
tfj_imageChanger.prototype.tfj_navDisablePrvsBtn = tfj_navDisablePrvsBtn;

function tfj_loadImg(id) {
new Effect.Opacity(id,
				{
					duration:.5,
					from:0,
					to:1.0
				});
}
 
function tfj_noFlash() {
	var tfjNoFlashMsg = "<div class=\"tfjNoFlashContainer\"><div class=\"tfjNoFlash\"><p class=\"tfjTopGraf\">This tfj.com feature is optimized for Adobe Flash Player version 8 or higher.<\/p>"
	
	if (parseInt(tfj_FlashDetect.prototype.getVersion())) {
		tfjNoFlashMsg += "<p><b>You are currently using Flash Player " + parseInt(tfj_FlashDetect.prototype.getVersion()) + "<\/b><\/p>";
	} else {
		tfjNoFlashMsg += "<p><b>You do not currently have the player installed.<\/b><\/p>";
	}
	
	tfjNoFlashMsg += "<a href=\"http://www.adobe.com/go/getflashplayer\" target=\"blank\"><img src=\"http://i.l.tfj.net/tfj/.element/img/2.0/global/noflash/install_btn.gif\" class=\"tfjGetBtn\" width=\"155\" height=\"31\" alt=\"Get Flash Player\" border=\"0\"><\/a><\/div><\/div>";
	try {
		new Insertion.Top($(curtfjContentTracker.tfjActiveTab), tfjNoFlashMsg); 
	} catch(e) {
		Event.observe(window, 'load', function() {
			var tfjActiveFlashContainer;	
			switch(tfjDefaultTab) {
				case 'tfjSTCVideo':
					tfjActiveFlashContainer = 'tfjVideoCmpnt';
				break;
				case 'tfjSTCPhoto':
					tfjActiveFlashContainer = 'tfjPhotoCmpnt';
				break;
				case 'tfjSTCOther1':
					tfjActiveFlashContainer = 'otherTab1';
				break;
				case 'tfjSTCOther2':
					tfjActiveFlashContainer = 'otherTab2';
				break;
				case 'tfjSTCText':
				default:
					tfjActiveFlashContainer = 'tfjTxtCmpnt';

			}
			new Insertion.Top($(tfjActiveFlashContainer), tfjNoFlashMsg); 
		});
	}
}

function onEmailClicked() {
	if (typeof ET == 'function') {
		ET();
	}
}

function tfjad_refreshAdInDiv(divId)
{
	var d = document.getElementById(divId);
	var subDivs = d.getElementsByTagName('div');
	var testString = 'ad-';

	for (var i = 0; i < subDivs.length; i++)
	{
		if (subDivs[i].id.substring(0,testString.length) ==
testString)
		{
			var iframes =
subDivs[i].getElementsByTagName('iframe');
			var iframeId =
subDivs[i].id.substring(testString.length);

			for (var k = 0; k < iframes.length; k++)
			{
				if (iframes[k].id == iframeId)
				{
	
iframes[k].contentWindow.location.reload();
				}
			}
		}
	}
}

function tfjFindAdInsertSpot(id) {
var tfjStringComplete = 'ds';
var tfjTriggerAdCall = true;
	var d = document.getElementById(id);
	var subDivs = d.getElementsByTagName('div');
	for (var i = 0; i < subDivs.length; i++)
	{
		if(subDivs[i].className == 'tfjMosaicSubElementCol') {
			if (!$(id+"AdContainer")) {
				 new Insertion.Bottom(subDivs[i], "<div id=\""+id+"AdContainer\"><div class=\"tfjStoryElementBox\"><div class=\"tfjStoryElementBoxAd\"><div class=\"tfjStoryElementBoxAdHead\"><img src=\"http://i.l.tfj.net/tfj/.element/img/2.0/content/a"+tfjStringComplete+"/advertisement.gif\" alt=\"advertisement\"></div><div id=\""+id+"AdContent\"><\/div><\/div><\/div><\/div>");
			}

	if (id == 'tfjPhotoCmpnt') {
		if (typeof tfjPhotoCmpntAd == "undefined") {
			tfjTriggerAdCall = false;
		}
		
	}
	if (id == 'tfjVideoCmpnt') {
		if (typeof tfjVideoCmpntAd == "undefined") {
			tfjTriggerAdCall = false;
		}
		
	}
	if (id == 'otherTab1') {
		if (typeof otherTab1Ad == "undefined") {
			tfjTriggerAdCall = false;
		}
		
	}
	if (id == 'otherTab2') {
		if (typeof otherTab2Ad == "undefined") {
			tfjTriggerAdCall = false;
		}
		
	}
			if (tfjTriggerAdCall) {
				tfjUpdateAdInDiv($(id+"AdContent"), eval(id+'Ad'));
			}
		}
	}

	
}

function tfjUpdateAdInDiv(id,path)
{
				new Ajax.Updater({success: id}, path,
					{
						onComplete:function() {
						},
						method:'get',
						evalScripts:true,
						asynchronous:true
					}
				);

}

tfj_omniture = {};

tfj_omniture.Load = new function() { //called when a tab is clicked. will need to trigger for default component too I guess
var configFileURL = (location.hostname.indexOf('edition.') == -1) ? "http://i.l.tfj.net/tfj/.element/js/2.0/mosaic_omniture.js" : "http://i.l.tfj.net/tfj/.element/js/2.0/intl_mosaic_omniture.js"; //url of our config file.

	this.fetchConfigNoTab = function(id){
		var dfltCmpntID;
		switch(id) {
			case 'tfjSTCText':
				dfltCmpntID = 'tfjTxtCmpnt';
			break;
			case 'tfjSTCVideo':
				dfltCmpntID = 'tfjVideoCmpnt';
			break;
			case 'tfjSTCPhoto':
				dfltCmpntID = 'tfjPhotoCmpnt';
			break;
			case 'tfjSTCOther1':
				dfltCmpntID = 'otherTab1';
			break;
			case 'tfjSTCOther2':
				dfltCmpntID = 'otherTab2';
			break;
			default:
				dfltCmpntID = 'tfjTxtCmpnt';

		}
		
		this.fetchConfig(dfltCmpntID);
		
	}

var tfjQueryParams = new Array(); //where we'll stuff values
 
this.fetchConfig = function(stc) {
 
 switch(stc) {
 			case 'tfjTxtCmpnt':
 			default: //stuffing content type and url into array based on component
					tfjQueryParams = [{contentType:'article',contentURL:location.pathname+'%23tfjSTCText',containerURL:location.pathname}]
			break;
			case 'tfjVideoCmpnt':
					tfjQueryParams = [{contentType:'video',contentURL:location.pathname+'%23tfjSTCVideo',containerURL:location.pathname}]
			break;
			case 'tfjPhotoCmpnt':
					tfjQueryParams = [{contentType:'photo',contentURL:location.pathname+'%23tfjSTCPhoto',containerURL:location.pathname}]
			break;
			case 'otherTab1':
					var tfjOtherTab1ContentType = ( typeof tfjOtherTab1Label != "undefined") ? tfjOtherTab1Label : 'other';
					tfjQueryParams = [{contentType:tfjOtherTab1ContentType,contentURL:location.pathname+'%23tfjSTCOther1',containerURL:location.pathname}]
			break;
			case 'otherTab2':
					var tfjOtherTab2ContentType = ( typeof tfjOtherTab2Label != "undefined") ? tfjOtherTab2Label : 'other';
					tfjQueryParams = [{contentType:tfjOtherTab2ContentType,contentURL:location.pathname+'%23tfjSTCOther2',containerURL:location.pathname}]
			break;
 }
 
 		requestConfig(); //call function that writes config js to page
		return false;
 }


	function requestConfig() {
//	alert(configFileURL);

	
	if ($('tfj_omnitureScript')) { //if the config script is already written to the page, remove it
		$('tfj_omnitureScript').remove();
	}
	
		//if(location.hostname.indexOf('edition.') == -1) {
	        var script = document.createElement('script'); //create config script
	        script.setAttribute('id','tfj_omnitureScript'); //id config script
	        script.src = configFileURL + '?contentType='+tfjQueryParams[0]['contentType']+'&contentURL='+tfjQueryParams[0]['contentURL']+'&containerURL='+tfjQueryParams[0]['containerURL']; //populate src passing values from array on query string
	        window.setTimeout( function() {
	       document.body.appendChild(script); //append as last element in the page
	       }, 1000);
		//}
	}
}

function getFlashMovieObject(movieName) {
        if (window.document[movieName]) {
                return window.document[movieName];
        }
        if (navigator.appName.indexOf("Microsoft Internet")==-1) {
                if (document.embeds && document.embeds[movieName]) {
                        return document.embeds[movieName];
                }
        } else  {
                if (document.getElementById(movieName)) {
                return document.getElementById(movieName);
                } else {
                        return null;
                }
        }
}

var tfj_other1ContentSWFString;
var tfj_other2ContentSWFString;


function tfj_unloadFlashMovie(id)
{
	var tfjTabFlashObject=getFlashMovieObject(id);
	switch(id) {
		case 'tfj_other1ContentSWF':
			tfj_other1ContentSWFString = tfjTabFlashObject.movie;
		break;
		case 'tfj_other2ContentSWF':
			tfj_other2ContentSWFString = tfjTabFlashObject.movie;
		break;
	}
	tfjTabFlashObject.movie = "about:blank";
}

function tfj_loadFlashMovie(id)
{
	var tfjTabFlashObject=getFlashMovieObject(id);
	
	switch(id) {
		case 'tfj_other1ContentSWF':
			if (typeof tfj_other1ContentSWFString == "string") {
				tfjTabFlashObject.movie = tfj_other1ContentSWFString;
			}
		break;
		case 'tfj_other2ContentSWF':
			if (typeof tfj_other2ContentSWFString == "string") {
				tfjTabFlashObject.movie = tfj_other2ContentSWFString;
			}
			break;
		}
}

