/*
show flash
*/

function showsubFlash(iUrl,iWidth,iHeight,iWmode)
{
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ iWidth +'" height="' + iHeight +'" />';
	flash = flash + '<param name="movie" value="'+ iUrl +'" />';
	flash = flash + '<param name="quality" value="high" />';
	flash = flash + '<param name="allowScriptAccess" value="always" />';
	flash = flash + '<param name="menu" value="false" />';
	if (iWmode == 1) {
	   flash = flash + '<param name="wmode" value="transparent" />';      
	}
	flash = flash + '<embed src="' + iUrl + '" width="'+ iWidth +'" height="'+ iHeight +'" allowScriptAccess="always"  quality="high" ';
	if (iWmode == 1) {
	   flash = flash + 'wmode="transparent" ';      
	}
	flash = flash + ' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" mwode="transparent"></embed>';
	flash = flash + '</object>';
	return flash;
}


/*
tabs
*/

function setTab2(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		con.style.display=i==cursel?"block":"none";
	}
	scroller = new jsScroller(document.getElementById("con_tab_"+cursel), 250, 120);
	//document.getElementById("nav_on").innerHTML= showsubFlash('images/nav'+cursel+'.swf','250','200',1)
}


/*
scroll
*/

function jsScroller (o, w, h) {
	var self = this;
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className.indexOf("Scroller-Container") > -1) {
			o = list[i];
		}
	}
	
	//Private methods
	this._setPos = function (x, y) {
		if (x < this.viewableWidth - this.totalWidth) 
			x = this.viewableWidth - this.totalWidth;
		if (x > 0) x = 0;
		if (y < this.viewableHeight - this.totalHeight) 
			y = this.viewableHeight - this.totalHeight;
		if (y > 0) y = 0;
		this._x = x;
		this._y = y;
		with (o.style) {
			left = this._x +"px";
			top  = this._y +"px";
		}
	};
	
	//Public Methods
	this.reset = function () {
		this.content = o;
		this.totalHeight = o.offsetHeight;
		this.totalWidth	 = o.offsetWidth;
		this._x = 0;
		this._y = 0;
		with (o.style) {
			left = "0px";
			top  = "0px";
		}
	};
	this.scrollBy = function (x, y) {
		this._setPos(this._x + x, this._y + y);
	};
	this.scrollTo = function (x, y) {
		this._setPos(-x, -y);
	};
	this.stopScroll = function () {
		if (this.scrollTimer) window.clearInterval(this.scrollTimer);
	};
	this.startScroll = function (x, y) {
		this.stopScroll();
		this.scrollTimer = window.setInterval(
			function(){ self.scrollBy(x, y); }, 120
		);
	};
	this.swapContent = function (c, w, h) {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("Scroller-Container") > -1) {
				o = list[i];
			}
		}
		if (w) this.viewableWidth  = w;
		if (h) this.viewableHeight = h;
		this.reset();
	};
	
	//variables
	this.content = o;
	this.viewableWidth  = w;
	this.viewableHeight = h;
	this.totalWidth	 = o.offsetWidth;
	this.totalHeight = o.offsetHeight;
	this.scrollTimer = null;
	this.reset();
};


/*
change style
*/

function o_cookiestyle(){
	
	function getCookie(Name) { 
		var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
		if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
		return null
	}
	
	function setCookie(name, value, days) {
		var expireDate = new Date()
		//set "expstring" to either future or past date, to set or delete cookie, respectively
		var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
		document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
	}
	
	function deleteCookie(name){
		setCookie(name, "moot")
	}
	
	function setStylesheet(title) {
		var i, cacheobj
		for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
			if(cacheobj.getAttribute("rel").indexOf("style") != -1 && cacheobj.getAttribute("title")) {
				cacheobj.disabled = true
				if(cacheobj.getAttribute("title") == title)
					cacheobj.disabled = false //enable chosen style sheet
			}
		}
	}
	
	function setActiveStyleSheet(styletitle){
		if (document.getElementById){
			setStylesheet(styletitle)
			setCookie("mysheet", styletitle, 365)
		}
	}
	
	this.doChange = function( styletitle ){
		setActiveStyleSheet(styletitle);
	}
	
	function init(){
		var selectedtitle=getCookie("mysheet");
		if (document.getElementById && selectedtitle!=null) //load user chosen style sheet if there is one stored
			setStylesheet(selectedtitle);
	}
	
	init();	
}
var o_cs = new o_cookiestyle();
