// JavaScript Document

var browser = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
browser.init();


function $() {var a = new Array(); for (var i = 0; i < arguments.length; i++) {var b = arguments[i]; if (typeof b == 'string') b = document.getElementById(b); if (arguments.length == 1) return b; a.push(b);} return a;}
function getStyle(a, b) {c = ((a.currentStyle) ? a.currentStyle[b] : ((window.getComputedStyle) ? document.defaultView.getComputedStyle(a,null).getPropertyValue(b) : false)); return (c != 'auto' && c !== false) ? c : 0;}

var scroller = {
  config : function(){

// Edit your configuration for the area (default)
    this.setWidth = 677; // Width of the area
    this.setHeight = 75; // Height of the area
    this.direction = 0; // 0 = scroll Y axis (left or right), 1 = scroll X axis (up or down)
    this.move = 1; // 1 = scroll left/right or up/down, 0 = scroll right/left or down/up
    this.speed = 75; // pixels per second
    this.rolloverPause = true; // allow pause when cursor hovers element (true/false);
// End edit area

   },

   items : [

// Edit your items for the area
    // either as 'string' or as ['image', 'title/alt', 'width', 'height']
    [sitePath +'images/scroller/01.jpg', '01', '112', '75'],
    [sitePath +'images/scroller/02.jpg', '02', '112', '75'],
    [sitePath +'images/scroller/03.jpg', '03', '112', '75'],
    [sitePath +'images/scroller/04.jpg', '04', '112', '75'],
    [sitePath +'images/scroller/05.jpg', '05', '112', '75'],
    [sitePath +'images/scroller/06.jpg', '06', '112', '75'],
    [sitePath +'images/scroller/07.jpg', '07', '112', '75'],
    [sitePath +'images/scroller/08.jpg', '08', '112', '75'],
    [sitePath +'images/scroller/09.jpg', '09', '112', '75']
// End edit area

  ],

  preload : function() {
	  var a = [];
	  for (i=0; i<this.items.length; i++) {
		  a[i] = new Image();
		  if (typeof this.items[i] != 'string' && this.items[i].length > 0) a.src = this.items[i][0];
	  }
  },

  make : function(a, b, c, d, e, f, g) {
    if ($(a)) {
      if (this.items.length < 1) return (this.mp.innerHTML = 'There are no items available to scroll.');

	  this.preload();
      this.config(); // Get config

      // Overwrite config
      if (b && b > 0) this.setWidth = b;
      if (c && c > 0) this.setHeight = c;
      if (d && d >= 0) this.direction = d;
      if (e && e >= 0) this.move = e;
      if (f && f > 0) this.speed = f;
      if (g && g === true || g === false) this.rolloverPause = g;


      this.mp = $(a); // save a few milliseconds
      this.mp.className = 'mp_container';

      this.mpc = document.createElement('div');
      this.mpc.className = 'mp_items';
      this.mpc.setAttribute('id', 'mpc0');

	  var mpdiw = 0;
      for (i=0; i<this.items.length; i++) {
        if (typeof this.items[i] == 'string') { // String
          var mpdi = document.createElement('span');
          if (this.direction > 0) mpdi.setAttribute('style', 'width: '+ this.setWidth +'px'); // Add a width if up/down
          mpdi.innerHTML = this.items[i];

        } else { // Image
          var mpdi = document.createElement('img');
          mpdi.setAttribute('src', this.items[i][0]);
          mpdi.setAttribute('title', this.items[i][1]);
          mpdi.setAttribute('alt', this.items[i][1]);
          mpdi.setAttribute('width', this.items[i][2]);
          mpdi.setAttribute('height', this.items[i][3]);
        }

        mpdi.className = 'mp_item';
        this.mpc.appendChild(mpdi);
		
        if (this.direction > 0) {
          var mpdi = document.createElement('br');
          this.mpc.appendChild(mpdi);
        }
      }

      this.mp.innerHTML = ''; // clean out
      this.mp.appendChild(this.mpc); // Add items


	  // ie bug with widths and absolutes. must calculate offset of each to get linear size, not broken size
      this.cn_w = 0;
      this.cn_h = 0;
	  for (i=0; i<this.mpc.childNodes.length; i++) {
		  // will increment dimension if scroll direction, otherwise get largest dimension
		  this.cn_w = ((this.direction < 1) ? (this.cn_w + this.mpc.childNodes[i].offsetWidth) : ((this.cn_w < this.mpc.childNodes[i].offsetWidth) ? this.mpc.childNodes[i].offsetWidth : this.cn_w));
		  this.cn_h = ((this.direction > 0) ? (this.cn_h + this.mpc.childNodes[i].offsetHeight) : ((this.cn_h < this.mpc.childNodes[i].offsetHeight) ? this.mpc.childNodes[i].offsetHeight : this.cn_h));
	  }

	  if (this.direction > 0) {
		  this.mpc.style.height = this.cn_h +'px';
	  } else {
		  this.mpc.style.width = this.cn_w +'px';
	  }

      this.cns = Math.ceil((this.direction > 0) ? (this.setHeight/this.cn_h) : (this.setWidth/this.cn_w));
      var mpc_i = 0;

      for (i=1; i<=this.cns; i++) {
        mpc_i += ((this.direction > 0) ? this.cn_h : this.cn_w);
        var mpc2 = this.mpc.cloneNode(true);
        mpc2.setAttribute('id', 'mpc'+i);
		if (this.direction > 0) {
        	mpc2.style.height = this.cn_h +'px';
			mpc2.style.top = mpc_i +'px';
		} else {
			mpc2.style.width = this.cn_w +'px';
			mpc2.style.left = mpc_i +'px';
		}
        mpc2.setAttribute('style', ((this.direction > 0) ? 'height: '+ this.cn_h +'px; top: '+ mpc_i +'px' : 'width: '+ this.cn_w +'px; left: '+ mpc_i +'px;'));
        this.mp.appendChild(mpc2);
      }

      if (this.setWidth > 0) this.mp.style.width = this.setWidth +'px';
      if (this.setHeight > 0) this.mp.style.height = this.setHeight +'px';

      this.adjust = (this.cns*((this.direction > 0) ? this.cn_h : this.cn_w));
      this.dirOffset = (this.move >= 1) ? 1 : -1;

      this.to_intrv = (this.speed > 0 && this.speed < 1000) ? Math.round(this.speed/40) : .5; // Microseconds per pixel. (default 10px/second.)
      this.to = setInterval('scroller.scroll()', 50);

      if (this.rolloverPause === true) { // Allow rollover pausing (to see/read items)
        this.mp.onmouseout = function() {scroller.to = setInterval('scroller.scroll()', 50);};
        this.mp.onmouseover = function() {clearInterval(scroller.to);};
      }
    }
  },

  // Scrolling controler
  scroll : function() {
    for (i=0; i<=this.cns; i++) {
      if ($('mpc'+i)) {
        var mpc = $('mpc'+i);

        if (this.direction > 0) { // Up/Down scrolling
          mpc.style.top = (parseInt(getStyle(mpc, 'top')) + (this.dirOffset * this.to_intrv)) +'px';
          if ((this.move >= 1 && parseInt(getStyle(mpc, 'top')) > this.setHeight) || (this.move < 1 && parseInt(getStyle(mpc, 'top')) < (-1*mpc.offsetHeight))) {
            mpc.style.top = parseInt(getStyle(mpc, 'top')) - (this.dirOffset * this.adjust) - (this.dirOffset * mpc.offsetHeight) +'px';
          }

        } else { // Left/Right scrolling
          mpc.style.left = (parseInt(getStyle(mpc, 'left')) + (this.dirOffset * this.to_intrv)) +'px';
          if ((this.move >= 1 && parseInt(getStyle(mpc, 'left')) > this.setWidth) || (this.move < 1 && parseInt(getStyle(mpc, 'left')) < (-1*mpc.offsetWidth))) {
            mpc.style.left = parseInt(getStyle(mpc, 'left')) - (this.dirOffset * this.adjust) - (this.dirOffset * mpc.offsetWidth) +'px';
          }
        }
      }
    }
  }
};


function imgSwap(imgid,imgsrc) {
	var theimg = document.getElementById(imgid);
	theimg.src = '/assets/templates/toolcare/images/' + imgsrc;
}


	// Detect if the browser is IE or not.
	// If it is not IE, we assume that the browser is NS.
	var IE = document.all?true:false
	
	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	
	// Set-up to use getMouseXY function onMouseMove
	document.onmousemove = getMouseXY;
	
	// Temporary variables to hold mouse x-y pos.s
	var tempX = 0
	var tempY = 0
		
	function showFloat(imgurl, imgoffset) {
		var imgoffset = (imgoffset == null) ? 0 : imgoffset;
		var imgpath = 'http://www.toolcare-us.com/assets/images/' + imgurl;
		var theDiv = document.getElementById('floaterDiv');
		theDiv.innerHTML = '<img src="' + imgpath + '" style="border: solid 1px #000;" id="floatImg" />';

		theImg = new Image();
		theImg.src = imgpath;
		imgH = theImg.height;

		theDiv.style.top = (tempY - (parseInt(imgH/2)) - 15 + parseInt(imgoffset)) + "px";
		theDiv.style.left = (tempX + 5) + "px";

		theDiv.style.display = "block";
		theDiv.style.visibility = "visible";
		imgoffset = 0;
	}
	
	function clearFloat() {
		var theDiv = document.getElementById('floaterDiv');
		theDiv.innerHTML = '';
		theDiv.style.display = "none";
		theDiv.style.visibility = "hidden";
	}

	// Main function to retrieve mouse x-y pos.s
	
	function getMouseXY(e) {
	  if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.documentElement.scrollLeft
		tempY = event.clientY + document.documentElement.scrollTop
	  } else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	  }  
	  // catch possible negative values in NS4
	  if (tempX < 0){tempX = 0}
	  if (tempY < 0){tempY = 0}  
	  // show the position values in the form named Show
	  // in the text fields named MouseX and MouseY
	  return true
	}