﻿	/*
	Yamaha-Racing.com JS file.
	This file contains snippets of JavaScript code used throughout the site.
	Please add the location where the function is used so we can maintain the script files better (cleaning old functions and such)
	
	When this file was created (22-2-2008) not all functions could be identified, so I left them in, but please help keep this file clean.
	*/
	
	/*
	-----------------------------------------
	    This function is used in:
	    n/a?
	-----------------------------------------
	*/
	function toggleText(divID,sString) {
		if(document.all){
			 document.getElementById(divID).innerText = sString;
		} else{
			document.getElementById(divID).textContent = sString;
		}
	}
	
	/*
	-----------------------------------------
	    This function is used in:
	    FunStuff pages, E-card section. Function is called from Flash file!
	-----------------------------------------
	*/
	function setEcard(id,name,path) {
		document.ecardForm.ecardId.value = id;
		document.ecardForm.ecardName.value = name;
		document.ecardForm.ecardPath.value = path;
	}
	
	/*
	-----------------------------------------
	    This function is used in:
	    Bottom navigation page.
	-----------------------------------------
	*/
	function bookmark(url,title){
	  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
	  window.external.AddFavorite(url,title);
	  } else if (navigator.appName == "Netscape") {
	    window.sidebar.addPanel(title,url,"");
	  } else {
	    alert("Press CTRL-D (Firefox + Netscape) or CTRL-T (Opera) to bookmark");
	  }
	}
	
	/*
	-----------------------------------------
	    This function is used in:
	    n/a?
	-----------------------------------------
	*/
	function openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}
	
	// NICELY CENTERED POPUP
	function popWindow(strURL,windowname,popwidth,popheight,features){
		var strfeatures;
		strfeatures = 'width='+popwidth+',height='+popheight+','+features;
		if(window.screen){
			var WindowLeft = (screen.width-popwidth)/2;
			var WindowTop = (screen.height-popheight)/2;
			strfeatures = 'top='+WindowTop+',left='+WindowLeft+','+strfeatures;
		}
		var openen=window.open(strURL,windowname,strfeatures);
		openen.focus();
		return false;
	}
	
	
	/*
	###START FLASH RESIZING FUNCTIONS####
	-----------------------------------------
	    This group of functions is used in:
	    Right menu flash file?
	-----------------------------------------
	
	Methods for resizing the flash stage at runtime.
	
	divid: id of the div containing the flash movie.
	newW: new width for flash movie
	newH: new height for flash movie
	
	canResizeFlash()
	returns true if browser supports resizing flash, false if not. 
	*/
	function setFlashWidth(divid, newW){
		document.getElementById(divid).style.width = newW+"px";
	}
	function setFlashHeight(divid, newH){
	    if(window.getContent){
	       getContent()
	    }
		document.getElementById(divid).style.height = newH+"px";
	
	}
	
	function setFlashMenuHeight(divid, newH, bDoReloadImg){
		document.getElementById(divid).style.height = newH+"px";
		
		if(bDoReloadImg){
			loadImages();
		}
		
	}
	
	function setFlashSize(divid, newW, newH){
		setFlashWidth(divid, newW);
		setFlashHeight(divid, newH);
	}
	
	function canResizeFlash(){
		var ua = navigator.userAgent.toLowerCase();
		var opera = ua.indexOf("opera");
		if( document.getElementById ){
			if(opera == -1) return true;
			else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
		}
		return false;
	}
	//###END FLASH RESIZING FUNCTIONS####
	

	// RSS HOMEPAGE FUNCTIONALITY
	function InitHomeRSS(readMore){
		if(!document.getElementById("news")) return;
		var ul = document.getElementById("rssItems");
		rssItems = ul.getElementsByTagName("li");
		totalRssItems = rssItems.length;
		rssItems[currentRssItem].style.display = "block";		
		if(totalRssItems>0) document.getElementById("news").style.display = "block";		
		
		var readMoreLinks = ul.getElementsByTagName("a");
	    for (i=0; i<readMoreLinks.length; i++){
	    	readMoreLinks[i].innerHTML = readMore;
		}
	
		var nav = document.getElementById("RssNav");
		links = nav.getElementsByTagName("a");
	    for (i=0; i<links.length; i++){
	        if(links[i].className.indexOf("left")!=-1){
	        	links[i].onclick = function(){
	        		currentRssItem = setHomepageItem("left",rssItems,totalRssItems,currentRssItem);
	        		return false;
	        	}
			}
	        if(links[i].className.indexOf("right")!=-1){
	        	links[i].onclick = function(){
	        		currentRssItem = setHomepageItem("right",rssItems,totalRssItems,currentRssItem);
	        		return false;
	        	}
			}
	    }
	}
	
	function InitHomeVideos(){
		if(!document.getElementById("video")) return;
		var ul = document.getElementById("videoItems");
		videoItems = ul.getElementsByTagName("li");
		totalVideoItems = videoItems.length;
		videoItems[currentVideoItem].style.display = "block";
		if(totalVideoItems>0) document.getElementById("video").style.display = "block";		
		
		var nav = document.getElementById("VideoNav");
		links = nav.getElementsByTagName("a");
	    for (i=0; i<links.length; i++){
	        if(links[i].className.indexOf("left")!=-1){
	        	links[i].onclick = function(){
	        		currentVideoItem = setHomepageItem("left",videoItems,totalVideoItems,currentVideoItem);
	        		return false;
	        	}
			}
	        if(links[i].className.indexOf("right")!=-1){
	        	links[i].onclick = function(){
	        		currentVideoItem = setHomepageItem("right",videoItems,totalVideoItems,currentVideoItem);
	        		return false;
	        	}
			}
	    }
	}
	
	function setHomepageItem(dir,items,totals,curItem){
		items[curItem].style.display = "none";	
		if(dir=="left"){
			if(curItem==0){
				curItem = totals-1;
			}
			else{
				curItem--; 
			}
		}
		if(dir=="right"){
			if(curItem == totals-1){
				curItem = 0;
			}
			else{
				curItem++; 
			}
		}
		items[curItem].style.display = "block";	
		// JUST SETTING THE 'curItem' WITHIN THIS FUNCTION AS THE NEW currentItem FOR VIDEOS OR RSS ISN'T ENOUGH, 
		// SO RETURN THE NEW VALUE HERE
		return curItem;	
	}


