﻿var tipsIndex = 0;
var req;

var ticker;
var outRight;
var oldRight;

var myBasePath='';

function initMenu(a){
	myBasePath=a;
	tickerComponent();
	getSrc(0);
}


function tickerComponent(){

	if(loadXMLDoc() != null){
		document.write("<div id=\"ticker\">");
			document.write("<a href=\"http://brothermuseum.g.hatena.ne.jp/\" target=_blank><div class=\"ticker-header\"><h1>ブラザー科学館</h1></div></a>");
			document.write("<div class=\"ticker-mid\">");
				document.write("<div id=\"tipsLeft\"></div>");
				document.write("<div id=\"tipsRight\"></div>");
			document.write("</div>");
			document.write("<div id=\"ticker-footer\">");
				document.write("<div class=\"previous\" onmousedown=\"getPrev()\"></div>");
				document.write("<div class=\"next\" onmousedown=\"getNext()\"></div>");
				document.write("<a href=\"http://brothermuseum.g.hatena.ne.jp/keyword/%e3%83%98%e3%83%ab%e3%83%97\" target=_blank><div class=\"hatena\"></div></a>");
			document.write("</div>");
		document.write("</div>");
		
		if(navigator.userAgent.indexOf("Safari") > -1){
			document.writeln('<LINK REL="stylesheet" TYPE="text/css" HREF="' + myBasePath + '/jp/tips/ticker_sf.css">');
		}else if(navigator.appName == "Netscape"){
			document.writeln('<LINK REL="stylesheet" TYPE="text/css" HREF="' + myBasePath + '/jp/tips/ticker_nn.css">');
		}else if(window.opera){
			document.writeln('<LINK REL="stylesheet" TYPE="text/css" HREF="' + myBasePath + '/jp/tips/ticker_op.css">');
		}else if(navigator.appName.indexOf("Microsoft")!=-1){
			document.writeln('<LINK REL="stylesheet" TYPE="text/css" HREF="' + myBasePath + '/jp/tips/ticker_ie.css">');
		}else{
		}
	}
}

function getSrc(i){
	ticker =document.getElementById('ticker');
	outRight = document.createElement('script');
	outRight.src = 'http://cgi.brother.co.jp/cgi-bin/tips/main_rss.cgi?id='+i + '&p=' + myBasePath;
	outRight.charset = 'utf-8';
	if(oldRight != null){
		ticker.replaceChild(outRight,oldRight);
	}
	else{
		ticker.appendChild(outRight);
	}
	oldRight = outRight;
}

function loadXMLDoc() {
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	return XMLhttpObject;
}


function getPrev(){
	getSrc(--tipsIndex);
}


function getNext(){
	getSrc(++tipsIndex);
}

