/*---------------------------------------------------------------*/



/*---------------------------------------------------------------*/



function MESCommon(){



	var ua = navigator.userAgent;

	this.ua = {};

	this.ua.isWin	 = ua.match(/Win/);

	this.ua.isMac	 = ua.match(/Mac/);

	this.ua.isNN4	 = (document.layers);

	this.ua.isNN6	 = ua.match(/Netscape\/6/);

	this.ua.isNN7	 = ua.match(/Netscape\/7/);

	this.ua.isMoz	 = ua.match(/Gecko\//);

	this.ua.isIE	 = (document.all && !window.opera);

	//this.ua.isIEver  = RegExp? ua.match(/MSIE (\d(.\d+)?)/)[1] : undefined;

	this.ua.isSafari = ua.match(/AppleWebkit/);



	this.file_name	       = "font\.js";

	this.shared_dir_name   = "";

	this.shared_dir_path   = this.getSharedDirPath();

}



MESCommon.prototype = {



	initMESCommon : function(){},



	getSharedDirName : function() {

		return this.shared_dir_name;

	},

	getScriptName : function() {

		return this.script_name

	},



	getSharedDirPath : function() {

		var path = "";

		var scriptTags = document.getElementsByTagName("script");

		

		if(RegExp){

			var reg = new RegExp( 'js\/' + this.file_name + '$' );

			for(var i=0; i<scriptTags.length; i++) {

				if(scriptTags[i].src && scriptTags[i].src.match(reg)){

					path = scriptTags[i].src.replace(reg,'');

					break;

				}

			}

		}

		return path? path: this.shared_dir_name;

	},



	loadJS : function() {

		for(var i=0;i<arguments.length;i++)

			document.write('<script type="text/javascript" src="' + this.getSharedDirPath() + 'js/' + arguments[i] + '"><\/script>');



	},



	setStyleSheet : function() {

		for(var i=0;i<arguments.length;i++)

			document.write('<link rel="stylesheet" href="' + this.getSharedDirPath() + 'css/' + arguments[i] + '" type="text/css" title="FontProperty'+ i +'">');

	}

};







/*---------------------------------------------------------------*/





MESCommon.prototype.getActiveCssFileName = function (){

	var cssFile = "";

	cssFile  = (this.ua.isWin)? "win_" : ((this.ua.isMac)? "mac_" : "win_");

	cssFile += (this.ua.isIE)? "ie" : ((this.ua.isMoz)? "nn6" : ((this.ua.isNN7)? "nn6" : ((this.ua.isNN6)? "nn6" : "ie")));

	return cssFile;

}



MESCommon.prototype.getCssFileTitle = function (){

	var ret = new Array();

	ret = [

	{

		suffix: "_b",

		title:	"fontlarge"

	},

	{

		suffix: "",

		title:	"fontmedium"

	},

	{

		suffix: "_s",

		title:	"fontsmall"

	}];

	return ret;

}



MESCommon.prototype.__StyleChangeStep__ = 3;

MESCommon.prototype.setStyleSheetForSS = function (){

	var step = 0;

	var data = this.getCssFileTitle();

	var cssfile = this.getActiveCssFileName();

	if(RegExp){

		for (var i=0; i<data.length; i++){

			document.write('<link rel="stylesheet" href="' + this.getSharedDirPath() + 'css/' + cssfile + data[i].suffix + '.css" type="text/css" title="' + data[i].title + '">');

			step += 1;

		}

	}

	return (step==this.__StyleChangeStep__);

}







/*---------------------------------------------------------------*/



/*---------------------------------------------------------------*/





function StyleSwitcher(){

	this.__SwitcherEnabled__ = true;

	var cookie = this.readCookie("style");

	this.__Active_Switcher_Button__ = cookie? cookie : this.getPreferredStyleSheet();

}



StyleSwitcher.prototype.setActiveStyleSheet = function(title) {

  var i, a, main;

  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") == title){

	a.disabled = false;

      }

    }

  }

}



StyleSwitcher.prototype.getActiveStyleSheet = function() {

  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;

}



StyleSwitcher.prototype.getPreferredStyleSheet = function() {

  var i, a;

  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {

    if(a.getAttribute("rel").indexOf("style") != -1

       && a.getAttribute("rel").indexOf("alt") == -1

       && a.getAttribute("title")

       ) return a.getAttribute("title");

  }

  return null;

}



StyleSwitcher.prototype.createCookie = function(name,value,days) {

  if (days) {

    var date = new Date();

    date.setTime(date.getTime()+(days*24*60*60*1000));

    var expires = "; expires="+date.toGMTString();

  }

  else expires = "";

  document.cookie = name+"="+value+expires+"; path=/";

}



StyleSwitcher.prototype.readCookie = function(name) {

  var nameEQ = name + "=";

  var ca = document.cookie.split(';');

  for(var i=0;i < ca.length;i++) {

    var c = ca[i];

    while (c.charAt(0)==' ') c = c.substring(1,c.length);

    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

  }

  return null;

}



StyleSwitcher.prototype.setActiveStyle = function( title ){

	if(this.__SwitcherEnabled__){

		this.setActiveStyleSheet( title );

		this.__Active_Switcher_Button__ = title;

	}

}



StyleSwitcher.prototype.initStyleSwitcher = function(){

	var cookie = this.readCookie("style");

	var title = cookie ? cookie : this.getPreferredStyleSheet();

	this.setActiveStyle(title);

}



StyleSwitcher.prototype.onUnloadStyleSwitcher = function(){

	var title = this.getActiveStyleSheet();

	this.createCookie("style", title, 365);

}







/*---------------------------------------------------------------*/



/*---------------------------------------------------------------*/



function RollOverObject(  ){

	this.__Active_Button_ID__ = "";

	this.plImages = new Array();

	this.plOnImages = new Array();

}



RollOverObject.prototype.preloadImages = function(srcs){

	var ret = new Array();

	if(!document.images || !srcs) return;

	for(var i=0;i<srcs.length;i++){

		(new Image()).src = srcs[i];

		ret.push(srcs[i]);

	}

}



RollOverObject.prototype.swapImage = function(id, status ){

	if( this.__Active_Button_ID__ == id && status =="off" ) return;

	status = status + "src";

	var elm = (document.all)? document.all[id] : document.getElementById(id);

	if( elm[status] ) elm.src = elm[status];



}







RollOverObject.prototype.init = function( button_ids, defaultID ){

	if(!document.getElementById && document.all) return;

	if(!document.images) return;



	var pli = new Array();

	var ploi = new Array();



	for( var i=0; i<button_ids.length; i++ ){

		var node = document.getElementById(button_ids[i]);

		var b = new Object();

		b.src = node.src

		b.filetype = b.src.substring( b.src.lastIndexOf('.') );

		b.basename = b.src.substring( 0, b.src.length - b.filetype.length );

		b.onsrc = b.basename + "on" + b.filetype;



		node.offsrc = b.src;

		node.onsrc = b.onsrc;



		pli.push(node.src);

		ploi.push(node.onsrc);

	}



	this.preloadImages(pli);

	this.preloadImages(ploi);

	if( defaultID ){

		this.__Active_Button_ID__ = defaultID;

		this.swapImage(this.__Active_Button_ID__, "on");

	}

}







/*---------------------------------------------------------------*/



var switchButtons = new Array("fontsmall", "fontmedium", "fontlarge");



var mes = new MESCommon();

mes.__StyleChangeStep__ = 3;



var switcher = new StyleSwitcher();



if( !mes.setStyleSheetForSS() ){

	switcher.__SwitcherEnabled__ = false;

	mes.setStyleSheet( "win_ie.css" );

}

else{

	switcher.__SwitcherEnabled__ = true;

	var cookie = switcher.readCookie("style");

	var title = cookie ? cookie : switcher.getPreferredStyleSheet();

	switcher.setActiveStyle(title);

}



function changeStyle(id){

	roo.__Active_Button_ID__ = id;

	for( var i=0; i<switchButtons.length; i++ ){

		roo.swapImage( switchButtons[i], "off" );

	}

	switcher.setActiveStyle(id);

	roo.swapImage(id, "on");

}





/*---------------------------------------------------------------*/





var instanceStr = "roo";

var roo = new RollOverObject();



function OnLoad(){

	switcher.initStyleSwitcher();

	roo.init(switchButtons, switcher.getActiveStyleSheet());

}



window.onunload = function(){

	if(switcher.__SwitcherEnabled__){

		switcher.onUnloadStyleSwitcher();

	}

}