﻿/* HOME Teaser Rotator */
var HTRIndex;
HTRIndex = 0;
var HTRStartIndex;
HTRStartIndex = 0;

var HTR_Link = new Array();
var HTR_Title = new Array();
var HTR_Pic = new Array();
var HTR_PicAlt = new Array();
var HTR_Text = new Array();

function RenderRotator() {
    if (HTRIndex == HTRStartIndex)
        return;

    var core = HTRStartIndex + (new Date().getSeconds() % (HTRIndex - HTRStartIndex));
    var ranlink = HTR_Link[core];
    var ranimage = HTR_Pic[core];
    var ranimagealt = HTR_PicAlt[core];
    var rantitle = HTR_Title[core];
    var rantext = HTR_Text[core];

    document.write(
        '<div class="teaserHome">' +
            '<h1 class=\"teaserHomeHeader\"><a href=\"' + ranlink + '"\>' + rantitle + '</a></h1>' +
            '<img src=\"' + ranimage + '\" alt=\"' + ranimagealt + '\" />' +
            '<div class=\"contentTH\">' +
                '<a href=\"' + ranlink + '">' + rantext + '</a>' +
            '</div>' +
        '</div>'
    );
}

/* Client-side access to querystring name=value pairs
Version 1.3
28 May 2008
	
License (Simplified BSD):
http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
    this.params = new Array();

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &

    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);

        var value = (pair.length == 2)
			? decodeURIComponent(pair[1])
			: name;

        this.params[i] = new Array(name.toLowerCase(), value);
    }
}

Querystring.prototype.get = function(key, default_) {
    for (var i = 0; i < this.params.length; i++) {
        if (this.params[i][0] == key.toLowerCase())
            return this.params[i][1];
    }
    return default_;
}

Querystring.prototype.contains = function(key) {
    for (var i = 0; i < this.params.length; i++) {
        if (this.params[i][0] == key.toLowerCase())
            return true;
    }
    return false;
}

Querystring.prototype.set = function(key, value) {
    for (var i = 0; i < this.params.length; i++) {
        if (this.params[i][0] == key.toLowerCase()) {
            this.params[i][1] = value;
            return;
        }
    }
    this.params[i] = new Array(key, value);
}

Querystring.prototype.toString = function() {
    var output = '';

    for (i = 0; i < this.params.length; i++)
        output = output + '&' + this.params[i][0] + '=' + this.params[i][1];

    if (output != '')
        output = '?' + output.substring(1, output.length);

    return output;
}