ImageRotator = function ImageRotator(options) {
    var defaultOptions = {
        cssSelector: '.main-page-adrotator img',
        delay: 6000,
        initialDelay: 6000,
        fadeDuration: 1500
    };

    this.options = Object.clone(defaultOptions);
    Object.extend(this.options, options || {});

    this.cycle = function () {

        var images = Sizzle(this.options.cssSelector);
        if (images.length > 1) {
            var currentDelay = 0;
            var delay = this.options.delay;
            var fadeDuration = this.options.fadeDuration;
            var firstImage = images[0];
            var i = images.length; while (i--) {
                var image = images[i];
                window.setTimeout(function () {
                    appear(this, fadeDuration);
                } .bind(image), currentDelay);
                var nextImage = next(image);
                if (!nextImage) nextImage = firstImage;
                if (nextImage) {
                    window.setTimeout(function () {
                        fade(this, fadeDuration);
                    } .bind(nextImage), currentDelay);
                }
                currentDelay += delay;
            }
        }
        window.setTimeout(this.cycle.bind(this), currentDelay);
    }

    window.setTimeout(this.cycle.bind(this), this.options.initialDelay);
};

/*!
* Sizzle CSS Selector Engine - v1.0
*  Copyright 2009, The Dojo Foundation
*  Released under the MIT, BSD, and GPL Licenses.
*  More information: http://sizzlejs.com/
*/
(function () { var z = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, A = 0, B = Object.prototype.toString, w = false, C = true; [0, 0].sort(function () { C = false; return 0 }); var l = function (a, b, d, c) { d = d || []; b = b || document; var g = b; if (b.nodeType !== 1 && b.nodeType !== 9) { return [] } if (!a || typeof a !== "string") { return d } var f = [], h, j, i, m, r = true, t = l.isXML(b), s = a, o, q, p, n; do { z.exec(""); h = z.exec(s); if (h) { s = h[3]; f.push(h[1]); if (h[2]) { m = h[3]; break } } } while (h); if (f.length > 1 && G.exec(a)) { if (f.length === 2 && k.relative[f[0]]) { j = D(f[0] + f[1], b) } else { j = k.relative[f[0]] ? [b] : l(f.shift(), b); while (f.length) { a = f.shift(); if (k.relative[a]) { a += f.shift() } j = D(a, j) } } } else { if (!c && f.length > 1 && b.nodeType === 9 && !t && k.match.ID.test(f[0]) && !k.match.ID.test(f[f.length - 1])) { o = l.find(f.shift(), b, t); b = o.expr ? l.filter(o.expr, o.set)[0] : o.set[0] } if (b) { o = c ? { expr: f.pop(), set: u(c)} : l.find(f.pop(), f.length === 1 && (f[0] === "~" || f[0] === "+") && b.parentNode ? b.parentNode : b, t); j = o.expr ? l.filter(o.expr, o.set) : o.set; if (f.length > 0) { i = u(j) } else { r = false } while (f.length) { q = f.pop(); p = q; if (!k.relative[q]) { q = "" } else { p = f.pop() } if (p == null) { p = b } k.relative[q](i, p, t) } } else { i = f = [] } } if (!i) { i = j } if (!i) { l.error(q || a) } if (B.call(i) === "[object Array]") { if (!r) { d.push.apply(d, i) } else if (b && b.nodeType === 1) { for (n = 0; i[n] != null; n++) { if (i[n] && (i[n] === true || i[n].nodeType === 1 && l.contains(b, i[n]))) { d.push(j[n]) } } } else { for (n = 0; i[n] != null; n++) { if (i[n] && i[n].nodeType === 1) { d.push(j[n]) } } } } else { u(i, d) } if (m) { l(m, g, d, c); l.uniqueSort(d) } return d }; l.uniqueSort = function (a) { if (x) { w = C; a.sort(x); if (w) { for (var b = 1; b < a.length; b++) { if (a[b] === a[b - 1]) { a.splice(b--, 1) } } } } return a }; l.matches = function (a, b) { return l(a, null, null, b) }; l.find = function (a, b, d) { var c; if (!a) { return [] } for (var g = 0, f = k.order.length; g < f; g++) { var h = k.order[g], j; if ((j = k.leftMatch[h].exec(a))) { var i = j[1]; j.splice(1, 1); if (i.substr(i.length - 1) !== "\\") { j[1] = (j[1] || "").replace(/\\/g, ""); c = k.find[h](j, b, d); if (c != null) { a = a.replace(k.match[h], ""); break } } } } if (!c) { c = b.getElementsByTagName("*") } return { set: c, expr: a} }; l.filter = function (a, b, d, c) { var g = a, f = [], h = b, j, i, m = b && b[0] && l.isXML(b[0]); while (a && b.length) { for (var r in k.filter) { if ((j = k.leftMatch[r].exec(a)) != null && j[2]) { var t = k.filter[r], s, o, q = j[1]; i = false; j.splice(1, 1); if (q.substr(q.length - 1) === "\\") { continue } if (h === f) { f = [] } if (k.preFilter[r]) { j = k.preFilter[r](j, h, d, f, c, m); if (!j) { i = s = true } else if (j === true) { continue } } if (j) { for (var p = 0; (o = h[p]) != null; p++) { if (o) { s = t(o, j, p, h); var n = c ^ !!s; if (d && s != null) { if (n) { i = true } else { h[p] = false } } else if (n) { f.push(o); i = true } } } } if (s !== undefined) { if (!d) { h = f } a = a.replace(k.match[r], ""); if (!i) { return [] } break } } } if (a === g) { if (i == null) { l.error(a) } else { break } } g = a } return h }; l.error = function (a) { throw "Syntax error, unrecognized expression: " + a; }; var k = l.selectors = { order: ["ID", "NAME", "TAG"], match: { ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/, POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ }, leftMatch: {}, attrMap: { "class": "className", "for": "htmlFor" }, attrHandle: { href: function (a) { return a.getAttribute("href") } }, relative: { "+": function (a, b) { var d = typeof b === "string", c = d && !/\W/.test(b), g = d && !c; if (c) { b = b.toLowerCase() } for (var f = 0, h = a.length, j; f < h; f++) { if ((j = a[f])) { while ((j = j.previousSibling) && j.nodeType !== 1) { } a[f] = g || j && j.nodeName.toLowerCase() === b ? j || false : j === b } } if (g) { l.filter(b, a, true) } }, ">": function (a, b) { var d = typeof b === "string", c, g = 0, f = a.length; if (d && !/\W/.test(b)) { b = b.toLowerCase(); for (; g < f; g++) { c = a[g]; if (c) { var h = c.parentNode; a[g] = h.nodeName.toLowerCase() === b ? h : false } } } else { for (; g < f; g++) { c = a[g]; if (c) { a[g] = d ? c.parentNode : c.parentNode === b } } if (d) { l.filter(b, a, true) } } }, "": function (a, b, d) { var c = A++, g = E, f; if (typeof b === "string" && !/\W/.test(b)) { b = b.toLowerCase(); f = b; g = F } g("parentNode", b, c, a, f, d) }, "~": function (a, b, d) { var c = A++, g = E, f; if (typeof b === "string" && !/\W/.test(b)) { b = b.toLowerCase(); f = b; g = F } g("previousSibling", b, c, a, f, d) } }, find: { ID: function (a, b, d) { if (typeof b.getElementById !== "undefined" && !d) { var c = b.getElementById(a[1]); return c && c.parentNode ? [c] : [] } }, NAME: function (a, b) { if (typeof b.getElementsByName !== "undefined") { var d = [], c = b.getElementsByName(a[1]); for (var g = 0, f = c.length; g < f; g++) { if (c[g].getAttribute("name") === a[1]) { d.push(c[g]) } } return d.length === 0 ? null : d } }, TAG: function (a, b) { return b.getElementsByTagName(a[1]) } }, preFilter: { CLASS: function (a, b, d, c, g, f) { a = " " + a[1].replace(/\\/g, "") + " "; if (f) { return a } for (var h = 0, j; (j = b[h]) != null; h++) { if (j) { if (g ^ (j.className && (" " + j.className + " ").replace(/[\t\n]/g, " ").indexOf(a) >= 0)) { if (!d) { c.push(j) } } else if (d) { b[h] = false } } } return false }, ID: function (a) { return a[1].replace(/\\/g, "") }, TAG: function (a, b) { return a[1].toLowerCase() }, CHILD: function (a) { if (a[1] === "nth") { var b = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(a[2] === "even" && "2n" || a[2] === "odd" && "2n+1" || !/\D/.test(a[2]) && "0n+" + a[2] || a[2]); a[2] = (b[1] + (b[2] || 1)) - 0; a[3] = b[3] - 0 } a[0] = A++; return a }, ATTR: function (a, b, d, c, g, f) { var h = a[1].replace(/\\/g, ""); if (!f && k.attrMap[h]) { a[1] = k.attrMap[h] } if (a[2] === "~=") { a[4] = " " + a[4] + " " } return a }, PSEUDO: function (a, b, d, c, g) { if (a[1] === "not") { if ((z.exec(a[3]) || "").length > 1 || /^\w/.test(a[3])) { a[3] = l(a[3], null, null, b) } else { var f = l.filter(a[3], b, d, true ^ g); if (!d) { c.push.apply(c, f) } return false } } else if (k.match.POS.test(a[0]) || k.match.CHILD.test(a[0])) { return true } return a }, POS: function (a) { a.unshift(true); return a } }, filters: { enabled: function (a) { return a.disabled === false && a.type !== "hidden" }, disabled: function (a) { return a.disabled === true }, checked: function (a) { return a.checked === true }, selected: function (a) { a.parentNode.selectedIndex; return a.selected === true }, parent: function (a) { return !!a.firstChild }, empty: function (a) { return !a.firstChild }, has: function (a, b, d) { return !!l(d[3], a).length }, header: function (a) { return (/h\d/i).test(a.nodeName) }, text: function (a) { return "text" === a.type }, radio: function (a) { return "radio" === a.type }, checkbox: function (a) { return "checkbox" === a.type }, file: function (a) { return "file" === a.type }, password: function (a) { return "password" === a.type }, submit: function (a) { return "submit" === a.type }, image: function (a) { return "image" === a.type }, reset: function (a) { return "reset" === a.type }, button: function (a) { return "button" === a.type || a.nodeName.toLowerCase() === "button" }, input: function (a) { return (/input|select|textarea|button/i).test(a.nodeName) } }, setFilters: { first: function (a, b) { return b === 0 }, last: function (a, b, d, c) { return b === c.length - 1 }, even: function (a, b) { return b % 2 === 0 }, odd: function (a, b) { return b % 2 === 1 }, lt: function (a, b, d) { return b < d[3] - 0 }, gt: function (a, b, d) { return b > d[3] - 0 }, nth: function (a, b, d) { return d[3] - 0 === b }, eq: function (a, b, d) { return d[3] - 0 === b } }, filter: { PSEUDO: function (a, b, d, c) { var g = b[1], f = k.filters[g]; if (f) { return f(a, d, b, c) } else if (g === "contains") { return (a.textContent || a.innerText || l.getText([a]) || "").indexOf(b[3]) >= 0 } else if (g === "not") { var h = b[3]; for (var j = 0, i = h.length; j < i; j++) { if (h[j] === a) { return false } } return true } else { l.error("Syntax error, unrecognized expression: " + g) } }, CHILD: function (a, b) { var d = b[1], c = a; switch (d) { case 'only': case 'first': while ((c = c.previousSibling)) { if (c.nodeType === 1) { return false } } if (d === "first") { return true } c = a; case 'last': while ((c = c.nextSibling)) { if (c.nodeType === 1) { return false } } return true; case 'nth': var g = b[2], f = b[3]; if (g === 1 && f === 0) { return true } var h = b[0], j = a.parentNode; if (j && (j.sizcache !== h || !a.nodeIndex)) { var i = 0; for (c = j.firstChild; c; c = c.nextSibling) { if (c.nodeType === 1) { c.nodeIndex = ++i } } j.sizcache = h } var m = a.nodeIndex - f; if (g === 0) { return m === 0 } else { return (m % g === 0 && m / g >= 0) } } }, ID: function (a, b) { return a.nodeType === 1 && a.getAttribute("id") === b }, TAG: function (a, b) { return (b === "*" && a.nodeType === 1) || a.nodeName.toLowerCase() === b }, CLASS: function (a, b) { return (" " + (a.className || a.getAttribute("class")) + " ").indexOf(b) > -1 }, ATTR: function (a, b) { var d = b[1], c = k.attrHandle[d] ? k.attrHandle[d](a) : a[d] != null ? a[d] : a.getAttribute(d), g = c + "", f = b[2], h = b[4]; return c == null ? f === "!=" : f === "=" ? g === h : f === "*=" ? g.indexOf(h) >= 0 : f === "~=" ? (" " + g + " ").indexOf(h) >= 0 : !h ? g && c !== false : f === "!=" ? g !== h : f === "^=" ? g.indexOf(h) === 0 : f === "$=" ? g.substr(g.length - h.length) === h : f === "|=" ? g === h || g.substr(0, h.length + 1) === h + "-" : false }, POS: function (a, b, d, c) { var g = b[2], f = k.setFilters[g]; if (f) { return f(a, d, b, c) } } } }; var G = k.match.POS, H = function (a, b) { return "\\" + (b - 0 + 1) }; for (var y in k.match) { k.match[y] = new RegExp(k.match[y].source + (/(?![^\[]*\])(?![^\(]*\))/.source)); k.leftMatch[y] = new RegExp(/(^(?:.|\r|\n)*?)/.source + k.match[y].source.replace(/\\(\d+)/g, H)) } var u = function (a, b) { a = Array.prototype.slice.call(a, 0); if (b) { b.push.apply(b, a); return b } return a }; try { Array.prototype.slice.call(document.documentElement.childNodes, 0)[0].nodeType } catch (e) { u = function (a, b) { var d = b || [], c = 0; if (B.call(a) === "[object Array]") { Array.prototype.push.apply(d, a) } else { if (typeof a.length === "number") { for (var g = a.length; c < g; c++) { d.push(a[c]) } } else { for (; a[c]; c++) { d.push(a[c]) } } } return d } } var x, v; if (document.documentElement.compareDocumentPosition) { x = function (a, b) { if (a === b) { w = true; return 0 } if (!a.compareDocumentPosition || !b.compareDocumentPosition) { return a.compareDocumentPosition ? -1 : 1 } return a.compareDocumentPosition(b) & 4 ? -1 : 1 } } else { x = function (a, b) { var d = [], c = [], g = a.parentNode, f = b.parentNode, h = g, j, i; if (a === b) { w = true; return 0 } else if (g === f) { return v(a, b) } else if (!g) { return -1 } else if (!f) { return 1 } while (h) { d.unshift(h); h = h.parentNode } h = f; while (h) { c.unshift(h); h = h.parentNode } j = d.length; i = c.length; for (var m = 0; m < j && m < i; m++) { if (d[m] !== c[m]) { return v(d[m], c[m]) } } return m === j ? v(a, c[m], -1) : v(d[m], b, 1) }; v = function (a, b, d) { if (a === b) { return d } var c = a.nextSibling; while (c) { if (c === b) { return -1 } c = c.nextSibling } return 1 } } l.getText = function (a) { var b = "", d; for (var c = 0; a[c]; c++) { d = a[c]; if (d.nodeType === 3 || d.nodeType === 4) { b += d.nodeValue } else if (d.nodeType !== 8) { b += l.getText(d.childNodes) } } return b }; (function () { var g = document.createElement("div"), f = "script" + (new Date()).getTime(); g.innerHTML = "<a name='" + f + "'/>"; var h = document.documentElement; h.insertBefore(g, h.firstChild); if (document.getElementById(f)) { k.find.ID = function (a, b, d) { if (typeof b.getElementById !== "undefined" && !d) { var c = b.getElementById(a[1]); return c ? c.id === a[1] || typeof c.getAttributeNode !== "undefined" && c.getAttributeNode("id").nodeValue === a[1] ? [c] : undefined : [] } }; k.filter.ID = function (a, b) { var d = typeof a.getAttributeNode !== "undefined" && a.getAttributeNode("id"); return a.nodeType === 1 && d && d.nodeValue === b } } h.removeChild(g); h = g = null })(); (function () { var f = document.createElement("div"); f.appendChild(document.createComment("")); if (f.getElementsByTagName("*").length > 0) { k.find.TAG = function (a, b) { var d = b.getElementsByTagName(a[1]); if (a[1] === "*") { var c = []; for (var g = 0; d[g]; g++) { if (d[g].nodeType === 1) { c.push(d[g]) } } d = c } return d } } f.innerHTML = "<a href='#'></a>"; if (f.firstChild && typeof f.firstChild.getAttribute !== "undefined" && f.firstChild.getAttribute("href") !== "#") { k.attrHandle.href = function (a) { return a.getAttribute("href", 2) } } f = null })(); if (document.querySelectorAll) { (function () { var g = l, f = document.createElement("div"); f.innerHTML = "<p class='TEST'></p>"; if (f.querySelectorAll && f.querySelectorAll(".TEST").length === 0) { return } l = function (a, b, d, c) { b = b || document; if (!c && b.nodeType === 9 && !l.isXML(b)) { try { return u(b.querySelectorAll(a), d) } catch (e) { } } return g(a, b, d, c) }; for (var h in g) { l[h] = g[h] } f = null })() } (function () { var c = document.createElement("div"); c.innerHTML = "<div class='test e'></div><div class='test'></div>"; if (!c.getElementsByClassName || c.getElementsByClassName("e").length === 0) { return } c.lastChild.className = "e"; if (c.getElementsByClassName("e").length === 1) { return } k.order.splice(1, 0, "CLASS"); k.find.CLASS = function (a, b, d) { if (typeof b.getElementsByClassName !== "undefined" && !d) { return b.getElementsByClassName(a[1]) } }; c = null })(); function F(a, b, d, c, g, f) { for (var h = 0, j = c.length; h < j; h++) { var i = c[h]; if (i) { i = i[a]; var m = false; while (i) { if (i.sizcache === d) { m = c[i.sizset]; break } if (i.nodeType === 1 && !f) { i.sizcache = d; i.sizset = h } if (i.nodeName.toLowerCase() === b) { m = i; break } i = i[a] } c[h] = m } } } function E(a, b, d, c, g, f) { for (var h = 0, j = c.length; h < j; h++) { var i = c[h]; if (i) { i = i[a]; var m = false; while (i) { if (i.sizcache === d) { m = c[i.sizset]; break } if (i.nodeType === 1) { if (!f) { i.sizcache = d; i.sizset = h } if (typeof b !== "string") { if (i === b) { m = true; break } } else if (l.filter(b, [i]).length > 0) { m = i; break } } i = i[a] } c[h] = m } } } l.contains = document.compareDocumentPosition ? function (a, b) { return !!(a.compareDocumentPosition(b) & 16) } : function (a, b) { return a !== b && (a.contains ? a.contains(b) : true) }; l.isXML = function (a) { var b = (a ? a.ownerDocument || a : 0).documentElement; return b ? b.nodeName !== "HTML" : false }; var D = function (a, b) { var d = [], c = "", g, f = b.nodeType ? [b] : b; while ((g = k.match.PSEUDO.exec(a))) { c += g[0]; a = a.replace(k.match.PSEUDO, "") } a = k.relative[a] ? a + "*" : a; for (var h = 0, j = f.length; h < j; h++) { l(a, f[h], d) } return l.filter(c, d) }; window.Sizzle = l })();

Object.prototype.extend = function (a, b) { for (var c in b) a[c] = b[c]; return a };
Object.prototype.clone = function (a) { return {}.extend(a) }; 
Object.prototype.isUndefined = function (a) { return typeof a === "undefined" };

//A bind function (prototypejs bind is too dependent on other stuff), found here: http://dhtmlkitchen.com/?category=/JavaScript/&date=2008/09/11/&entry=Function-prototype-bind
Function.prototype.bind = function (context) {
    var fn = this,
      ap, concat, args,
      isPartial = arguments.length > 1;
    // Strategy 1: just bind, not a partialApply
    if (!isPartial) {
        return function () {
            if (arguments.length !== 0) {
                return fn.apply(context, arguments);
            } else {
                return fn.call(context); // faster in Firefox.
            }
        };
    } else {
        // Strategy 2: partialApply
        ap = Array.prototype,
    args = ap.slice.call(arguments, 1);
        concat = ap.concat;
        return function () {
            return fn.apply(context,
        arguments.length === 0 ? args :
        concat.apply(args, arguments));
        };
    }
};

//custom next function 
function next(element) {
    var element = element.nextSibling;
    while (element && element.nodeType == 3) {
        element = element.nextSibling;
    }
    return element;
}

//fade in and fade out code from http://www.robpoyntz.com/blog/?p=71
function Fader(el, fadeIn, duration) {
    var me = this;
    this.el = (typeof (el) == "object") ? el : (typeof (el) == "string") ? document.getElementById(el) : null;
    this.fadeIn = fadeIn;
    this.doFade = doFade;
    this.setOpacity = setOpacity;
    this.showElement = showElement;
    this.opacity = 0;

    this.doFade(duration);

    function setOpacity() {
        if (typeof (this.el.style.opacity) != null) this.el.style.opacity = this.opacity / 100;
        if (typeof (this.el.style.filter) != null) this.el.style.filter = "alpha(opacity=" + this.opacity + ")";
        this.opacity += (this.fadeIn) ? 1 : -1;
    }

    function showElement(show) {
        if (this.el && this.el.style) this.el.style.display = (show) ? "block" : (this.fadeIn) ? "block" : "none";
    }

    function doFade(duration) {

        this.showElement(true);
        if (this.fadeIn) {
            this.opacity = 0;
            this.setOpacity();

            for (var i = 0; i <= 100; i++) {
                var newFunc = function () { me.setOpacity(); };
                setTimeout(newFunc, (duration/100) * i);
            }
        }
        else {
            this.opacity = 100;
            this.setOpacity();

            for (var i = 0; i <= 100; i++) {
                var newFunc = function () { me.setOpacity(); };
                setTimeout(newFunc, (duration / 100) * i);
            }
        }

        var newFunc = function () { me.showElement(); };

        setTimeout(newFunc, duration);
    }
}


function appear(obj, duration) {
    if (obj) new Fader(obj, true, duration);
}

function fade(obj, duration) {
    if (obj) new Fader(obj, false, duration);
}

