var lat = 6400; 
var lon = 6400;
var zoom = 2;
var maxResolution = 1;
var map, icon, searchMarkers, disabledLayer, infoLayer, phoneLayer, resetTimeout;
var marker = null;
var results;
var resultsSlideSpeed = 3;
var listLoaded = false;
var loadingItems = 0;
var maskImage, mask, maskTimeout;

document.write("<style type='text/css'> #browserNotSupported{display: none;} #entireMapContainer { display: block; } #javascriptWorking {display: block; }</style>");

/* Initialises the map and runs any queries if need be */
function init() {
  if (checkBrowser()) {
    loadMap();
  } else {
    showWarning();
  }
}

function loadMap(){
    loading();
    
	  // these should be object methods or something
    map = new OpenLayers.Map( $('map'), 
      { resolutions: [25, 16.67, 10, 5],
        //maxExtent: new OpenLayers.Bounds(0,0,200,200),
        //numZoomLevels: 5,
        units: "m", 
        maxExtent: new OpenLayers.Bounds(0, 0, 12800, 12800 ), 
        controls: [new OpenLayers.Control.MouseDefaults(), 
                   new OpenLayers.Control.PanZoomBar()]
      } );
    var url = location.href.slice(0, location.href.lastIndexOf("/"));

    var mymap = new OpenLayers.Layer.TMS( "UoW", 
            url + "/data/", {layername: 'uow', type:'png',   tileOrigin: new OpenLayers.LonLat(0, 0)} );
    map.addLayer(mymap);
    
    /* Start marker layers here */
    disabledLayer = new OpenLayers.Layer.Text( "DisabledParking", {location: url + "/data/disabled.txt"});
    disabledLayer.setVisibility(false);
    map.addLayer(disabledLayer);
    
    infoLayer = new OpenLayers.Layer.Text( "InformationPoints", {location: url + "/data/infopoints.txt"})
    infoLayer.setVisibility(false);
    map.addLayer(infoLayer);
    
    phoneLayer = new OpenLayers.Layer.Text( "EmergencyPhones", {location: url + "/data/emergency.txt"})
    phoneLayer.setVisibility(false);
    map.addLayer(phoneLayer);
    
    /* End marker layers here */
    
    searchMarkers = new OpenLayers.Layer.Markers("SearchResult");
    map.addLayer(searchMarkers);
    var size = new OpenLayers.Size(37,34);
    icon = new OpenLayers.Icon("marker.png", size, new OpenLayers.Pixel(-10, -34),
        function(size) { return new OpenLayers.Pixel(-10, -34); }
      );
      
   maskImage = new OpenLayers.Icon("mask.png", new OpenLayers.Size(550,350), new OpenLayers.Pixel(-275, -175),
        function(size) { return new OpenLayers.Pixel(-275, -175); }
      );
      
    map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
    map.events.register("mousedown", this, removeMask);
    resultsBox = $('results');
    if (location.search != "") {
      var hashQuery;

      if (location.search.indexOf("=") >= 0) {
        hashQuery = location.search.slice(location.search.indexOf("=")+1);
      } else {
        hashQuery = location.search.slice(1);
      }
      
      if (hashQuery != "showpoints") {
        $('buildingQuery').value = hashQuery;
        doSearch();
      } else {
        map.addControl(new OpenLayers.Control.MousePosition({element: $('showing')}));
        
        if (resultsBox.style.display != 'block') {
          resultsBox.style.height = '0px';
          resultsBox.style.display = 'block';
          resultInterval = window.setInterval("slideResults()", 5);
        }
      }
      
    }
    
    /* Preload the grab cursor */
    if(!(/Gecko/.test(navigator.userAgent))) {
      var cur = new Image();
      cur.src = "./img/closedhand.cur";
    }
       
    notLoading();
}

function checkBrowser() {
  var version = parseInt(BrowserDetect.version);
  var floatVersion = parseFloat(BrowserDetect.version);

  switch (BrowserDetect.browser) {
    case "Safari":
      if (version > 2) {
        return true;
      } else {
        return false;
      }
      break;
    case "Firefox":
      if (floatVersion >= 1.0) {
        return true;
      } else {
        return false;
      }
      break;
    case "Opera":
      if (floatVersion >= 7.5) {
        return true;
      } else {
        return false;
      }
      break;
    case "Explorer":
      if (floatVersion >= 5.5) {
        return true;
      } else {
        return false;
      }
      break;
    case "Mozilla":
      if (floatVersion >= 1.4) {
        return true;
      } else {
        return false;
      }
      break;
    case "Netscape":
      if (floatVersion >= 7.0) {
        return true;
      } else {
        return false;
      }
      break;
    case "Camino":
      return true;
      break;
    case "Chrome":
      return true;
      break;
    default:
      return false;

  }
  
  return true;
}

function showWarning() {
  $("browserNotSupported").style.display = 'block';
  $("entireMapContainer").style.display = 'none';
}

/* Skips the old browser warning */
function skipWarning() {
  $("browserNotSupported").style.display = 'none';
  $("entireMapContainer").style.display = 'block';
  loadMap();
}

/* Switches the find box between the two options */
function switchFindType(obj) {

  $('buildingSearch').style.display = 'none';
  $('buildingSelect').style.display = 'none';
  $('buildingSearchTie').src = './img/switch-un.gif';
  $('buildingSelectTie').src = './img/switch-un.gif';
  $(obj).style.display = 'block';
  $(obj+'Tie').src = './img/switch-ed.gif';

  if (obj == 'buildingSelect' && !listLoaded) {
    listBuildingOptions();
  }
}



var resultInterval;
var resultsBox;
/* Begins the search query */
function doSearch() {
  loading();
  var term = $('buildingQuery').value;  
  OpenLayers.loadURL("query.php", "q="+term, this, doSearchComplete, doRequestFailed);

  
}

/* Once the AJAX request is through flick to the result and show the
   extra results if necessary. */
function doSearchComplete(request) {
try {
    if (request.responseText.indexOf("nothing") >= 0) {
      report("NOT_FOUND");
    } else {
      var doc = request.responseXML;
      
      var root = doc.firstChild;
      results = root;

      mark(0);

      provideRest(root);
     
      resultsBox = $('results');
      if (resultsBox.style.display != 'block') {
        resultsBox.style.height = '0px';
        resultsBox.style.display = 'block';
        resultInterval = window.setInterval("slideResults()", 5);
      }
    }
    notLoading();
} catch(e) {
  report("AJAX_BAD");

}
}

/* Outputs all the results if there were some. If there were, it will expand
   the results dialog automatically. */
function provideRest(root) {

  var num = root.childNodes.length;
  var extras = $('extraResults');

  if (num < 2) {
    $('showing').className = 'noResultsAvailable';
    if ($('extraResults').style.display == 'block') {
      showResults();
    }    
    $('morelink').innerHTML = "";

  } else {

    $('showing').className = 'moreResultsAvailable';
    $('matchResults').innerHTML = "There are " + num + " matching buildings";
    if ($('morelink').innerHTML == "") {
      $('morelink').innerHTML = "more results...";
    }
    if ($('extraResults').style.display != 'block') {
      showResults();
    }  
  }
  var output = "";
  for(i = 0; i < num; i++) {
    output += "<a href='javascript:mark(" + i + ");'>" + getNodeText(root.childNodes[i].childNodes[0]) + "</a><br>";
  }


  $('resultOutput').innerHTML = output;

}

/* Shows the expanded results box */
function showResults() {
  resultsSlideSpeed = 10;
  resultsobj = $('extraResults');
  linkobj = $('morelink');
  showingobj = $('showing');
  if (resultsobj.style.display == 'none') {
    if (showingobj.className == 'moreResultsAvailable') {
      $('results').style.height = $('results').clientHeight + "px";
      
      resultsobj.style.display = 'block';
      showingobj.style.display = 'none';
      linkobj.innerHTML = 'hide results';
      resultInterval = window.setInterval("slideResults()", 5);
    } 
  } else {
    resultsobj.style.display = 'none';
    showingobj.style.display = 'block';
    linkobj.innerHTML = 'more results...';
  }
}

/* Pretty effect for when the results box is shown */
function slideResults() {
  curHeight = parseInt(resultsBox.style.height);
  curHeight +=resultsSlideSpeed;
  if (curHeight < resultsBox.scrollHeight) {
    resultsBox.style.height = curHeight + "px";
  } else {
    resultsBox.style.height = "auto";
    resultsSlideSpeed = 10;
    clearInterval(resultInterval);
  }
}

/* Cross-platform function to get the node text */
function getNodeText(obj) {
  if (obj.text) {
    return obj.text;
  } else if (obj.firstChild) {
    return obj.firstChild.nodeValue;
  } else {
    return obj.textContent;
  }
}

/* Calls to the AJAX to make a list of options. Called only once per page view. */
function listBuildingOptions() {
  loading();
  OpenLayers.loadURL("query.php", "list", this, doListComplete, doRequestFailed);
}

/* Once the AJAX request is completed put the <options> into the <div> */
function doListComplete(request) {
  var doc = request.responseText;
  $('buildingSelect').innerHTML =
    "<select name='buildingOption' id='buildingList' onChange='javascript:doListChanged();'>" 
    + "<option value=''>-</option>"
    + doc + "</select>";
  listLoaded = true;
  notLoading();
}

/* If the AJAX request failed, say so. */
function doRequestFailed(request) {
  report("AJAX_FAIL");
}

var oldMsg = "";
var moreShowing = "none";
/* Report any errors */
function report(strProb) {

  var messageBar = $('showing');
  oldMsg = messageBar.innerHTML;

  moreShowing = $('morelink').innerHTML;
  
  
  if ($('extraResults').style.display == 'block') {
    showResults();
  }
  $('showing').className = 'noResultsAvailable';
  $('morelink').innerHTML = "";
  var newMessage = "";
  
  if (strProb == "NOT_FOUND") {
    newMessage = "No buildings matched the search term.<br/> Please check your input, or choose a building from the <a style=\"cursor: pointer\"  onclick=\"javascript:switchFindType('buildingSelect')\">'Select from a List'</a> dropdown (above).";
    fade("#ffa", 10, 10, "results");
  } else if (strProb == "AJAX_FAIL" || strProb == "AJAX_BAD") {
  
    newMessage = "We are experiencing technical difficulties. Please try again in a few moments.";
    fade("#fcc", 10, 10, "results");
  }
  
  notLoading();
  messageBar.innerHTML = newMessage;
  resultsBox = $('results');
  if (resultsBox.style.display != 'block') {
    resultsBox.style.height = '0px';
    resultsBox.style.display = 'block';
    resultInterval = window.setInterval("slideResults()", 5);
  }
  setTimeout("resetMessageBG()", 3000);
  resetTimeout = setTimeout("resetMessage()", 5000); 

}

/* Resets the background of the results after the report() has been done */
function resetMessageBG() {
  fade("#eee", 50, 50, "results");
  
}

/* Resets the message of the results to what it was before report() was called */
function resetMessage() {

  if ((oldMsg.length > 0) && (oldMsg != $('showing').innerHTML)) {
    $('showing').innerHTML = oldMsg;
    if (moreShowing != '') {
      $('morelink').innerHTML = "more results...";
      $('showing').className = 'moreResultsAvailable';
    }
  }
}

/* Switch to the new co-ords, by filling in the search and sending it. */
function doListChanged() {
  var query =
    $('buildingList').options[$('buildingList').selectedIndex].value;
  $('buildingQuery').value = query;
  doSearch();
}

/* Taking the node ID, it will switch the marker to the new location. */
function mark(resultNum) {
  
  clearTimeout(resetTimeout);
  
  var thisNode = results.childNodes[resultNum];

  var lon = getNodeText(thisNode.childNodes[1]);
  var lat = getNodeText(thisNode.childNodes[2]);
  var pos = new OpenLayers.LonLat(lon, lat);
  map.setCenter(pos);
  if (marker != null) {
    searchMarkers.removeMarker(marker);
  }
  
  maskImage.setOpacity(1.00);
  marker = new OpenLayers.Marker(pos, icon);
  
  mask = new OpenLayers.Marker(pos, maskImage);
  searchMarkers.addMarker(marker);
  searchMarkers.addMarker(mask);
  
  maskTimer = setTimeout("fadeMask(1.00)", 1500);
  
  $('showing').innerHTML = getNodeText(thisNode.childNodes[0]);
  var loc = location.href.slice(0, location.href.lastIndexOf("?"));
  
  loc += "?" + getNodeText(thisNode.childNodes[3]);

  $('locationLink').href= loc;
  document.title = "Campus Map - " + getNodeText(thisNode.childNodes[0]);
  
}

function fadeMask(opacity) {
  opacity = opacity - 0.05;
  maskImage.setOpacity(opacity);
  if (opacity >= 0.00) {
    maskTimer = setTimeout("fadeMask(" + opacity + ")", 50);
  } else {
    searchMarkers.removeMarker(mask);
  }
}

function removeMask() {
  if (mask != null) {
    clearTimeout(maskTimer);
    searchMarkers.removeMarker(mask);
  }
}

/* Show or hide a marker layer */
function turnOn(layername, chkobj) {
    if (chkobj.checked) {
      layername.setVisibility(true);
    } else {
      layername.setVisibility(false);
    }
}

/* Show the loading indicator */
function loading() {
  loadingItems++;
  $('loading').style.display = 'block';
}

/* Hide the loading indicator only if nothing is loading */
function notLoading() {
  loadingItems--;
  if (loadingItems <= 0) {
    $('loading').style.display = 'none';
    loadingItems = 0; // so then we never have negative number
  }
}

/* Expands the help content box. If already expanded, collapses. */
function showHelp() {
  var helpBox = $('help');
  if (helpBox.style.display == 'block') {
    helpBox.style.display = 'none';
  } else {
    helpBox.style.display = 'block';
  }
}

/* Expands the help content box if it isn't already, and then expands the legend.
   If already expanded, it collapses help */
function showLegend() {
  var helpBox = $('help');
  
  if (helpBox.style.display != 'block' || $('legend').style.display != 'block') {
    $('legend').style.display = 'block';
    $('legendHead').style.backgroundImage = "url('./img/switch-ed.gif')";
    helpBox.style.display = 'block';
  } else {
    $('legend').style.display = 'none';
    $('legendHead').style.backgroundImage = "url('./img/switch-un.gif')";
    helpBox.style.display = 'none';
  }

}

/* If the user clicks on the 'Link to Building', show the help on what to use
   the link for. If it is already shown, hide the Help */
function alertLinkUsage() {
  var helpBox = $('help');
  
  if (helpBox.style.display != 'block' || $('linkingHelp').style.display != 'block') {
    $('linkingHelp').style.display = 'block';
    $('linkingHead').style.backgroundImage = "url('./img/switch-ed.gif')";
    helpBox.style.display = 'block';
  } else {
    $('linkingHelp').style.display = 'none';
    $('linkingHead').style.backgroundImage = "url('./img/switch-un.gif')";
    helpBox.style.display = 'none';
  }
}

/* For help, expand a section and switch the twist-tie */
function expandSection(objID,heading) {
  if ($(objID).style.display == 'block') {
    $(objID).style.display = 'none';
    $(heading).style.backgroundImage = "url('./img/switch-un.gif')";
  } else {
    $(objID).style.display = 'block';
    $(heading).style.backgroundImage = "url('./img/switch-ed.gif')";
    
  }
}

/**
 * Author: Lachlan Hunt
 * Date: 2005-11-24
 * Version: 1.0
 *
 * Licence: Public Domain
 * Attribution is considered ethical, but not required.
 *
 * Usage:
 *   Color(255, 255, 255);
 *   Color(255, 255, 255, 1.0);
 *   Color("#FFF");
 *   Color("#FFFFFF");
 *   Color("rgb(255, 255, 255)");
 *   Color("rgba(255, 255, 255, 1.0)");
 *   Color("white"); - CSS 2.1 Color keywords only
 */
var Color = function() {

	var keyword = new Array(); // CSS 2.1 Colour Keywords
	keyword["maroon"]  = "#800000";
	keyword["red"]     = "#ff0000";
	keyword["orange"]  = "#ffA500";
	keyword["yellow"]  = "#ffff00";
	keyword["olive"]   = "#808000";
	keyword["purple"]  = "#800080";
	keyword["fuchsia"] = "#ff00ff";
	keyword["white"]   = "#ffffff";
	keyword["lime"]    = "#00ff00";
	keyword["green"]   = "#008000";
	keyword["navy"]    = "#000080";
	keyword["blue"]    = "#0000ff";
	keyword["aqua"]    = "#00ffff";
	keyword["teal"]    = "#008080";
	keyword["black"]   = "#000000";
	keyword["silver"]  = "#c0c0c0";
	keyword["gray"]    = "#808080";

	var func = new Array(); // CSS Functional Notations and Hex Patterns
	func["rgb"]   = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\);?$/;
	func["rgb%"]  = /^rgb\(\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\);?$/;
	func["rgba"]  = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*((?:\d+(?:\.\d+)?)|(?:\.\d+))\s*\);?$/;
	func["rgba%"] = /^rgba\(\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*((?:\d+(?:\.\d+)?)|(?:\.\d+))\s*\);?$/;
	func["hex3"]  = /^#([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f]);?$/;
	func["hex6"]  = /^#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2});?$/;

	/*
	 * Clamp the value between the low value and the high value
	 */
	function clamp(value, low, high) {
		if (value < low) {
			value = low;
		}
		else if (value > high) {
			value = high;
		}
		return value;
	}

	function alphaBlend(forground, background, alpha) {
		return Math.round(background * (1.0 - alpha) + forground * (alpha));
	}

	/*
	 * Return the colour in hexadecimal notation: #RRGGBB. e.g. #FF9933
	 * @param bg - Optional parameter used for calculating the colour if an alpha value less than 1.0 has been specified.
	 *             If not specified, the alpha value will be ignored.
	 */
	function hex(bg) {
		if (bg) {
			var r = alphaBlend(this.red, bg.red, this.alpha);
			var g = alphaBlend(this.green, bg.green, this.alpha);
			var b = alphaBlend(this.blue, bg.blue, this.alpha);
		} else {
			r = this.red;
			g = this.green;
			b = this.blue;
		}
		
		var strHexR = r.toString(16).toUpperCase();
		var strHexG = g.toString(16).toUpperCase();
		var strHexB = b.toString(16).toUpperCase();
	
		if (strHexR.length < 2) strHexR = "0" + strHexR;
		if (strHexG.length < 2) strHexG = "0" + strHexG;
		if (strHexB.length < 2) strHexB = "0" + strHexB;
	
		return "#" + strHexR + strHexG + strHexB
	}

	/*
	 * Return the colour in CSS rgb() functional notation, using integers 0-255: rgb(255, 255 255);
	 * @param bg - Optional parameter used for calculating the colour if an alpha value less than 1.0 has been specified.
	 *             If not specified, the alpha value will be ignored.
	 */
	function rgb(bg) {
		if (bg) {
			var r = alphaBlend(this.red, bg.red, this.alpha);
			var g = alphaBlend(this.green, bg.green, this.alpha);
			var b = alphaBlend(this.blue, bg.blue, this.alpha);
		} else {
			r = this.red;
			g = this.green;
			b = this.blue;
		}
	
		return "rgb(" + r + ", " + g + ", " + b + ")";
	}

	/*
	 * Return the colour in CSS rgba() functional notation, using integers 0-255 for color components: rgb(255, 255 255, 1.0);
	 * @param bg - Optional parameter used for calculating the colour if an alpha value less than 1.0 has been specified.
	 *             If not specified, and there is an alpha value, black will be used as the background colour.
	 */
	function rgba() {
		return "rgba(" + this.red + ", " + this.green + ", " + this.blue + ", " + this.alpha + ")";
	}

	/*
	 * Blend this colour with the colour specified and return a pallet with all the steps in between.
	 * @param color - The colour to blend with
	 * @param steps - The number of steps to take to reach the color.
	 */
	function blend(color, steps) {
		var pallet = new Array();
		var r, g, b, i;

		var step = new Object();
		step.red   = (alphaBlend(color.red, this.red, color.alpha) - this.red) / steps;
		step.green = (alphaBlend(color.green, this.green, color.alpha) - this.green) / steps;
		step.blue  = (alphaBlend(color.blue,  this.blue,  color.alpha) - this.blue) / steps;
		for (i = 0; i < steps + 1; i++) {
			r = Math.round(this.red   + (step.red * i));
			g = Math.round(this.green + (step.green * i));
			b = Math.round(this.blue  + (step.blue * i));
			pallet.push(new Color(r, g, b));
		}
		return pallet;
	}

	/*
	 * Constructor function
	 */
	return function() {
		this.toString = this.hex = hex;
		this.rgb = rgb;
		this.rgba = rgba;
		this.blend = blend

		if (arguments.length >= 3) {
			/* r, g, b or r, g, b, a */
			var r = arguments[0];
			var g = arguments[1];
			var b = arguments[2];
			var a = arguments[3];
	
			this.red   = (!isNaN(r)) ? clamp(r, 0, 255) : 0;
			this.green = (!isNaN(g)) ? clamp(g, 0, 255) : 0;
			this.blue  = (!isNaN(b)) ? clamp(b, 0, 255) : 0;
			this.alpha = (!isNaN(a)) ? clamp(a, 0.0, 1.0) : 1.0;
		} else if (arguments.length == 1) {
			/* CSS Colour keyword or value */
			var value = keyword[arguments[0]] ? keyword[arguments[0]] : arguments[0];
			var components, pattern;

			for (var key in func) {
				if (func[key].test(value)) {
					pattern = key;
				}
			}
	
			components = value.match(func[pattern]);
			var base = 10;
			var m = 1; // Multiplier for percentage values
	
			switch (pattern) {
			case "rgb%":
			case "rgba%":
				m = 2.55;
			case "rgb":
			case "rgba":
				base = 10;
				break;
			case "hex3":
				components[1] = components[1] + "" + components[1]
				components[2] = components[2] + "" + components[2]
				components[3] = components[3] + "" + components[3]
			case "hex6":
				base = 16;
				break;
			default:
				components = new Array(0, "255", "255", "255", "1.0");
			}

			this.red   = clamp(Math.round(parseInt(components[1],base) * m), 0, 255);
			this.green = clamp(Math.round(parseInt(components[2],base) * m), 0, 255);
			this.blue  = clamp(Math.round(parseInt(components[3],base) * m), 0, 255);

			if (isNaN(components[4])) {
				this.alpha = 1;
			} else {
				this.alpha = clamp(parseFloat("0" + components[4]), 0.0, 1.0);
			}
		}
	}
}();

/**
 * Author: Lachlan Hunt
 * Date: 2005-11-24
 * Version: 1.0
 *
 * Licence: Public Domain
 * Attribution is considered ethical, but not required.
 */

function fadeStep(element, pallet, step, delay) {
	return function() {
		if (step < pallet.length) {
			element.style.backgroundColor = pallet[step++].hex();
			setTimeout(fadeStep(element, pallet, step, delay),delay);
		}
	}
}

function fade(colEndVal, steps, delay, obj) {
	var colEnd = new Color(colEndVal);

	var element = $(obj);
	var colStart = (element.style.backgroundColor) ? new Color(element.style.backgroundColor) : new Color("white");

	var pallet = colStart.blend(colEnd, steps);
	
	setTimeout(fadeStep(element, pallet, 0, delay), delay);
}

/*
 * Browser detection script
 * c/o http://www.quirksmode.org/js/detect.html
 */
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: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			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();

