// JavaScript Document

/*
 +-------------------------------------------------------------------+
 |                   J S - T O O L T I P   (v1.5)                    |
 |                                                                   |
 | Copyright Gerd Tentler               www.gerd-tentler.de/tools    |
 | Created: Feb. 15, 2005               Last modified: Mar. 28, 2006 |
 +-------------------------------------------------------------------+

Beaten to pieces for sparkytype.com - might not work as intended

*/

  var OP = (navigator.userAgent.indexOf('Opera') != -1) ? true : false;
  var IE = (navigator.userAgent.indexOf('MSIE') != -1 && !OP) ? true : false;
  var GK = (navigator.userAgent.indexOf('Gecko') != -1) ? true : false;
  var NN4 = document.layers;
  var DOM = document.getElementById;

  function TOOLTIP() {
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------
    this.width = 200;                     // width (pixels)
    this.bgColor = '#FFFFC0';             // background color
    this.textColor = '#A00000';           // text color
    this.borderColor = '#D00000';         // border color
    this.opacity = 80;                    // opacity (percent) - doesn't work with all browsers
    this.cursorxDistance = 7;              // xdistance from cursor (pixels)
	this.cursoryDistance = 17;              // xdistance from cursor (pixels)

    // don't change
    this.text = '';
    this.height = 0;
    this.obj = 0;
    this.sobj = 0;
    this.active = false;

// -------------------------------------------------------------------------------------------------------
// Functions
// -------------------------------------------------------------------------------------------------------
    this.create = function() {
      if(!this.sobj) this.init();

      var t = '<img src=\"\/images\/floater\/' + this.text + '.gif\" \/>';

      if(NN4) {
        this.sobj.document.write(t);
        this.sobj.document.close();
      }
      else {
        this.setOpacity();
        if(document.getElementById) document.getElementById('ToolTip').innerHTML = t;
        else document.all.ToolTip.innerHTML = t;
      }
//      if(DOM) this.height = this.obj.offsetHeight;
//      else if(IE) this.height = this.sobj.pixelHeight;
//      else if(NN4) this.height = this.obj.clip.bottom;

      this.show();
    }

    this.init = function() {
      if(DOM) {
        this.obj = document.getElementById('ToolTip');
        this.sobj = this.obj.style;
      }
      else if(IE) {
        this.obj = document.all.ToolTip;
        this.sobj = this.obj.style;
      }
      else if(NN4) {
        this.obj = document.ToolTip;
        this.sobj = this.obj;
      }
    }

    this.show = function() {
      var ext = (document.layers ? '' : 'px');
      var left = mouseX;
      var top = mouseY;

      if(left + this.width + this.cursorxDistance > winX) left -= this.width + this.cursorxDistance;
      else left += this.cursorxDistance;

      if(top + this.height + this.cursoryDistance - scrTop > winY) top -= this.height;
      else top += this.cursoryDistance;

      this.sobj.left = left + ext;
      this.sobj.top = top + ext;

      if(!this.active) {
        this.sobj.visibility = 'visible';
        this.active = true;
      }
    }

    this.hide = function() {
      if(this.sobj) this.sobj.visibility = 'hidden';
      this.active = false;
    }

    this.setOpacity = function() {
      this.sobj.filter = 'alpha(opacity=' + this.opacity + ')';
      this.sobj.mozOpacity = '.1';
      if(this.obj.filters) this.obj.filters.alpha.opacity = this.opacity;
      if(!document.all && this.sobj.setProperty) this.sobj.setProperty('-moz-opacity', this.opacity / 100, '');
    }
  }

//----------------------------------------------------------------------------------------------------
// Build layer, get mouse coordinates and window width, create tooltip-object
//----------------------------------------------------------------------------------------------------
  var tooltip = mouseX = mouseY = winX = winY = scrTop = 0;

  if(document.layers) {
    document.write('<layer id="ToolTip"></layer>');
    document.captureEvents(Event.MOUSEMOVE);
  }
  else document.write('<div id="ToolTip" style="position:absolute; z-index:69"></div>');
  document.onmousemove = getMouseXY;

  function getMouseXY(e) {
    if(document.body && document.body.scrollTop >= 0) scrTop = document.body.scrollTop;
    else if(window.pageYOffset >= 0) scrTop = window.pageYOffset;

    if(IE) {
      mouseX = event.clientX + document.body.scrollLeft;
      mouseY = event.clientY + document.body.scrollTop;
    }
    else {
      mouseX = e.pageX;
      mouseY = e.pageY;
    }

    if(mouseX < 0) mouseX = 0;
    if(mouseY < 0) mouseY = 0;

    if(GK || NN4) {
      winX = window.innerWidth - 25;
      winY = window.innerHeight;
    }
    else if(DOM) {
      winX = document.body.offsetWidth - 25;
      winY = document.body.offsetHeight;
    }
    else {
      winX = screen.width - 25;
      winY = screen.height;
    }
    if(tooltip && tooltip.active) tooltip.show();
  }

  function toolTip(text) {
    if(text) {
      tooltip = new TOOLTIP();
      tooltip.text = text;
      tooltip.create();
    }
    else if(tooltip) tooltip.hide();
  }



//  IMAGE SWAPPER

function loadImg(from,to){
    	document.getElementById(from).src = to;
}


//  RASMUS' AJAX STEEZ

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function updateCart() {
	var ref = document.getElementById('ref').value;
	var users = document.getElementById('users').value;
	var format = document.getElementById('format').value;
	//alert('REF: '+ref+'  USERS: '+users+'  FORMAT: '+format);
	http.open('get', '/cart_update_ajax.php?ref='+ref+'&users='+users+'&format='+format);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
			fadeup('nav_cart',224,237,195)
        }
    }
}

// YFT

function fadeup(elementId,red,green,blue) {
	
	if (red ==255 && green == 255 && blue==255) {
		document.getElementById(elementId).style.backgroundColor = "transparent";
		return true;
	}

	document.getElementById(elementId).style.backgroundColor = "rgb("+red+","+green+","+blue+")";

	red = red + Math.ceil((255 - red)/10);
	green = green + Math.ceil((255-green)/10);
	blue = blue + Math.ceil((255-blue)/10);

	setTimeout("fadeup('"+elementId+"',"+red+","+green+","+blue+")", 60);
}