/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 */

/**
 * DDJS.js
 *
 * File Path: /scripts/
 *
 * $Id: DDJS.js 181 2007-08-31 18:50:28Z topdog $
 *
 * LICENSE: copyright 2005 - 2007 Edward Vermillion - Doggydoo Codeworks.
 * Unless otherwise stated ALL RIGHTS ARE RESERVED. Use or reuse without prior
 * written permission from the author or Doggydoo Codeworks is prohibited.
 * Visit http://www.doggydoo.net/license/DDJS-V1.X.txt for the full license.
 * Installation and use of this software implies agreement to the full
 * license.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DOGGYDOO
 * CODEWORKS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package     DDJS
 * @author      Edward Vermillion <evermillion@doggydoo.net>
 * @copyright   2005 - 2007 Edward Vermillion, Doggydoo Codeworks
 * @license     http://www.doggydoo.net/license/DDJS-V1.X.txt
 * @version     1.0
 */
var DDJS = {

    baseURL: '',
    siteURL: '',
    isIE: false,
    initCache: [],
    addInit: function (obj) {
        this.initCache.push(obj);
    },
    initSubs: function () {
        var n = this.initCache.length;
        var i;
        if (n > 0) {
            for (i=0; i < n; i++) {
                this.initCache[i].init();
            }
        }
    },
    loadPage: function () {
        if (typeof DDJS.Config != 'undefined') {
            DDJS.Config.init();
        }
        this.initSubs();
    },
    toString: function () {
        return '[Object] DDJS';
    }

};
if (!window.getComputedStyle) {
    window.getComputedStyle = function (elem, psudoElem) {
        if (document.defaultView && document.defaultView.getComputedStyle) {
            return document.defaultView.getComputedStyle(elem, psudoElem);
        } else if (elem.currentStyle) {
            return elem.currentStyle;
        } else if (elem.style){
            return elem.style;
        } else {
            return null;
        }
    };
}
DDJS.Utils = {
    generateRandomString: function (stringLength) {
        var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
        var randomstring = '';
        for (var i = 0; i < stringLength; i++) {
            randomstring += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        return randomstring;
    },
    generateObjectID: function (type) {
        switch (type) {
            case 'md5':
            case '1':
                return DDJS.Utils.MD5.md5(DDJS.Utils.generateRandomString(10) + Date().toString);
                break;
            case 'sha1':
            case '2':
                return DDJS.Utils.SHA1.sha1(DDJS.Utils.generateRandomString(10) + Date().toString);
                break;
            case 'uuidTime':
            case '3':
                return DDJS.Utils.UUID.getTime();
                break;
            case 'uuidRand':
            case '4':
                return DDJS.Utils.UUID.getRandom();
                break;
            default:
                return DDJS.Utils.generateRandomString(15);
        }
    },
    toString: function () {
        return '[Object] DDJS.Utils';
    }

};
DDJS.Config = {
    init: function () {
        var outer1, inner1, outer2, inner2, outer3, inner3;
        outer1 = document.getElementById('scrollOuter1');
        inner1 = document.getElementById('scrollInner1');	    
        window.scroller1 = new DDJS.Effects.Scroller(outer1, inner1);
        window.scroller1.setScrollerAccel(0);
        outer2 = document.getElementById('scrollOuter2');
        inner2 = document.getElementById('scrollInner2');	    
        window.scroller2 = new DDJS.Effects.Scroller(outer2, inner2);
        window.scroller2.setScrollerAccel(0);
        outer3 = document.getElementById('scrollOuter3');
        inner3 = document.getElementById('scrollInner3');	    
        window.scroller3 = new DDJS.Effects.Scroller(outer3, inner3);
        window.scroller3.setScrollerAccel(0);
    },
    page: null,
    loadClasses: function (page) {
        this.page = page;
        DDJS.Images.addToCache('images/lowerLink_on.png');
        DDJS.Images.addToCache('images/podcastLink1_on.png');
        DDJS.Images.addToCache('images/podcastLink2_on.png');
        DDJS.Images.addToCache('images/podcastLink3_on.png');
        DDJS.Images.addToCache('images/radioSpotLink1_on.png');
        DDJS.Images.addToCache('images/upArrow1_on.png');
        DDJS.Images.addToCache('images/upArrow2_on.png');
        DDJS.Images.addToCache('images/upArrow3_on.png');
        DDJS.Images.addToCache('images/downArrow1_on.png');
        DDJS.Images.addToCache('images/downArrow2_on.png');
        DDJS.Images.addToCache('images/downArrow3_on.png');
    },
    toString: function () {
        return '[Object] DDJS.Config';
    }

};
DDJS.Images = {
    imageCache: new Array(),
    _icc: -1,
    addToCache: function (imgSrc) {
        this._icc++;
        this.imageCache[this._icc] = new Image();
        this.imageCache[this._icc].src = imgSrc;
        return this.imageCache[this._icc];
    },
    swapImage: function (imgObj, newSrc) {
        imgObj.src = newSrc;
    },
    rollImage: function (imgObj, state) {
        var oldSrc = imgObj.src;
        var newSrc;
        if (imgObj.filters && imgObj.filters.length > 0) {
            oldSrc = imgObj.filters(0).src;
        }
        if (state == 'off') {
            newSrc = oldSrc.replace('_on', '_off');
        } else if (state == 'on') {
            newSrc = oldSrc.replace('_off', '_on');
        }
        this.swapImage(imgObj, newSrc);
    },
    toString: function () {
        return '[Object] DDJS.Images';
    }
};
DDJS.Effects = {
    _effectsObjs: {},
    registerEffect: function (obj, objID) {
        this._effectsObjs[objID] = obj;
    },
    execEffect: function (objID, func, args) {
        var evalString = 'this._effectsObjs["'+objID+'"].'+func+'(';
        if (typeof args != 'undefined') {
            if (typeof args == 'string') {
                evalString += "'"+args+"'";
            } else {
                for (var i=0; i<args.length; i++) {
                    evalString += "'"+args[i]+"',";
                }
                evalString.replace(/,$/, '');
            }
        }
        evalString += ');';
        eval(evalString);
    },
    toString: function () {
        return '[Object] DDJS.Effects';
    }
};
DDJS.Utils.Loader = {
    _numImages: 0,
    _loadedImages: 0,
    init: function (div) {
        var mainDiv = document.getElementById(div);
        DDJS.loadPage();
        if (DDJS.IE && DDJS.IE.IE6 != 'undefined') {
            DDJS.IE.IE6.checkPNGs();
        }
        mainDiv.style.visibility = 'visible';
    },
    countImage: function (imageObj) {
        this._loadedImages++;
    }
};
DDJS.Effects.Scroller = function (outer, inner) {
    this._outer = outer;
    this._inner = inner;
    this._innerStyle = null;
    this._scrollerID = DDJS.Utils.generateObjectID();
    this._state = 'start';
    this._vertScrollDistance = null;
    this._horzScrollDistance = null;
    this._defaultGain = 2;
    this._gain = null;
    this._defaultFrequency = 10;
    this._frequency = this._defaultFrequency;
    this._scrollCount = 0;
    this._scrollAccel = 100;
    this._timerID = null;
    this._left = 0;
    this._top = 0;
    DDJS.Effects.registerEffect(this, this._scrollerID);
    this._innerStyle = window.getComputedStyle(this._inner,'');
    if (this._innerStyle.fontSize.replace(/(?:px|pt)/, '') != 0) {
        this._defaultGain = Math.round(this._innerStyle.fontSize.replace(/(?:px|pt)/, '')/10);
    }
    this._gain = this._defaultGain
    this._vertScrollDistance = this._outer.scrollHeight - this._outer.offsetHeight;
    if (this._vertScrollDistance < 0) {
        this._vertScrollDistance = 0;
    }
    this._horzScrollDistance = this._outer.scrollWidth - this._outer.offsetWidth;
    if (this._horzScrollDistance < 0) {
        this._horzScrollDistance = 0;
    }
};
DDJS.Effects.Scroller.prototype = {
    showScrollers: function () {
        if (this._vertScrollDistance == 0 && this._horzScrollDistance == 0) {
            return false;
        }
        return true;
    },
    setScrollerAccel: function (val) {
        this._scrollAccel = Math.abs(val);
    },
    setDefaultGain: function (num, setGain) {
        if (num != null) {
            this._defaultGain = num;
            if (setGain) {
                this._gain = num;
            }
        }
    },
    getState: function () {
        return this._state;
    },
    scroll: function (direction) {
        var callString = "DDJS.Effects.execEffect('"+this._scrollerID+"', 'scroll', '"+direction+"');";
        if (this._timerID != null) {
            window.clearTimeout(this._timerID);
            this._timerID = null;
        }
        if (direction == 'start' ) {
            if (this._vertScrollDistance) {
                if (this._top < 0) {
                    this._top = this._top + this._gain;
                    if (this._top > 0) {
                        this._top = 0;
                    }
                } else {
                    this._state = 'start';
                }
            } else if (this._horzScrollDistance) {
                if (this._left < 0) {
                    this._left = this._left + this._gain;
                    if (this._left > 0) {
                        this._left = 0;
                    }
                } else {
                    this._state = 'start';
                }
            }
        } else if (direction == 'end') {
            if (this._vertScrollDistance) {
                if (Math.abs(this._top) < this._vertScrollDistance) {
                    this._top = this._top - this._gain;
                    if (Math.abs(this._top) > this._vertScrollDistance) {
                        this._top = -this._vertScrollDistance;
                    }
                } else {
                    this._state = 'end';
                }
            } else if (this._horzScrollDistance) {
                if (Math.abs(this._left) < this._horzScrollDistance) {
                    this._left = this._left - this._gain;
                    if (Math.abs(this._left) > this._horzScrollDistance) {
                        this._left = -this._horzScrollDistance;
                    }
                } else {
                    this._state = 'end';
                }
            }
        }
        if ((direction == 'start' && this._state != 'start') ||
            (direction == 'end' && this._state != 'end')) {
            this._doScroll();
            if (this._scrollAccel !== 0) {
                if (this._scrollCount % this._scrollAccel == 0) {
                    this._gain = Math.round(this._gain + 2);
                }
            }
            this._timerID = window.setTimeout(callString, this._frequency);
        } else {
            window.clearTimeout(this._timerID);
            this._timerID = null;
        }
    },
    halt: function () {
        window.clearTimeout(this._timerID);
        this._timerID = null;
        this._scrollCount = 0;
        this._frequency = this._defaultFrequency;
        this._gain = this._defaultGain;
        this._state = 'halted';
    },
    zoom: function (direction) {
        if (this._timerID != null) {
            window.clearTimeout(this._timerID);
            this._timerID = null;
        }
        if (direction == 'start') {
            this._left = 0;
            this._top = 0;
        } else if (direction = 'end') {
            if (this._vertScrollDistance) {
                this._top = -this._vertScrollDistance;
            } else if (this._horzScrollDistance) {
                this._left = -this._horzScrollDistance;
            }
        }
        this._doScroll();
    },
    toString: function () {
        return '[Object] DDJS.Effects.Scroller';
    },
    _doScroll: function () {
        this._inner.style.top = this._top.toString() + 'px';
        this._inner.style.left = this._left.toString() + 'px';
        this._state = 'scrolling';
        this._scrollCount++;
    }

};


DDJS.audioPlayer = function () {
	
    this.playerWindow = null;
	
	this.currFile = null;
    
    this.openWindow = function () {
    	this.playerWindow = open('files/' + this.currFile + '.html', 'audioPlayerWin', 'width=450,height=250');
    };
    
    this.focusWindow = function () {
		if (!this.playerWindow.closed) {
    		this.playerWindow.focus();
		} else {
			this.openWindow();
		}
    };
	
	this.closeWindow = function () {
		if (this.playerWindow && !this.playerWindow.closed) {
			this.playerWindow.close();
		}
	};
 
    this.play = function (file) {
		if (file !== this.currFile) {
			this.closeWindow();
			this.currFile = file;
			this.openWindow();
		} else {
			this.focusWindow();
		}
		return true;
    }
};














