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

/**
 * larue.js
 *
 * Site specific javascript
 *
 * File Path: /scripts/
 *
 * $Id: larue.js 237 2009-06-16 19:05:55Z topdog $
 *
 * LICENSE: copyright 2005, 2006 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/v2.x 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     DD-CMS
 * @author      Edward Vermillion <evermillion@doggydoo.net>
 * @copyright   2005, 2006 Edward Vermillion, Doggydoo Codeworks
 * @license     http://www.doggydoo.net/license/v2.x
 * @version     2.0.2
 */

/**
 * This is the namespace container for the site specific functions
 */
var LARUE = new function () {

    this.profileLinks = {show: function(){}, hide: function(){}};
    this.projectsLinks = {show: function(){}, hide: function(){}};

    /**
     * Main navigation link images...
     */
    DDJS.Images.addToCache('/images/profileLink_on.png');
    DDJS.Images.addToCache('/images/projectsLink_on.png');
    DDJS.Images.addToCache('/images/contactsLink_on.png');

    DDJS.addInit(this);

    this.init = function () {

        /**
         * Main navigation object setup...
         */
        this.profileLinks = new this.mainLink('profileLinkImg', 'profileSubLinks');
        this.projectsLinks = new this.mainLink('projectsLinkImg', 'projectsSubLinks');
    };

    this.hideFlash = function () {

        var flashDiv = document.getElementById('flashContent');
        var mainDiv = document.getElementById('mainContent');

        if (flashDiv != null) {
            mainDiv.style.display = "block";
            flashDiv.style.display = "none";
        }

    };

    this.showFlash = function () {

        var flashDiv = document.getElementById('flashDiv');

        if (flashDiv != undefined) {
            flashDiv.style.visibility = 'visible';
        }

    };
    
    this.loadPage = function (div) {

        DDJS.loadPage();

        // Selected Works and On the Boards sub links scroller
        // only builds out if the container div is available
        //
        var sectionSubsOuter = document.getElementById('sectionSubLinks');
        var sectionSubsInner = document.getElementById('scrolledLinks');
        if (sectionSubsOuter && sectionSubsInner) {
            this.sectionSubs = new DDJS.Effects.Scroller(sectionSubsOuter, sectionSubsInner);            
            this.sectionSubs.scrollToElement(document.getElementById('activeLink'));
        }
        
    };
    
}; // End Class LARUE

LARUE.progressMeter = function (name) {

	this.progressBar = document.getElementById('progressBar');
	this.progressCount = document.getElementById('progressCount');

	this.interval = window.setInterval(name + '.updateProgress()', 1000);

	this.updateProgress = function () {

		var meterMaxWidth = 367;
		var meterCurrWidth = 0;
		var currPercent = 0;
		var cnt = DDJS.loadedImages;
		var tot = document.images.length;

		currPercent = Math.floor(cnt/tot * 100);
		meterCurrWidth = Math.floor(currPercent/100 * meterMaxWidth);

		if (this.progressCount) {
			this.progressCount.innerHTML = currPercent + '%';
		}
		if (this.progressBar) {
			this.progressBar.style.width = meterCurrWidth+'px';
		}

		if (currPercent >= 100) {
			window.clearInterval(this.interval);
		}
	};
};

/**
 * LARUE.mainLink
 *
 * An action container object for the main navigation
 *
 * This object abstracts out the necessary actions to show and hide the various
 * main navigation elements into two methods, show() and hide();. It works on a
 * main link/sub link div pair.
 */
LARUE.mainLink = function (linkImg, subLinkDiv) {

    /**
     * @type Object HTMLImageElement
     *
     * The main link image object
     */
    this.link = document.getElementById(linkImg);

    /**
     * @type Object HTMLDivElement
     *
     * The container div for the sublinks
     */
    this.subLinks = document.getElementById(subLinkDiv);

    /**
     * @type Integer
     *
     * State of this object
     *
     * 0 = hidden
     * 1 = shown
     */
    this.state = 0;

    /**
     * show method
     *
     * Shows the main/sub link pair
     *
     * @return null
     */
    this.show = function () {

        if (this.state == 1) {
            return;
        }

        this.link.src = this.link.src.replace(/_off/, '_on');
        this.subLinks.style.display = 'block';

        this.state = 1;
        return;
    };

    /**
     * hide method
     *
     * Hides the main/sub pair
     *
     * @return null
     */
    this.hide = function () {

        if (this.state == 0) {
            return;
        }

        this.link.src = this.link.src.replace(/_on/, '_off');
        this.subLinks.style.display = 'none';

        this.state = 0;
        return;
    };

}; // End LARUE.mainLink()






