﻿function gfx_setcookie(name,value,hours) {
    if (hours) {
        var date = new Date();
        date.setTime(date.getTime()+(hours*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function gfx_getcookie(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 gfx_delcookie(name) {
    createCookie(name,"",-1);
}

function gfx_switch(name) {
	var iswitch = gfx_getcookie(name);
	if (iswitch == 1) iswitch = 0;
	else iswitch = 1;
	
	gfx_setcookie(name,iswitch,1);
}

function gfx_viewhide(id)
{
	el = document.getElementById(id);
	var display = el.style.display ? true : false;
	if (display) gfx_view(id);
	else setTimeout("gfx_hide(id)",2000);
}

function gfx_view(id)
{
	document.getElementById(id).style.display = '';
}

function gfx_pause_hide(id,millisec) {
	setTimeout("gfx_hide('" + id + "')",millisec);
}

function gfx_hide(id)
{
	document.getElementById(id).style.display = 'none';
}

function gfx_fade(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.display == 'none') {
        gfx_opacity(id, 0, 100, millisec);
    } else {
        gfx_opacity(id, 100, 0, millisec);
    }
} 

function gfx_opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	var i = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("gfx_changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("gfx_changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function gfx_changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	if (opacity == 0) object.display = 'none';
	else object.display = 'block';
} 

var gfx_offsetfromcursorX=12 //Customize x offset of tooltip
var gfx_offsetfromcursorY=10 //Customize y offset of tooltip

var gfx_offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var gfx_offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="gfx_tooltip"></div>') //write out tooltip DIV
document.write('<img id="gfx_tooltip_pointer" src="/img/gfx_arrow.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var gfx_enabletip=false
if (ie||ns6)
var gfx_tipobj=document.all? document.all["gfx_tooltip"] : document.getElementById? document.getElementById("gfx_tooltip") : ""
var gfx_pointerobj=document.all? document.all["gfx_tooltip_pointer"] : document.getElementById? document.getElementById("gfx_tooltip_pointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function gfx_tooltip(thetext, thewidth, thecolor){
	if (ns6||ie){
		if (typeof thewidth!="undefined" && thewidth!=0) gfx_tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") gfx_tipobj.style.backgroundColor=thecolor;
		gfx_tipobj.innerHTML=thetext;
		gfx_enabletip=true;
		return false;
	} else return true;
}

function gfx_positiontip(e){
if (gfx_enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-gfx_offsetfromcursorX : winwidth-e.clientX-gfx_offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-gfx_offsetfromcursorY : winheight-e.clientY-gfx_offsetfromcursorY

var leftedge=(gfx_offsetfromcursorX<0)? gfx_offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<gfx_tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
gfx_tipobj.style.left=curX-gfx_tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
gfx_tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
gfx_tipobj.style.left=curX+gfx_offsetfromcursorX-gfx_offsetdivfrompointerX+"px"
gfx_pointerobj.style.left=curX+gfx_offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<gfx_tipobj.offsetHeight){
gfx_tipobj.style.top=curY-gfx_tipobj.offsetHeight-gfx_offsetfromcursorY+"px"
nondefaultpos=true
}
else{
gfx_tipobj.style.top=curY+gfx_offsetfromcursorY+gfx_offsetdivfrompointerY+"px"
gfx_pointerobj.style.top=curY+gfx_offsetfromcursorY+"px"
}
gfx_tipobj.style.visibility="visible"
if (!nondefaultpos)
gfx_pointerobj.style.visibility="visible"
else
gfx_pointerobj.style.visibility="hidden"
}
}

function gfx_hidetooltip(){
if (ns6||ie){
gfx_enabletip=false
gfx_tipobj.style.visibility="hidden"
gfx_pointerobj.style.visibility="hidden"
gfx_tipobj.style.left="-1000px"
gfx_tipobj.style.backgroundColor=''
gfx_tipobj.style.width=''
}
}

document.onmousemove=gfx_positiontip
