
//ROLLOVER RELATED
///////////////////////////
var over = new Array();
var out = new Array();
function addRollovers(idArr) {
	var imgs, a;

	if (!document.images) return;

	for (i = 0; i < idArr.length; i++) {
		imgs = getObj(idArr[i]);
		if (!imgs) continue;
		a = imgs.parentNode;
		if (a && a.tagName == 'A'){
			over[i] = new Image();
			out[i] = new Image();
			over[i].src = getRollSrc(imgs.src,"gif",1);
			out[i].src = imgs.src;
			imgs.setAttribute('ro_index',i);
			a.onmouseover = function() { this.childNodes[0].src = over[this.childNodes[0].getAttribute('ro_index')].src; }
			a.onfocus = function() { this.childNodes[0].src = over[this.childNodes[0].getAttribute('ro_index')].src; }
			a.onmouseout = function() { this.childNodes[0].src = out[this.childNodes[0].getAttribute('ro_index')].src; }
			a.onblur = function() { this.childNodes[0].src = out[this.childNodes[0].getAttribute('ro_index')].src; }
		}
	}
}
function getRollSrc(src, ext, hover) {
	return (hover) ? src.replace("a."+ext,"b."+ext) : src.replace("b."+ext,"a."+ext);
}


var wini; //Reference to a window
function PopWin(url, name, width, height) {
	h = (height) ? height : 500;
	w = (width) ? width : 600;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =  'height='+ h +',width='+ w +',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';
	wini = window.open(url,name,settings);
	if (wini) wini.focus();
	return ( !wini )
}// PopWin()


//****************************
//** FROM: somewhere. Seen these functions elsewhere too many times to properly credit
//***************************
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function addEvent(obj,evType,fn){
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,false);
		return true;
	}
	else if(obj.attachEvent){
		var r=obj.attachEvent("on"+evType,fn);
		return r;
	}
	else{
		eval("obj.on"+evType+ " = " + fn);
		return true;
	}

}


function getObj(name) {
  if (document.getElementById) {
  	this.obj = document.getElementById(name);
		if(this.obj) 
			this.style = document.getElementById(name).style;
  }
  else if (document.all) {
		this.obj = document.all[name];
		if(this.obj)
			this.style = document.all[name].style;
  }
  else if (document.layers) {
   	this.obj = document.layers[name];
		if(this.obj)
	   	this.style = document.layers[name];
  }
	return this.obj; //secondary functionality returns reference to obj
}

function ImgRotator (objId,speed)
{
	this.objId = objId; // VARIABLE SHOULD BE NAMED THIS AS WELL
	this.obj = getObj(objId);
	this.speed = speed;
	this.ImgSrc = new Object();
	this.ImgAlt = new Object();
	this.ImgLnk = new Object();
	this.curIndex =  0;
	this.count = 0;
	this.started = false;
	this.preloaded = false;
	//if (this.obj && this.obj.parentNode.tagName == 'A') { this.addImage(this.obj.src,this.obj.alt,this.obj.parentNode.href);	this.curIndex++; }
}

var IR = ImgRotator.prototype;

IR.addImage = function(source,alt,lnk) { this.ImgSrc[this.count] = source; this.ImgLnk[this.count] = lnk; this.ImgAlt[this.count++] = alt; }
IR.preloadImages = function() { for(i=0;i < this.count;i++) { var img= new Image(); img.src = this.ImgSrc[i]; } this.preloaded = true; }
IR.beginSlideShow = function() { if (!this.obj) return; this.obj.onload = function() { this.started = true; setTimeout("eval("+this.id+").showImage()",eval(this.id).speed); } }
IR.showImage = function () { 
	if (this.obj.parentNode){
		var a = this.obj.parentNode;
		a.style.backgroundImage = 'url('+this.obj.src+')';
		if ( a.tagName == 'A') a.href=this.ImgLnk[this.curIndex];
	}
	this.obj.title = this.ImgAlt[this.curIndex];
	this.obj.alt = this.ImgAlt[this.curIndex];
	this.obj.src = this.ImgSrc[this.curIndex];
	this.curIndex++; this.curIndex %= this.count;
	
	fadeIn(this.objId,0);
	if (!this.preloaded) { // fetch the next image when preloading has
		imgy = new Image();
		imgy.src = this.ImgSrc[this.curIndex];
	}
}

$(document).ready
(
    function ()
    {
        var sizer = $('#tb_fontsize').FontSizer('content', 'fsUp', 'fsDown', 'fsNormal');
    }
);

var Cookies = {
    add: function (name, value, days) {
        var expires = '';
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = '; expires=' + date.toGMTString(); ;
        }
        document.cookie = name + "=" + escape(value) + expires + "; path=/";
    },
    remove: function (name) {
        this.add(name, '', -1);
    },
    get: function (name) {
        var results = document.cookie.match(name + '=([^;]*?)(;|$)');
        if (results)
            return (unescape(results[1]));
        else
            return null;
    }
};

(function ($) {
    jQuery.fn.FontSizer = function (type, upid, downid, resetid) {
        $.extend(this, {
            theconstructor: function (type, upid, downid, resetid) {
                this.type = type;
                this.baseSize = 14;
                this.minSize = 9;
                this.maxSize = 20;
                this.stepSize = 2;
                this.cookieName = type + 'FontSize';
                var x = Cookies.get(this.cookieName);
                this.currentSize = x ? parseInt(x) : this.baseSize;
                if (this.currentSize != this.baseSize) {
                    this.update();
                }
                var sizer = this;
                $('#' + upid).click(function (e) {
                    sizer.increase(e, this);
                });
                $('#' + downid).click(function (e) {
                    sizer.decrease(e, this);
                });
                $('#' + resetid).click(function (e) {
                    sizer.reset(e, this);
                });
                return this;
            },
            reset: function (e) {
                e.preventDefault();
                Cookies.remove(this.cookieName);
                this.currentSize = this.baseSize;
                this.update();
            },
            update: function () {
                Cookies.add(this.cookieName, this.currentSize, 7);
                cont = this.type;
                $('#' + cont).css('font-size', (this.currentSize / this.baseSize) + 'em');
            },
            increase: function (e) {
                e.preventDefault();
                this.currentSize = Math.min(this.currentSize + this.stepSize, this.maxSize);
                this.update();
            },
            decrease: function (e) {
                e.preventDefault();
                this.currentSize = Math.max(this.currentSize - this.stepSize, this.minSize);
                this.update();
            }
        });
        this.theconstructor(type, upid, downid, resetid);
        return this;
    };
})(jQuery);


