﻿// JScript File

//window.addEvent('domready',function() { new SmoothScroll({ duration: 1800 }); });  
window.addEvent('domready', function() {
    //SCROLLER
    new SmoothScroll({ duration: 1800 });

    moopop.captureByRel('popup');

    /* ----------Config Vars----------- */
    var slideTimer = 0;  //time between slides (1 second = 1000), a.k.a. the interval duration
    var transitionTime = 1250; //transition time (1 second = 1000)
    var items = $$('.slide_item');  //Get array of elements for sliding
    var prevBtn = $('prevbtn');
    var nextBtn = $('nextbtn');
    var itemNum = 0;  //initialize a variable to hold the current slide index
    var isPaused = 1;

    /* --------end config vars-------- */

    //Setup positions
    items.each(function(element, index) {

        //since the viewer obviously has javascript on, we can remove the 'first_item' class
        if (index == 0) {
            element.removeClass('first_item');
            element.setStyle('left', "0");
        }
        else {
            element.setStyle('left', "916px");
        }

    });

    var numItems = items.length;  //get number of slider items
    //end setup



    //Slider Stuff
    var slideForward = function() {

        //get item to slide out
        var curItem = items[itemNum];

        //change index
        if (itemNum < (numItems - 1)) {
            itemNum++;
        }
        else {
            itemNum = 0;
        }

        //now get item to slide in using new index
        var newItem = items[itemNum];


        //set up our animation stylings for out and in motions (note:  Fx.Styles does NOT exist in moo 1.2, so we must use Fx.Morph or Fx.Tween)
        var item_in = new Fx.Morph(newItem, {
            duration: transitionTime,
            transition: Fx.Transitions.Quad.easeInOut,
            wait: false
        });

        var item_out = new Fx.Morph(curItem, {
            duration: transitionTime,
            transition: Fx.Transitions.Quad.easeInOut,
            wait: false
        });

        //we will set a beginning value here
        //this is so that it gives the illusion of continuous motion from one direction, even after the first cycle of items
        item_in.start({
            'left': [916, 0]
        });

        //no beginning values needed, since we always want to push the old item out to the left
        item_out.start({
            'left': '-916'
        });

    };


    var slideBackward = function() {

        //get item to slide out
        var curItem = items[itemNum];

        //change index for reverse movement
        if (itemNum > 0) {
            itemNum--;
        }
        else {
            itemNum = (numItems - 1);
        }

        //now get item to slide in using new index
        var newItem = items[itemNum];


        var item_in = new Fx.Morph(newItem, {
            duration: transitionTime,
            transition: Fx.Transitions.Quad.easeInOut,
            wait: false
        });

        var item_out = new Fx.Morph(curItem, {
            duration: transitionTime,
            transition: Fx.Transitions.Quad.easeInOut,
            wait: false
        });


        //we will set a beginning value here too, but this time to make it come from left to right
        item_in.start({
            'left': [-916, 0]
        });

        //no beginning values needed
        item_out.start({
            'left': '916'
        });

    };
    //end slideBackward


    //call the slider function periodically
    var theTimer = slideForward.periodical(slideTimer, this);

    nextBtn.addEvent('click', function() {
        if (isPaused == 0) {
            $clear(theTimer);
            theTimer = slideForward.periodical(slideTimer);
        }
        slideForward();
    });

    prevBtn.addEvent('click', function() {
        if (isPaused == 0) {
            $clear(theTimer);
            theTimer = slideForward.periodical(slideTimer);
        }
        slideBackward();
    });


});


/*
moopop: unobtrusive javascript popups via late binding using mootools 1.2
  
copyright (c) 2007-2008 by gonchuki - http://blog.gonchuki.com
  
version:	1.1
released: June 23, 2008
  
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
http://creativecommons.org/licenses/by-sa/3.0/
*/


var moopop = {
    width: 0,
    height: 0,
    /*
    Function: captureByRel
    standard capturing method, it's autorun onDomReady and you can manually use it
    to capture a different set of popup windows.
      
    Syntax:
    moopop.captureByRel(value, element);
      
    Arguments:
    value - The partial string to match against the rel attribute of your links.
    element - [optional] a DOM element to restrict which links should be processed.
    */
    captureByRel: function(attrVal, parent) {
        this.capture((parent || document).getElements('a[rel*=' + (attrVal || 'popup') + ']'));
    },

    /*
    Function: capture
    multipurpose function allowing for different methods of capturing the popups.
      
    Syntax:
    moopop.capture(obj, width, height);
      
    Arguments:
    obj - (mixed) can be either a DOM element, an Array of elements or a className.
    width - [optional] (integer) default width for popups without a given size, if
    specified you must also specify the height.
    height - [optional] (integer) default height for popups without a given size.
    */
    capture: function(el, width, height) {
        if ($defined(width) && $defined(height)) {
            this.width = width;
            this.height = height;
        }

        switch ($type(el)) {
            case 'string':
                el = $$(el);
            case 'element':
            case 'array':
                $splat(el).each(this.add_pop_to, this);
        }

        this.width = null;
        this.height = null;
    },

    /*
    Function: add_pop_to
    Primarily used internally but you can also use it to manually attach the popup
    behavior to a single DOM element.
      
    Syntax:
    moopop.add_pop_to(element);
      
    Arguments:
    element - a DOM element to process.
    */
    add_pop_to: function(el) {
        el.addEvent('click', function(e) { e.stop(); this.popup(el); } .bind(this));

        var size = el.get('rel').match(/\[(\d+),\s*(\d+)/) || ['', this.width, this.height];
        var resizable = el.get('rel').match(/,(r)/) || [];

        if (size[1]) el.store('popupprops', 'width=' + size[1] + ', height=' + size[2] + (resizable[1] ? ', scrollbars=yes, resizable=yes' : ''));
    },

    /*
    Function: popup
    Triggers the popup behavior on a given link. Used internally but you can also use it to
    force a given unprocessed link to open in a new window.
      
    Syntax:
    moopop.popup(element);
      
    Arguments:
    element - a DOM element to process.
    */
    popup: function(el) {
        window.open(el.get('href'), el.get('name') || '', el.retrieve('popupprops') || '');
    }
};

function verScroll(dir, spd, loop) {
    loop = true;
    direction = "left";
    speed = 20;
    scrolltimer = null;
    if (document.layers) {
        var page = eval(document.scroller);
    }
    else {
        if (document.getElementById) {
            var page = eval("document.getElementById('scroller').style");
        }
        else {
            if (document.all) {
                var page = eval(document.all.scroller.style);
            }
        }
    }

    direction = dir;
    speed = parseInt(spd);
    width = -6000;  //minus the scrolling divs width
    containerdiv = 300;

    if (loop == true) {
        var y_pos = parseInt(page.left);
        if (direction == "right" && y_pos > (containerdiv + width)) {
            page.left = (y_pos - (speed))+"px";
        }
        else {
            if (direction == "left" && y_pos < 0) {
                page.left = (y_pos + (speed)) + "px";
            }
        }
        scrolltimer = setTimeout("verScroll(direction,speed)", 1);
    }

    //document.getElementById('ben').innerHTML = "y: " +y_pos;  
}
function stopScroll() {
    loop = false;
    clearTimeout(scrolltimer);
}