

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
	} while (obj = obj.offsetParent);
	return([curleft,curtop]);
  }	
}



function copyObject(dst,src){
  for (i in src){
    if (typeof src[i] != 'object')
      dst[i]=src[i];
  }
}

function cloneObject(what) {
  for (i in what) {
    if (typeof what[i] != 'object')
      this[i] = what[i];
/*
    if (typeof what[i] == 'object') {
      this[i] = new cloneObject(what[i]);
    }else
      this[i] = what[i];
*/      
  }
}

function unserialize(str){
/*  return(eval("("+str+")")); */
  return(JSON.parse(str));
}

function serialize(obj){
  var str="";
  var i;
  switch(typeof obj){
    case 'string':
      str+='"'+obj+'"';
     break;
    case 'number':
      str+=obj;
     break;
    case 'array':
      str+="[";
      for (i=0; i<obj.length; ++i)  
        str+=serialize2(obj[i])+",";
      for (i in obj)
        str+=i+":"+serialize2(obj[i])+",";
      if (str.length>1)
        str=str.substr(0,str.length-1)+"]";
      else
        str+="]";
     break;
    case 'object':
      str+="{";
      for (i in obj)
        str+=i+":"+serialize2(obj[i])+",";
      if (str.length>1)
        str=str.substr(0,str.length-1)+"}";
      else
        str+="}";
     break;
    case 'boolean':
      if (obj) str+='true';
      else str+='false';
     break;
    default:
      alert("serialize: unhandled type: "+typeof obj);
  }
  return(str);
}


function getWindowSize(){
  if (self.innerWidth)
    { sWidth=self.innerWidth; sHeight=self.innerHeight; }
  else if (document.documentElement && document.documentElement.clientHeight)
	{ sWidth = document.documentElement.clientWidth; sHeight = document.documentElement.clientHeight; }
  else if (document.body)
	{ sWidth = document.body.clientWidth; sHeight = document.body.clientHeight; }
}

function doResize(){
  getWindowSize();
  var Hwrapper=document.getElementById("wrapper");
  var Hhorizon=document.getElementById("horizon");
  if (sHeight < Hwrapper.offsetHeight+10){
    Hwrapper.style.top="0px";
    Hhorizon.style.height="0px";
  }else{
    Hwrapper.style.top=(-Hwrapper.offsetHeight/2)+"px";
    Hhorizon.style.height="50%";
  }
}


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();

if(!Array.indexOf && (BrowserDetect.browser=="Explorer" || BrowserDetect.browser=="Opera")){
  Array.prototype.indexOf = function(obj){
    for(var i=0; i<this.length; i++){
      if(this[i]==obj){
        return i;
      }
    }
    return -1;
  }
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]

/*
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
           img.style.width=img.width+"px";
           img.style.height=img.height+"px";
           img.style.display="inline-block";
           img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='scale')";
         }
*/

         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}


function revertPNGImg(img,newsrc)
{
  var imgID = (img.id) ? "id='" + img.id + "' " : ""
  var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  var imgStyle = "display:inline-block;" + img.style.cssText 
  if (img.align == "left") imgStyle = "float:left;" + imgStyle
  if (img.align == "right") imgStyle = "float:right;" + imgStyle
  if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
  var strNewHTML = "<img src=\""+newsrc+"\" " + imgID + imgClass + imgTitle
          + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
          + "\">" 
          img.outerHTML = strNewHTML
}








