﻿
var BrowserDetect = {
	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"
		}
	]

};
BrowserDetect.init();

function handleOut(elname) {
// hides all popups, parameter is the div name
// function called on onmouseout of hyperlink parameter

d = document.getElementById(elname) ;
d.style.left = "-650px";
}

function setLyr(obj1,lyr, whichobject)
{
    // control the blue popups
    /*
    parameters:
    obj1 - the element to reference location from, generally the hyperlink
    lyr - the DIV to position - the divs are positioned off the page to start, the html is at the top of each page for each div
    help - a flag for the help div
    
    requires the browser.js script for browser detection
    as well as findPosX and findPosY, which find the referenced object's position
     
     function is called on the on mouse over of the hyperlink element
    */
	obj = document.getElementById (obj1) ;
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	
	var x = document.getElementById(lyr);
	
	// get the width of the screen
	var winWidth = (typeof(window.innerWidth) != 'undefined') ? window.innerWidth + self.pageXOffset - 20 : document.documentElement.clientWidth + document.documentElement.scrollLeft;
	// get the top
	var winTop =  document.documentElement.scrollTop;
    
    // variables for final resting place
    var finY ;
    var finX ;
    // change final resting places based on whether working with the top popup or bottom (help) popup
	// adjust finY and finX for tooltip placement on rollover ***********************
    finY = (newY - 395) ;   
	finX = (newX - 100) ;
	// set the default x
	
	
	// Safari section
	if (BrowserDetect.browser == "Safari")
	{
	    //safari uses the below property for getting the distance to the top of the page
	   winTop = self.pageYOffset ;
	   finY = (newY - 510) ; 
	   
	}
	if (BrowserDetect.browser == "Firefox")
	{
		 finY = (newY - 510) ;  	
	}
	if (BrowserDetect.version == "8")
	{
		finY = (newY - 515) ;  	
	}
	   // alert(winWidth);
	    if (winWidth < 900) // flip to the other side
	    {
        finX = (newX -265);	
            
	    }
	    
	 
    
		
	//set final position
	 x.style.top =  finY + 'px';
	 x.style.left = finX + 'px';
	 
}
function findPosX(obj)
  { //recursively searches through dom to get x postion
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {//recursively searches through dom to get y postion
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
