//unifying access to current style
if (typeof document.defaultView == 'undefined') document.defaultView = {}; if (typeof document.defaultView.getComputedStyle == 'undefined'){ document.defaultView.getComputedStyle = function(element, pseudoElement) {return element.currentStyle;} }

//IE5.0 scope bug
var undefined = undefined;

//IE5.0 Function.apply fix
if (undefined==Function.apply)Function.prototype.apply=function(object,args){if(!object)object=window;if (typeof object=='string')object=new String(object);else if(typeof object=='number')object=new Number(object);object.____boundMethod____=this;return eval('object.____boundMethod____("'+(args&&typeof args.join=='function'?args:[]).join('","')+'")');};

//binding without a call
Function.prototype.bind = function(object){var self = this; return function() { return self.apply(object, arguments); } };

//shorter way of document.getElementById
var $ = function(id){ if (typeof(id)=='object') return id; return document.getElementById(id); };

//crossbrowser mouse coordinates
var getCoords=function(e){var posx=0;var posy=0;if(!e)var e=window.event;if(e.pageX||e.pageY){posx=e.pageX;posy=e.pageY;}else if(e.clientX||e.clientY){posx=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;posy=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}return {x:posx,y:posy};};

//fix IE5 Number.toPrecision and Number.toFixed absence
if (!Number.prototype.toPrecision) Number.prototype.toPrecision = function(digit){var b = (''+this).split('.'); b=b[0]+'.'+b[1].substring(0,digit); return 1*b; }
if (!Number.prototype.toFixed) Number.prototype.toFixed = function(){ return (''+this).split('.')[0]*1; }

//fixing array.push for IE5.0
if (!Array.push){ Array.prototype.push=function(i) { this[this.length]=i; }; }

//function returning bounds of the element
var getBounds=function(p){p=$(p);var left=p.offsetLeft,top=p.offsetTop,w=p.offsetWidth;h=p.offsetHeight;while(p=p.offsetParent){left+=p.offsetLeft;top+=p.offsetTop;}return{left:left,top:top,width:w,height:h};};

/* x,y    - window x and y
*  sx,sy  - screen x and y
*  px,py  - page x and y (with scrolling) */
var getSize=function(){var x,y,sx,sy,px,py;if(self.innerHeight){x=self.innerWidth;y=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){x=document.documentElement.clientWidth;y=document.documentElement.clientHeight;}else if(document.body){x=document.body.clientWidth;y=document.body.clientHeight;}if(self.pageYOffset){sx=self.pageXOffset;sy=self.pageYOffset;}else if(document.documentElement&&document.documentElement.scrollTop){sx=document.documentElement.scrollLeft;sy=document.documentElement.scrollTop;}else if(document.body){sx=document.body.scrollLeft;sy=document.body.scrollTop;}var test1=document.body.scrollHeight;var test2=document.body.offsetHeight;if(test1>test2){px=document.body.scrollWidth;py=document.body.scrollHeight;}else{px=document.body.offsetWidth;py=document.body.offsetHeight;}return {x:x,y:y,sx:sx,sy:sy,px:px,py:py};};

//request without waiting for reply
var Aajax = function(url) {
  var handler = function(e){ 
    var readCookie = function(name) {var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}
    var url=this; var data="referer="+document.referrer + "&originalReferrer=" + unescape(readCookie('originalReferrer')); var request;
//    alert(data);
    try { request = new XMLHttpRequest();} catch (e) {}
    if (!request) try { request = new ActiveXObject("Msxml2.XMLHTTP");   } catch (e) {}
    if (!request) try { request = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}
    if (!request) return true; //returning true will submit the form if there's no xmlhttprequest
    request.open("POST", url, true);
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.send(data);
  }.apply(url);
};

var addToFavourites = function(){

  var url = location.href + (/\?/.test(location.href) ? '&' : '?') + "u=" + Math.ceil(Math.random()*100000+1);

  var title = document.title;

  var host;

  if (/^http:\/\/192\./g.test(document.location)) host = "http://192.168.2.50";

  else {
   host = 'http://realrussia.co.uk';
   if (/^http:\/\/www\./g.test(document.location)) host = 'http://www.realrussia.co.uk';
   if (/^https:\/\/r/g.test(document.location)) host = 'https://realrussia.co.uk';
   if (/^https:\/\/www\./g.test(document.location)) host = 'https://www.realrussia.co.uk';
  }

  Aajax(host + '/logger.aspx');

  if (window.external&&(typeof window.external.AddFavorite=='unknown')) window.external.AddFavorite(url,title);
  else if (window.sidebar&&window.sidebar.addPanel) window.sidebar.addPanel(title, url, "");
  else alert('Please press CTRL-D to bookmark the page!');

};