/**
 * @projectDescription Real Russia Limited public website
 * @fileoverview This file contains all the required client-side libraries for Real Russia public part of the website.
 * @author Vitaly Sharovatov vitaly@realrussia.co.uk
 * @version 0001
 */
 
/**
 * DomLoaded object provides a cross-browser way to add event handlers that will be fired right after the DOM is ready without waiting for window.onload
 * 
 *
 */
var DomLoaded = {
  onload: [],
  loaded: function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    for (var i=0, f; (f=DomLoaded.onload[i]); ++i) f();
  },
  load: function(fireThis) {
    this.onload.push(fireThis);
    if (document.addEventListener) document.addEventListener("DOMContentLoaded", DomLoaded.loaded, null);
    if (/KHTML|WebKit/i.test(navigator.userAgent)) var _timer = setInterval(function() { if (/loaded|complete/.test(document.readyState)) { clearInterval(_timer); delete _timer; DomLoaded.loaded();} }, 10);
    /*@cc_on 
  	var proto = "src='javascript:void(0)'";
  	if (location.protocol == "https:") proto = "src=//0";
  	document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
  	var script = document.getElementById("__ie_onload");
  	script.onreadystatechange = function() { if (this.readyState == "complete") DomLoaded.loaded(); };
     @*/
     window.onload = DomLoaded.loaded;
  }
};

//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 }; };

/* fastest trim function - see http://blog.stevenlevithan.com/archives/faster-trim-javascript */
String.prototype.trim = function() { var str = this.replace(/^\s\s*/, ''), ws = /\s/, i = str.length; while (ws.test(str.charAt(--i))); return str.slice(0, i + 1); };

/* basic function toggling element visibility */
var toggleElem = function(obj){ obj.style.display = 'none' == obj.style.display ? '' : 'none'; };

/**
 * Create a div shim only once. If the browser is older than IE7, iframe is created and positioned under this div
 * @classDescription Singleton object creating only one instance of the shim and iframe.
 * @author Vitaly Sharovatov vitaly@realrussia.co.uk
 * @return {Object} Returns instantiated object
 * @type {Object}
 * @constructor
 */
var shim = function() {
    if ('undefined' == typeof arguments.callee.__shim) {

        /**
        * @constructor
        */
        arguments.callee.__shim = new function() {

            var div = document.createElement('div');
            div.id = 'rrShimDiv';
            div.style.position = 'absolute';
            div.style.zIndex = '1000';
            document.body.appendChild(div);

            //we create an iframe for IE6 and older;
            /*@cc_on
            var oldIE = (5.6 > @_jscript_version || (5.7 == @_jscript_version && -1 != navigator.userAgent.toLowerCase().indexOf("msie 6.")));

            if (oldIE) {
                var iframe = document.createElement('iframe');
                document.body.appendChild(iframe);
                iframe.id = div.iframeShimId = 'rrShimIframe';
                iframe.src = 'javascript:"<html style=display:none></html>"';
                var st = iframe.style;
                st.padding = '0';
                st.margin = '0';
                st.position = 'absolute';
                st.zIndex = '999'; // less than rrShimDiv
                st.setExpression('left', 'rrShimDiv.offsetLeft');
                st.setExpression('top', 'rrShimDiv.offsetTop');
                st.setExpression('width', 'rrShimDiv.offsetWidth');
                st.setExpression('height', 'rrShimDiv.offsetHeight');
            }
            @*/

            /**
            * @method
            * @public
            * @return {Object} Returns shim div's handler
            */
            this.getShim = function() {
                return div;
            };

            /**
            * hides shim (and iframe if neccessary)
            * @method
            * @public
            */
            this.hideShim = function() {
                div.style.display = 'none';
                /*@cc_on
                if (oldIE) iframe.style.display = 'none';
                @*/
            };

            /**
            * shows shim (and iframe if neccessaary)
            * @method
            * @public
            */
            this.showShim = function() {
                /*@cc_on
                if (oldIE) iframe.style.display = '';
                @*/
                div.style.display = 'block';
            };

            /**
            * @method
            * @public
            * @param {String} width any CSS length value (http://www.w3.org/TR/CSS2/syndata.html#length-units)
            */
            this.setWidth = function(width) {
                div.style.width = width;
            };

            /**
            * @method
            * @public
            * @param {String} height any CSS length value (http://www.w3.org/TR/CSS2/syndata.html#length-units)
            */
            this.setHeight = function(height) {
                div.style.height = height;
            };

            /**
            * @method
            * @public
            * @param {String} left any CSS length value (http://www.w3.org/TR/CSS2/syndata.html#length-units)
            */
            this.setLeft = function(left) {
                div.style.left = left;
            };

            /**
            * @method
            * @public
            * @param {String} top any CSS length value (http://www.w3.org/TR/CSS2/syndata.html#length-units)
            */
            this.setTop = function(top) {
                div.style.top = top;
            };

            /**
            * @method
            * @public
            * @param {String} right any CSS length value (http://www.w3.org/TR/CSS2/syndata.html#length-units)
            */
            this.setRight = function(right) {
                div.style.right = right;
            };

            /**
            * @method
            * @public
            * @param {String} bottom any CSS length value (http://www.w3.org/TR/CSS2/syndata.html#length-units)
            */
            this.setBottom = function(bottom) {
                div.style.bottom = bottom;
            };

            /**
            * @method
            * @public
            * @param {Number} opacity as defined in CSS3 (http://www.w3.org/TR/css3-color/#opacity) - <alphavalue> [0,x,1]
            */
            this.setTransparency = function(opacity) {
                //CSS3 standard method first:
                div.style.opacity = opacity;

                /*@cc_on
                //NOT FUTURE COMPATIBLE! :( What happens if w3c opacity gets supported in IE9?
                opacity = opacity * 100;
                div.style.filter = 'alpha(opacity=' + opacity + ')';

                //if it's old IE which requires a shim, we set it to be transparent
                if (oldIE) iframe.style.filter = 'alpha(opacity=0)';
                @*/
            };

        };
    }
    return arguments.callee.__shim;
};

//marquee

/*
var delayb4scroll=1400; //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=2; //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1; //Pause marquee onMousever (0=no. 1=yes)?

var copyspeed=marqueespeed;
var pausespeed=(pauseit==0)? copyspeed: 0;
var actualheight='';

function scrollmarquee() {
   var currentTop = parseInt(cross_marquee.style.top);
   if (currentTop > (actualheight * (-1) + 8))
     cross_marquee.style.top=currentTop-copyspeed+"px";
  else
     cross_marquee.style.top=parseInt(marqueeheight)+8+"px";
}

function initializemarquee(){
    cross_marquee = document.getElementById("vmarquee");
    cross_marquee.style.top = 0;
    marqueeheight = document.getElementById("marqueecontainer").offsetHeight;
    actualheight = cross_marquee.offsetHeight;
  //setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll);
}

//if (window.addEventListener) window.addEventListener("load", initializemarquee, false)
//else if (window.attachEvent) window.attachEvent("onload", initializemarquee)
//else if (document.getElementById) window.onload=initializemarquee

*/
