// get cookie style
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);




// tooltips
		window.addEvent('domready', function(){
			/* Tips 1 */
			var Tips1 = new Tips($$('.Tips1'));

			/* Tips 2 */
			var Tips2 = new Tips($$('.Tips2'), {
				initialize:function(){
					this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
				},
				onShow: function(toolTip) {
					this.fx.start(1);
				},
				onHide: function(toolTip) {
					this.fx.start(0);
				}
			});

			/* Tips 3 */
			var Tips3 = new Tips($$('.Tips3'), {
				showDelay: 400,
				hideDelay: 400,
				fixed: true
			});

			/* Tips 4 */
			var Tips4 = new Tips($$('.Tips4'), {
				className: 'custom'
			});
		});


//this create the scroll for anchor links
window.addEvent("domready", function() {
     new SmoothScroll({duration: 1500, fps:60, transition: Fx.Transitions.backOut});
});



// Stylesheet
// font sizer changer
var prefsLoaded = false;
var defaultFontSize = 76;
var currentFontSize = defaultFontSize;
function revertStyles(){
 currentFontSize = defaultFontSize;
 changeFontSize(0);
}

  function toggleColors(){
 if(currentStyle == "White"){
 setColor("Black");
 }else{
 setColor("White");
 }
}
function changeFontSize(sizeDifference){
 currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);
 if(currentFontSize > 100){
  currentFontSize = 100;
 }else if(currentFontSize < 60){
  currentFontSize = 60;
 }
 setFontSize(currentFontSize);
};
function setFontSize(fontSize){
 var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
 document.body.style.fontSize = fontSize + '%';
 //alert (document.body.style.fontSize);
};
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 setActiveStyleSheet(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 dpionload(func) {
if(typeof window.addEventListener != 'undefined')
{window.addEventListener('load', func, false);}
else if(typeof document.addEventListener != 'undefined')
{document.addEventListener('load', func, false);}
else if(typeof window.attachEvent != 'undefined')
{window.attachEvent("onload", func);}
else{ if(typeof window.onload == 'function') {
var prevonload = onload; window.onload = function() {prevonload();func();};}
else { window.onload = func;}}}

dpionload(setUserOptions);
function setUserOptions(){
 if(!prefsLoaded){
  cookie = readCookie("fontSize");
  currentFontSize = cookie ? cookie : defaultFontSize;
  setFontSize(currentFontSize);
  prefsLoaded = true;

 }
 var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);

}
window.onunload = saveSettings;
function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);

}

//Navigation
sfHover = function() {
    var sfEls = document.getElementById("main").getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
dpionload(sfHover);

window.addEvent('domready', function() {
        new Rokmoomenu($E('ul.topnav'), {
            bgiframe: false,
            delay: 500,
            animate: {
                props: ['opacity', 'width', 'height'],
                opts: {
                    duration:400,
                    fps: 100,
                    transition: Fx.Transitions.Expo.easeOut
                }
            }
        });
    });

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (version < 7) && (document.body.filters))
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id=\'" + img.id + "\' " : ""
            var imgClass = (img.className) ? "class=\'" + img.className + "\' " : ""
            var imgTitle = (img.title) ? "title=\'" + img.title + "\' " : "title=\'" + img.alt + "\' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod=\'scale\');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }
}
//here we don't care about browser compatiblity, it's for IE anyways.
if(window.attachEvent) window.attachEvent("onload", correctPNG);
