﻿/*
Base Scripts
*/
function wcBase() {
    //browser detection
    this.strUserAgent = navigator.userAgent.toLowerCase();
    this.isIE = this.strUserAgent.indexOf("msie") > -1 && this.strUserAgent.indexOf("msie 9") == -1;

    // Attributes
    this.imagefader = 0; // Specifies whether fades should be initialised on pageload.
    this.imageslider = 0; // Specifies whether slider should be initialised on pageload.
    this.reveals = 0; // Specifies whether reveals should be initialised on pageload.

    var self = this;

    // Onload
    this.onloadScripts = new Array();
    this.onloadProcess = function() {
        for (var i = 0; i < self.onloadScripts.length; i++) {
            eval(self.onloadScripts[i]);
        }
        // Check for fades
        if (self.imagefader == 1) {
            imagefader();
        }
        // Check for slides
        if (self.imageslider == 1) {
            imageslider();
        }
        // Check for reveals
        if (self.reveals == 1) {
            contentreveals();
        }
    }
    this.onloadAdd = function(func) {
        self.onloadScripts[self.onloadScripts.length] = func;
    }
    window.onload = self.onloadProcess;

}

var wcbs = new wcBase();

/*
    Strings
*/
if (!String.prototype.endswith) {
    String.prototype.endswith = function(suffix) {
        var startPos = this.length - suffix.length;
        if (startPos < 0) {
            return false;
        }
        return (this.lastIndexOf(suffix, startPos) == startPos);
    };
}
// Starts With
if (!String.prototype.startswith) {
    String.prototype.startswith = function(prefix) {
        return (this.indexOf(prefix) == 0);
    };
}
// Contains
if (!String.prototype.contains) {
    String.prototype.contains = function(content) {
        return (this.indexOf(content) > -1);
    };
}


/*
    Positions
*/
function getRelativePosition(e, o) {
    var left = 0;
    var top = 0;
    if (e.offsetHeight == 0) {
        /** Safari 2 doesn't correctly grab the offsetTop of a table row */
        e = e.firstChild; // a table cell
    }

    while (e.offsetParent && e != o) {
        left += e.offsetLeft;
        top += e.offsetTop;
        e = e.offsetParent;
    }

    left += e.offsetLeft;
    top += e.offsetTop;

    return { x: left, y: top };
};

