
// Image Rotator Copyright (C) 2009 Seth Hill. All rights reserved. 
 
function Rotator(img1, img2, txt1, txt2, rotate_time) {
    this.sources = Array();

    this.index = 0;

    this.image_nodes = Array($(img1), $(img2));
    this.text_nodes = Array($(txt1), $(txt2));

    this.rotate_delay = rotate_time;

    this.stop = true;
};

Rotator.prototype.add_image = function(img_url, html_text, link_href) {
    var i = new Image();
    i.src = img_url;

    this.sources.push(Array(i, html_text, link_href));
};

Rotator.prototype.begin_rotate = function() {
    var t = this;
    var f = function() {
        t.rotate.apply(t);
    };  

    this.stop = false;
    setTimeout(f, this.rotate_delay);
};

Rotator.prototype.rotate = function() {
    var cur;
    var cur_img, next_img;
    var cur_text, next_text;

    cur = this.index % 2; // idx++ % 2

    cur_img = this.image_nodes[cur];
    next_img = this.image_nodes[(cur + 1) % 2];
    cur_text = this.text_nodes[cur];
    next_text = this.text_nodes[(cur + 1) % 2];

    this.index = (this.index + 1) % this.sources.length;
    next_img.src = this.sources[this.index][0].src;

    next_text.innerHTML = this.sources[this.index][1];

	if (this.sources.length == 1) {
		return;
	}

    new Effect.Fade(cur_img, { duration: 0.5, queue: { scope: 'img'} });
    new Effect.Appear(next_img, { duration: 1.0, queue: { scope: 'img', position: 'end'} });

    new Effect.Fade(cur_text, { duration: 0.75, queue: { 'scope': 'text'} });
    new Effect.Appear(next_text, { duration: 0.25, queue: { scope: 'text', position: 'end'} });

    if (!this.stop) {
        this.begin_rotate();
    }
};

z4 = function() {
	var a = ''
	for (var i = 0; i < arguments.length; i++) { 
		a = a + (Number(arguments[i]) / 7);
	}
	document.write(a.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3"));
}

q7 = function() {
	var a = arguments[0].replace(/(.)\1+/gi,'$1') + 
			String.fromCharCode(Math.pow(2,6)) + arguments[1].replace(/(.)\1+/gi,'$1');
	document.write('<'+'a href="mai','lto:',a,'">' + a, '</' + 'a>');
}

