document.write('<style type="text/css">.JS {display: block;}</style>');

// style switcher
function setStyle(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;
    }
  }
}
function getActiveStyleSheet() {
  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;
}
function getPreferredStyleSheet() {
  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;
}
function createCookie(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=/";
}
function readCookie(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;
}
function initSetLayout(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setStyle(title);
}
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setStyle(title);
// style switcher


// text size

// read cookie
function get_cookie ( cookie_name ) {
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results ) return ( unescape ( results[1] ) );
  else return null;
}
// check cookie
function checkCookie() {
	Cookie = get_cookie('contenttext');
	if (Cookie != null) { TxtSize = get_cookie('contenttext'); }
	else { TxtSize = "1";}
}

function initTextSize(){
	checkCookie();
	txtFX = new fx.RememberText('content', {duration: 300});
	
	if (TxtSize == '0.8') {
		document.getElementById('TxtSm').className="Off";
	}	
	else if (TxtSize == '1.4') {
		document.getElementById('TxtLg').className="Off";
	}
}

function textSize(size) {
var TxtSm = document.getElementById('TxtSm');
var TxtLg = document.getElementById('TxtLg');
	if (size == 'larger') {	
		if (TxtSize == '0.8') {
			txtFX.custom(0.8,1);
			TxtSize = "1";
			TxtSm.className="a";
		}
		else if (TxtSize == '1') {
			txtFX.custom(1,1.2);
			TxtSize = "1.2";
		}
		else if (TxtSize == '1.2') {
			txtFX.custom(1.2, 1.4);
			TxtSize = "1.4";
			TxtLg.className="Off";
		} 
	}

	else if (size == 'smaller') {

		if (TxtSize == '1.4') {
			txtFX.custom(1.4,1.2);
			TxtSize = "1.2";	
			TxtLg.className="a";
		}
		else if (TxtSize == '1.2') { 
			txtFX.custom(1.2, 1);
			TxtSize = "1";
		}
		else if (TxtSize == '1') { 
			txtFX.custom(1, 0.8);
			TxtSize = "0.8";
			TxtSm.className="Off";
		}
	}
}
// text size


// anchor scroll function
var ScrollLinks = {
    currentHash: false,
    start: function(){
        this.scroll = new fx.Scroll({duration: 800, onComplete: function(){ScrollLinks.end();}});
        this.allinks = document.getElementsByTagName('a');
        for (i=0; i<this.allinks.length; i++){
            var lnk = this.allinks[i];
            if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
                lnk.onclick = function(){
                    ScrollLinks.scroll.clearTimer();
                    this.initialHref = this.href;
                    this.initialHash = this.hash;
                    this.href = "javascript:void(0)";
                    setTimeout(function(){this.href = this.initialHref;}.bind(this), 200);
                    ScrollLinks.click(this);
                }
            }
        }
    },

    click: function(link){
        this.currentHash = link.initialHash.substr(1);
        if (this.currentHash) {
            for (j=0; j<this.allinks.length; j++){
                if (this.allinks[j].id == this.currentHash){
                    if (!window.opera) this.scroll.scrollTo(this.allinks[j]);
                    else this.scroll.scrollTo(this.allinks[j].parentNode);
                    break;
                }
            }
        }
    },

    end: function(){
        window.location.href = "#"+this.currentHash;
        this.currentHash = false;
    }
}
// anchor scroll function

// top button 
function initTopBtn(){setInterval("TopBtn()",1)}

function TopBtn(){
	var position = window.pageYOffset;
	var Btn = document.getElementById('BackToTop')
		if (position > 160){
			Btn.className="on";
		}
		if (position < 160){
			Btn.className="off";
		}
	return true;
}
// top button 



// site color
function Color(a) { 
	var Bdy = document.body;
		Bdy.className=a;
		createCookie("Color", a, 365);	
	}
	
	
