
/* Javascript stylesheet */
document.write("<link rel=\"StyleSheet\" href=\"/triumphAssets/css/triumphJavascript.css\" type=\"text/css\" media=\"screen\" />");

/* Javascript Form Builder Stylesheet */
if((navigator.userAgent.toLowerCase().indexOf("netscape6/6") == -1)){
	document.write('<link rel="StyleSheet" href="/triumphAssets/css/triumphFormBuilder.css" type="text/css" media="screen" />');
} 

/******************************************************************************************
Global variables
******************************************************************************************/
var ua = navigator.userAgent.toLowerCase();

/******************************************************************************************
set bolean to detect browsers
******************************************************************************************/
mac = (ua.indexOf("windows") == -1)? true:false; 
safari = (ua.indexOf("safari") != -1)? true:false; 
ie7 = (ua.indexOf("msie 7") != -1)? true:false;
ieMac = ((ua.indexOf("msie") != -1)&&(ua.indexOf("windows") == -1))? true:false;
iepc = (((ua.indexOf("msie 7") != -1)||(ua.indexOf("msie 6") != -1)||(ua.indexOf("msie 5.5") != -1))&&(ua.indexOf("windows") != -1)&&(ua.indexOf("opera") == -1))? true:false;
op7 = (ua.indexOf("opera/7") != -1)? true:false;
op9 = (ua.indexOf("opera/9") != -1)? true:false;
ns6 = (ua.indexOf("netscape6") != -1)? true:false;
ns7 = (ua.indexOf("netscape/7") != -1)? true:false;
ns8 = (ua.indexOf("netscape/8") != -1)? true:false;


/********************************************************************************
 
Name:     		Config
Description: 	Runs on load
 
*********************************************************************************/

function fnConfig() {
	fnFrtTitle();
	fnH3Title();
	//fnFrtHome();
	
	fnFrtNewsLarge();
	fnH2Title();
	fnH2SearchTitle();	
	//fnColourText();
	
	fnBackButton();
	
	// prepare help areas on forms
	if (typeof(fnInitFormHelp) == "function") {
	    fnInitFormHelp();
	}
	//fnSurveyInit(); // Does this need to be in to activate the survey?
}


/********************************************************************************
 
Name:     Flash plugin detect
 
*********************************************************************************/
var flash = new Object();	
flash.installed = false;
if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {		
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {		
			flash.installed = true;					
			flash.version = eval(navigator.plugins[x].description.split('Shockwave Flash ')[1].split('.')[0]);					
			break;
		}
	}
}
else if (window.ActiveXObject) {
	for (x = 2; x <= 20; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {		
				flash.installed = true;	
				flash.version = x;
			}
		}
		catch(e) {}
	}
}




	
/********************************************************************************
 
Name:     			Flash embed
Description:  		Writeout flash code. Fixes Eolas update for IE as well.
@param swf  		String - path to swf file
@param width     	Number - value of movie width
@param height    	Number - value of movie height
@param noFlashID	String - ID of a div to show if flash not installed or wrong version
@param minVersion	Number - version of flash required for this movie
*********************************************************************************/
 
flash.insert = function(swf,width,height,noFlashID,minVersion,wmodeOff) {
	// if greek - add sAssets var path for flash to pull in greek flash
	if(typeof($) != 'undefined' && $('.el-GR').length > 0){
		swf = swf.replace(/sAssetFolder=\/triumphAssets\/flash\/homepage/i,"sAssetFolder=/triumphAssets/flash/homepage/greek");
	}
	// if czech - add sAssets var path for flash to pull in czech flash (it is just a copy - not using greek directly to save confusion)
	if(typeof($) != 'undefined' && $('.cs-CZ').length > 0){
		swf = swf.replace(/sAssetFolder=\/triumphAssets\/flash\/homepage/i,"sAssetFolder=/triumphAssets/flash/homepage/czech");
	}
	// if japan - add sAssets var path for flash to pull in japan flash (it is just a copy - not using greek directly to save confusion)
	if(typeof($) != 'undefined' && $('.ja-JP').length > 0){
		swf = swf.replace(/sAssetFolder=\/triumphAssets\/flash\/homepage/i,"sAssetFolder=/triumphAssets/flash/homepage/japan");
	}
	swf = swf.replace(/\./g,"%2E") // encode periods as %2e	
	
	if(!minVersion){minVersion = 6;}		 // default flash required version is 6.
	
 	if(flash.installed && (flash.version >= minVersion)) {
 		flashObject = '<embed src="'+swf+'" menu="false" quality="high" '
		if (!(wmodeOff == true)) {
			flashObject += 'wmode="transparent" '
		}
		flashObject += 'width="'+width+'px" height="'+height+'px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer"/>'
		document.write(flashObject);
		
		if (noFlashID) {
			fnHideItem(noFlashID);	// non-flash content should be hidden by the JS stylesheet, but in case its not, hide it now.
		}
	} else {
		if (noFlashID) {
			fnShowItem(noFlashID);	// show non-flash content.
		}
	} 
}


/** 
	Version of flash.insert specific for triumph model pages navigation 
*/
flash.insertNav = function(xmlUrl,page) {
	// url in reddot mode contains & so must be encoded so it doesnt split the flash query string
	xmlUrl = xmlUrl.replace(/&amp;/g,"%26").replace(/&/g,"%26");
	
 	if(flash.installed && (flash.version >= 8)) {
 		flashObject = '<embed src="/triumphAssets/flash/navShell.swf?sLocale='+lang+'&sXmlUrl='+xmlUrl+'&sPage='+page+'" menu="false" quality="high" width="810px" height="21px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer"  bgcolor="#000000"/>'
		document.write(flashObject);
		fnHideItem("noFlashContentNav");	
	} else {
		fnHideItem("flashContentNav");
		fnShowItem("noFlashContentNav");
	}
}

/**
	Insert the Triumph strap line "GO YOUR OWN WAY" 
*/
flash.insertStrap = function() {
	if (document.getElementById("strap") && flash.installed) {
		flashObject = '<embed src="/triumphAssets/flash/strap.swf" menu="false" quality="high" width="251px" height="23px" wmode="transparent" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer"  bgcolor="#000000"/>'
		document.getElementById("strap").innerHTML = flashObject;
	}
}
	
	
/**
	Find #frtTitle (bike name and strap line) and replace with flash movie
*/
function fnFrtTitle() {
	if(document.getElementById("frtTitle")) {
		var h2Title = document.getElementById("frtTitle");
		
		if(flash.installed && (flash.version >= 8)) {
			// Replace top title with flash movie
			var topHeadings = h2Title.getElementsByTagName("SPAN");
			var titleText;		
			var strapText;
			var titleFlash;
			
			titleText = escapeHTMLforFRT(topHeadings[0].innerHTML);
			strapText = escapeHTMLforFRT(topHeadings[2].innerHTML);
			
			var langChanged = false;
			if (lang == "cs-CZ") {
				langChanged = true;
				lang = "ja-JP";
			}

			titleSwf = '<embed src="/triumphAssets/flash/h2Title.swf?sLocale='+lang+'&titleText='+titleText+'&strapText='+strapText+'" menu="false" quality="high" width="300px" height="70px" wmode="transparent" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />';

			if (langChanged) {
				lang = "cs-CZ";
			}

			h2Title.innerHTML = "<span class=\"hide\">"+h2Title.innerHTML+"</span>"+titleSwf;	
		}
		
		// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
		h2Title.style.visibility = "visible";
	} 
}	

/**
	Find #frtHome (wide page title) and replace with flash movie
*/
function fnFrtHome() {
	if(document.getElementById("frtHome")) {
		var h2Title = document.getElementById("frtHome");
		
		if(flash.installed && (flash.version >= 8)) {
			// Replace top title with flash movie

			var titleText = escapeHTMLforFRT(h2Title.innerHTML);		
			var titleSwf;
			
			titleSwf = '<embed src="/triumphAssets/flash/h3Title.swf?sLocale='+lang+'&titleText='+titleText+'" menu="false" quality="high" width="534px" height="14px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer"  bgcolor="#070e28" wmode="transparent" />';

			h2Title.innerHTML = "<span class=\"hide\">"+h2Title.innerHTML+"</span>"+titleSwf;	
		}
		
		// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
		h2Title.style.visibility = "visible";
	} 
}	


/**
	Find #frtTitleNews (bike name and strap line) and replace with flash movie
*/
function fnFrtNewsLarge() {
	if(document.getElementById("newsFrtLarge")) {

		var h2TitleNews = document.getElementById("newsFrtLarge");
		
		if(flash.installed && (flash.version >= 8)) {
			// Replace top title with flash movie
			var topHeadings = h2TitleNews.getElementsByTagName("SPAN");
			var titleText;		
			var strapText;
			var titleFlash;
			
			titleText = escapeHTMLforFRT(topHeadings[0].innerHTML);
			strapText = escapeHTMLforFRT(topHeadings[1].innerHTML);

			titleSwf = '<embed src="/triumphAssets/flash/h2TitleNews.swf?sLocale='+lang+'&titleText='+titleText+'&strapText='+strapText+'" menu="false" quality="high" width="600px" height="55px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" bgcolor="#000000" />';

			h2TitleNews.innerHTML = "<span class=\"hide\">"+h2TitleNews.innerHTML+"</span>"+titleSwf;	
		}
		
		// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
		h2TitleNews.style.visibility = "visible";
	} 
}	


/**
	Find all <h2> tags with class "frt" and replace with flash movie with correct font.
*/
function fnH2Title() {
	
	var h2titles = document.getElementsByTagName("H2");
	
	if (flash.installed && (flash.version >= 8)) {		
		var titleText;
		var strapText;
		var titleSwf;
		var backgroundColour;
		
		// loop through all h2 titles, move h2 text into span.hide and insert swf embed after this.
		for (i = 0; i < h2titles.length; i++) {
		
			// Only apply this to h2 tags with the class containing "frt" (some titles must not be replaced)
			if (h2titles[i].className.indexOf("frt") != -1) {
				
				var topHeadings = h2titles[i].getElementsByTagName("SPAN");
								
				titleText = escapeHTMLforFRT(topHeadings[0].innerHTML);
				strapText = escapeHTMLforFRT(topHeadings[1].innerHTML);

				//titleSwf = '<embed src="/triumphAssets/flash/h3TitleNews.swf?sLocale='+lang+'&titleText='+titleText+'&strapText='+strapText+'" menu="false" quality="high" width="534px" height="14px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />';
				titleSwf = '<embed src="/triumphAssets/flash/h3TitleNews.swf?sLocale='+lang+'&titleText='+titleText+'&strapText='+strapText+'" menu="false" quality="high" width="399px" height="14px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />';
				
				h2titles[i].innerHTML = "<span class=\"hide\">" + h2titles[i].innerHTML + "</span>" + titleSwf;
				
				// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
				h2titles[i].style.visibility = "visible";
			}			
		}			
	} else {
		for (i = 0; i < h2titles.length; i++) {
			// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
			h2titles[i].style.visibility = "visible";
		}	
	}	
}

/**
	Find all <h2> tags with id "frtSearch" and replace with flash movie with correct font.
*/
function fnH2SearchTitle() {

	if(document.getElementById("frtSearch")) {

		var myTitle = document.getElementById("frtSearch");
		
		if (flash.installed && (flash.version >= 8)) {		
			var titleText;
			var titleSwf;
			
			titleText = myTitle.innerHTML;
			titleSwf = '<embed src="/triumphAssets/flash/h2Title.swf?sLocale='+lang+'&titleText='+titleText+'&strapText=" menu="false" quality="high" width="300px" height="70px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />';
	
			myTitle.innerHTML = "<span class=\"hide\">" + titleText + "</span>" + titleSwf;		
			
		}	
	}
}

/**
	Find all <h3> tags with class "frt" and replace with flash movie with correct font.
*/
function fnH3Title() {
	
	var h3titles = document.getElementsByTagName("H3");
	
	if (flash.installed && (flash.version >= 8) && lang != "cs-CZ") {		
		var titleText;
		var titleSwf;
		var backgroundColour;
		
		// loop through all h3 titles, move h3 text into span.hide and insert swf embed after this.
		for (i = 0; i < h3titles.length; i++) {
		
			// Only apply this to h3 tags with the class containing "frt" (bike specs page has h3 tags that must not be replaced)
			if (h3titles[i].className.indexOf("frt") != -1) {
			
				titleText = escapeHTMLforFRT(h3titles[i].innerHTML);

				titleSwf = '<embed src="/triumphAssets/flash/h3Title.swf?sLocale='+lang+'&titleText='+titleText+'" menu="false" quality="high" width="228px" height="14px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer"  bgcolor="#070e28" />';

				h3titles[i].innerHTML = "<span class=\"hide\">" + h3titles[i].innerHTML + "</span>" + titleSwf;
				
				// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
				h3titles[i].style.visibility = "visible";
			}			
		}			
	} else {
		for (i = 0; i < h3titles.length; i++) {
			// Show the title whether its flash or normal. It's hidden in the JS.css so no flicker.
			h3titles[i].style.visibility = "visible";
		}	
	}	
}

/** Prepares the innerHTML from an element for use in the querystring of a flash replacement swf.
 * It gets the text content (e.g. < instead of &lt;) and encodes only & and spaces.
 * This is because our FRT swf's use the raw text thats given to them instead of parsing html entities.
 * Also it was not working for japanese text before because it was encoded like &u2145; 
 */
function escapeHTMLforFRT(str) {
	return unescapeHTML(str).replace(/&/g,"%26").replace(/ /g,"%20");
}

/* from prototype */
function escapeHTML(str) {
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}

/* from prototype */
function unescapeHTML(str) {
   try {
     var div = document.createElement('div');
     div.innerHTML = str.replace(/<\/?[^>]+>/gi, '');
     return div.childNodes[0].nodeValue;
   } catch (e) {
     return str;  // sometimes it goes wrong, like when str is empty.
   }
}

function fnHideItem(targ) {
	document.getElementById(targ).style.position = "absolute";
	document.getElementById(targ).style.top = "-3000px";
	document.getElementById(targ).style.left = "-3000px";
	}
	
function fnShowItem(targ) {
	document.getElementById(targ).style.position = "static";		// relative was not showing up in IE
	document.getElementById(targ).style.top = "0";
	document.getElementById(targ).style.left = "0";
	}	



/********************************************************************************
 
Name:     		fnRightColShowHide
Description: 	Show / Hide the right column bike details.  Anchor contains link to ID 
				of element to show/hide.  JS tales the url, splits string to get ID 
				after the "#", and uses this ID to target element to show/hide.

*********************************************************************************/	
	
function fnRightColShowHide(targ) {
	
	fnSelectMe(targ);
	
	var rightColDetails = document.getElementById("rightColShowHide").getElementsByTagName("DIV");
	
	for (i=0;i<rightColDetails.length;i++) { /* Loop through to hide all items */
		rightColDetails[i].style.display = "none";	
		}	
	
	var showItem = targ.href.split("#")[1];	/* Get ID from link */
	document.getElementById(showItem).style.display = "block";	
	
	}		
	
	
	
/********************************************************************************
 
Name:     		fnSelectMe
Description: 	Sets class "selected" on the LI in the itinerary nav list that is 
				clicked on

*********************************************************************************/	
function fnSelectMe(obj) {
	var listItems = obj.parentNode.parentNode.getElementsByTagName("LI");
	
	for (i=0;i<listItems.length;i++) {
		listItems[i].className = "";
	}	
	
	obj.parentNode.className = "selected";
}	





function fnRightColShPagination(direction) {

	//alert(direction);
	var menuItems = document.getElementById("rightColShMenu").getElementsByTagName("LI");
	
	for (i=0;i<menuItems.length;i++) {
	
		var totalItems = menuItems.length;
	
		if(menuItems[i].className == "selected") {
			if(direction == "prev") {
				if(i<=0) {
					pagedItem = menuItems[i+(totalItems-1)];	
				}
				if((i>0)&&(i<(totalItems))) {
					pagedItem = menuItems[i-1];	
				}	
				if(i>(totalItems-1)) {
					pagedItem = menuItems[i-(totalItems-1)];	
				}						
			}
			if(direction == "next") {
				pagedItem = menuItems[i+1];						
				if(i<=0) {
					pagedItem = menuItems[i+1];
				}
				if((i>0)&&(i<(totalItems))) {
					pagedItem = menuItems[i+1];
				}	
				if(i>=(totalItems-1)) {
					pagedItem = menuItems[i-(totalItems-1)];
				}		
			}
			

			fnRightColShowHide(pagedItem.childNodes[0]);
		}
	}	

}


/********************************************************************************

Name:     fnPopup
Description: Standard popup, but takes target from href on link.  Scrollbars are 
hidden unless screen resolution is less than 1024 x 768, when scrollbars are present.
 
*********************************************************************************/

function fnPopup(targ, width, height) {
	var obj = targ.href;
	var sScreenX = screen.width;
	var sScreenY = screen.height;
	var x = sScreenX - width;
	var y = sScreenY - height;
	var winLeft = x/2;
	var winTop =  y/2;	
	var scrollStatus = "no";
	
	if ((screen.width>=1024) && (screen.height>=768)) {
 		var scrollStatus = "no";
		}
	else {
  		var scrollStatus = "yes";
		}

	window.open(obj,"","width=" + width + ",height="+ height + ",scrollbars=" + scrollStatus + ",left=" + winLeft + ",top=" + winTop + ",resizable=yes, status=no");	
}
	
/* For backwards compatibility with the function in the old triumph.js file - it may be used in existing text editor attributes */
function fnPopUp(href, height, width) {
	var targ = new Object();
	targ.href = href;
	fnPopup(targ, width, height);
}	

/***********************************************************************************
fnPopupAudio : Pops up a audio player in new window, using the href of the given 
					<a> object as the audio file. 
					
					Usage: <a href="me.mp3" onclick="return fnPopupAudio(this)" title="Window Title" target="_blank">AUDIO LINK</a>
***********************************************************************************/
function fnPopupAudio(targ) {

	// build dummy href object with the url to the sound popup player
	var targ2 = new Object();
	targ2.href = "/sharedContent/sound/popupSound.asp?file=" + targ.href + "&title=" + targ.title;
	
	// Show sound popup using existing fnPopup
	fnPopup(targ2, 371, 150);
	
	// return false so that you can use it like onclick="return fnPopupAudio(this)"
	return false;
}

/***********************************************************************************
fnPopupVideo : Pops up a video player in new window, using the href of the given 
					<a> object as the video file. Width and height are the size of the video file.
					
					Usage: <a href="me.mov" onclick="return fnPopupVideo(this,320,240)" title="Window Title" target="_blank">MOVIE LINK</a>
***********************************************************************************/
function fnPopupVideo(targ, width, height) {
	
	// build dummy href object with the url to the sound popup player
	var targ2 = new Object();
	
	// If video file ends with "flv" then use flv player, else quicktime movie player.
	if (targ.href.toLowerCase().lastIndexOf(".flv") == targ.href.length - 4) {
		targ2.href = targ.href + "&title=" + targ.title;
		// size of popup is always the same
		width = 526;
		height = 412;
	}
	else {
		targ2.href = "/sharedContent/movie/popupMovie.aspx?width=" + width + "&height=" + height + "&video=" + targ.href + "&title=" + targ.title;
		// size of popup is this amount larger than the movie file.
		width = width + 40;
		height = height + 105
	}
	
	// Show video popup using existing fnPopup
	fnPopup(targ2, width, height);
	
	// return false so that you can use it like onclick="return fnPopupVideo(this,320,240)"
	return false;
}

/********************************************************************************
 
Name:     		fnGalleryThumb
Description: 	

*********************************************************************************/	
 
 function fnGalleryThumb(targ,medImage,largeImage) {
 	
	
	//var medImage = (targ.getElementsByTagName("img")[0].src.split("_")[0])+ "_med.jpg";	/* Get ID from link */
	//var largeImage = (targ.getElementsByTagName("img")[0].src.split("_")[0])+ "_large.jpg";
	
	//var largeImage = targ.href;
	var thumbAlt = targ.getElementsByTagName("img")[0].alt;
	
	
	/* For Gallery page only */
	if(document.getElementById("galleryHeroBot")) {
		document.getElementById("galleyHero").getElementsByTagName("img")[0].src = medImage;	
		document.getElementById("galleyHero").getElementsByTagName("a")[0].href = largeImage;	
		document.getElementById("largeImageLink").href = largeImage;
		
		if (document.getElementById("galleryHeroCaption")) {
			if (thumbAlt.length == 0) {
				thumbAlt = "&nbsp;";
			}
			document.getElementById("galleryHeroCaption").innerHTML = thumbAlt;
		}
	}
	
	
	/* For Colour page only */
	/* Takes alt text from thumbnail image and puts this string within the span with ID of "colourName" */
	
	if(document.getElementById("colourName")) {
		document.getElementById("colourName").innerHTML = thumbAlt;
		document.getElementById("galleyHero").getElementsByTagName("img")[0].src = medImage;
	}
	
	
	
	
	
	
		// Loop through links to set opacity to default, then sets selected link opacity to 50%
		var anchors = document.getElementById("thumbWrapper").getElementsByTagName("LI");	
	
		for (i=0;i<anchors.length;i++) {
			anchors[i].className = "";
			}	
		targ.parentNode.className = "selected";	

 }
 
 /* Set selected colour text as string from alt text on first Item */
 
function fnColourText() {
		if(document.getElementById("colourName")) {
			document.getElementById("colourName").innerHTML = document.getElementById("thumbWrapper").getElementsByTagName("img")[0].alt;
		}
	} 
	
	
	
	/**
 * Gets fired when the user changes country on the new Dealer pages.
 * It will show or hide the state drop down for USA or Canada.
 */
function fnDealerCountryChanged(oDropdown, sIdPrefix) {
	var oUS = document.getElementById(sIdPrefix + "_lstStatesUS");
	var oCA = document.getElementById(sIdPrefix + "_lstStatesCA");
	
	if (oUS && oCA) {		
		// show one if you selected a country that has a state drop.
		if (oDropdown.options[oDropdown.selectedIndex].value == "US") {
			oUS.style.display = "";
			oCA.style.display = "none";
		}
		else if (oDropdown.options[oDropdown.selectedIndex].value == "CA") {
			oCA.style.display = "";
			oUS.style.display = "none";
		}
		else {
			// hide both if any other country chosen.
			oCA.style.display = "none";
			oUS.style.display = "none";
		}
	}
}
	
	
/********************************************************************************

Name: 				Quicktime embed
Description:		Writeout Quicktime code. Fixes Eolas patent bug for IE as well.
@param	mov			String path to mov file
@param	width		Number|String value of movie width
@param	height		Number|String value of movie height

*********************************************************************************/
quicktime = new Object();
quicktime.insert = function(mov,width,height) {
	quicktimeObject = '<embed src="'+mov+'" controller="true" width="'+width+'" height="'+(height+15)+'" type="video/quicktime" pluginspage="http://www.apple.com/qtactivex/qtplugin.cab" scale="tofit" />'
	document.write(quicktimeObject);
}

/********************************************************************************
Name: 				Sound media embed. Will use default media player on system (Quicktime and windows media player mainly)
Description:		Writeout Quicktime code. Fixes Eolas patent bug for IE as well.
@param	mov		String path to sound file
@param	width		Number|String value of width for media player
@param	height	Number|String value of height for media player (44 works well - different players require more/less height)
@param   bgcolor  String hex color for background around media player, if player is narrower than given height (quicktime is) e.g. "#193468"
*********************************************************************************/
soundfile = new Object();
soundfile.insert = function(mov,width,height,bgcolor) {
	quicktimeObject = '<embed src="'+mov+'" controller="true" width="'+width+'" height="'+height+'" type="video/quicktime" pluginspage="http://www.apple.com/qtactivex/qtplugin.cab" bgcolor="'+bgcolor+'" />'
	document.write(quicktimeObject);
}	



// THIS IS FOR BACKWARDS COMPATIBILITY INCASE THE OLD MENU (WHICH POPS UP THE FLASH) IS STILL USED ON THE NEW TEMPLATES.
//--Links to Accessory Popup to a the accessory list for a specific bike--//
function fnLinkToCAPopup(type, sBike){

	var sPopUpUrl;
	var sUrl;
	var scrollStatus = "no";
	
	if ((screen.width>=1024) && (screen.height>=768)) {
 		var scrollStatus = "no";
		}
	else {
  		var scrollStatus = "yes";
		}
	/*  */
	switch(type){
		case "clothing" :
			sPopUpUrl = "clothingAccessoriesPopup.aspx?GID=1&BIKE=" + sBike;
			sUrl = "clothing.aspx"
			break;

		case "accessories" : 	
			sPopUpUrl = "clothingAccessoriesPopup.aspx?GID=2&BIKE=" + sBike;
			sUrl = "accessories.aspx"
			break;
	}
	
	window.open(sPopUpUrl,'CAPopUp','width=1010,height=695,scrollbars=' + scrollStatus + ',resizable=yes, status=no'); 
	document.location.href=sUrl;
}


/*********************************************************************/
/******** Back Button Function for Error Pages (404 and 500) *********/
/*********************************************************************/

/* Runs on load. Only one "strong" tag allowed! */

function fnBackButton() {
	/* Check "error ID exists" */
	if(document.getElementById("error")) {
		var myList = document.getElementById("error").getElementsByTagName("UL"); /* Get the list */
		if (myList.length > 0) {
		    var myBackButton = myList[0].getElementsByTagName("STRONG");	/* get the first "strong" tag within the first list */	
		    if (myBackButton.length > 0) {
	            /* Add a link containing back JS around that strong text */		
	            sbackTxt = myBackButton[0].innerHTML;		
	            myBackButton[0].innerHTML = '<a href="javascript: history.go(-1)" class="backButton">'+ sbackTxt +'</a>';
		    }	
		}
	}
}

/*********************************************************************/
/***************** Text Sizing for 2008+ templates *******************/
/*********************************************************************/

    //set the text size that the default body computes to
    if (typeof($) != 'undefined') {
    var n = 10;
    var version = $.browser.version.number();
    var isNetscape = $.browser.netscape();
    $().ready(function(){
	    if(isNetscape==true && version<8){
		    //
	    }else{
		    fnResize();
	    }
    	
	    });
    $.jqem.bind(function(a,b,c) {
	    if(isNetscape==true && version<8){
		    //
	    }else{
		    fnResize();
	    }
	    });
    	
    fnResize = function(){
	    if( $.jqem.current() == n ) {
		    //alert($.jqem.current())
			    $('#wrapper').removeClass('defaultText');
			    $('#wrapper').addClass('graphicText');
		    }else if($.jqem.current() != n){
			    //alert($.jqem.current());
			    $('#wrapper').removeClass('graphicText');
			    $('#wrapper').addClass('defaultText');
		    };
	    };
	    }
	    

/************** jQuery based functions **************/


    if (typeof($) != 'undefined') {
    $(document).ready(function() {
    
        // if we are on the homepage
		if ($("#container.homepage").length > 0) {
				    
		    // do flash replacement text on h3 titles		    	    
		    /*
		    $("#homeFamilyTree h3.e3FRT a")		    			    	
		    	.each(function() {
		    		var sTxt1,sTxt2,sH3Swf,sHtml;	
		    		sHtml = $(this).html().toLowerCase();		    		
		    		sTxt1 = sHtml.split("<span>",1);		    		
		    		sTxt2 = $(this).find("span").text();		    		
		    		sH3Swf = '<embed src="/triumphAssets/flash/tradegothic-172x38.swf?text1='+sTxt1+'&text2='+sTxt2+'&colour=bluewhite&bg=0x112143" menu="false" quality="high" width="172px" height="38px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />';		    		
		    		this.innerHTML = "<span class=\"hide\">"+this.innerHTML+"</span>"+sH3Swf;	
		    	});
		    $("#homeNews h3.e3FRT a")		    			    	
		    	.each(function() {
		    		var sTxt1,sTxt2,sH3Swf,sHtml;	
		    		sHtml = $(this).html().toLowerCase();		    				    		
		    		sTxt1 = sHtml.split("<span>",1);		    		
		    		sTxt2 = $(this).find("span").text();		    		
		    		sH3Swf = '<embed src="/triumphAssets/flash/tradegothic-172x24.swf?text1='+sTxt1+'&text2='+sTxt2+'&colour=bluewhite&bg=0x112143" menu="false" quality="high" width="172px" height="24px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />';		    		
		    		this.innerHTML = "<span class=\"hide\">"+this.innerHTML+"</span>"+sH3Swf;	
		    	});
		    
	    	$("#botLeft h3.e3FRT")		    			    	
		    	.each(function() {
		    		var sTxt1,sTxt2,sH3Swf,sHtml;	
		    		sTxt1 = $(this).text().toLowerCase();		
		    		sTxt1 = escapeHTMLforFRT(sTxt1);
		    		//console.log(sTxt1);
		    		sH3Swf = '<embed src="/triumphAssets/flash/tradegothic-124x38.swf?text1='+sTxt1+'&colour=blue&bg=0xFFFFFF" menu="false" quality="high" width="124px" height="38px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />';		    		
		    		this.innerHTML = "<span class=\"hide\">"+this.innerHTML+"</span>"+sH3Swf;	
		    	});	
		   	*/   
		   
			// sIFR flash titles on homepage
			if(typeof sIFR == "function"){
			
				// sIFR for 3 bot left block titles - local dependant
				
				var swf = 'h3titleHome_en-GB.swf'				
				if($('.el-GR').length>0){				
					swf = 'h3titleHome_el-GR.swf';
					}
				else if($('.cs-CZ').length>0){				
					swf = 'h3titleHome_cs-CZ.swf';
					}

				sIFR.replaceElement(named({sSelector:"#homeFb1 h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#FFFFFF", sBgColor:"#025790"}));		
				sIFR.replaceElement(named({sSelector:"#homeFb2 h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#417CC5", sBgColor:"#102A5B"}));		
				sIFR.replaceElement(named({sSelector:"#homeFb3 h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#417CC5", sBgColor:"#FFFFFF"}));		
				sIFR.replaceElement(named({sSelector:"#partAccFb h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#417CC5", sBgColor:"#FFFFFF"}));		
				sIFR.replaceElement(named({sSelector:"#clothFb h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#417CC5", sBgColor:"#FFFFFF"}));		
				sIFR.replaceElement(named({sSelector:"#homeFamilyTree h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#417CC5", sBgColor:"#112143"}));		
				sIFR.replaceElement(named({sSelector:"#homeNews h3", sFlashSrc:"/triumphAssets/flash/" + swf, sCase: "upper", sColor:"#417CC5", sBgColor:"#112143"}));		
			
			};
	
		    	
		    	
		    $("#homeFamilyTree ul").accordion({   					
		        header: 'h4',
		        selectedClass: 'open',
		        event: 'mouseover',
		        autoHeight: false
		    });	
		    
		    /* Issue with swf not showing */ 
		    //var redraw = $("#homeFamilyTree h3").html();
		    //$("#homeFamilyTree h3").html(redraw);
		    
		}
		
		/* Bike Homepages */ 
		if ($("#bikeLanding").length > 0) {
			
			fnBikeHomeH4Titles();
			
		} // end bike home		
		
		
		
		
	});	
	}


/**
	Find all <h4> tags with straplines and replace with flash movie with correct font.
*/
function fnBikeHomeH4Titles() {
	
	var h4Titles = $(".bike h4");	
		
	if (flash.installed && (flash.version >= 8)) {		
		var title;
		var strap;				
		var localeSwf = (lang == "jp-JP")? 'h4TitleBikeHome_Japan.swf':'h4TitleBikeHome_Europe.swf';
		
		h4Titles .each(function(i) {
			//this.innerHTML = this + " is the element, " + index + " is the position";
			title = escapeHTMLforFRT($(this).html().toLowerCase().split("<span>")[0]).toUpperCase(); // split the html to get the string before the span tag. toLowerCase is cos IE has <SPAN>.
			strap = escapeHTMLforFRT($(this).find("span").text().substr(1)); // strip off the first space so the text lines up in flash
			titleSwf = '<embed src="/triumphAssets/flash/'+localeSwf+'?text1='+title+'&text2='+strap+'" menu="false" quality="high" width="340px" height="40px" type="application/x-shockwave-flash" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer"  bgcolor="#ffffff" />';
			h4Titles[i].innerHTML = "<span class=\"hide\">" + h4Titles[i].innerHTML + "</span>" + titleSwf;
			$(this).css('margin-left','-4px'); // line it up nicely
		});			
	} 	
}


/**
 * Called from the configurator landing page flash movie to launch the popup.
 */
function fnLaunchCreateMyTriumph() {
	fnPopUp('configuratorPopup.aspx',675,870);
}



// Friday night hack - To be removed when solution is found
// ie<6 png 


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

if(window.attachEvent){
window.attachEvent("onload", correctPNG);
}