﻿// © 2009 WorldManuals

// Vars
var allDevices = $("div#AllDevices");
var currentPosition = 0;
var stepSize = 202;
var allDevicesHeight;

// Preload
$(document).ready(function() {
    allDevicesHeight = parseInt("-" + parseInt(allDevices.height())) + (stepSize * 2);
    if ("-150" < allDevicesHeight) {
        $("img#ScrollUp").hide();
        $("img#ScrollDown").hide();
    }
});

$("img#ScrollDown").click(ScrollDown);
$("img#ScrollUp").click(ScrollUp);


//
// Functions
function ScrollDown() {
    if (currentPosition > allDevicesHeight) {
        currentPosition = currentPosition - stepSize;
        allDevices.stop(); //Stops the active animation
        allDevices.animate(
                { top: (currentPosition - 10) + "px" },
                300).animate(
                { top: currentPosition + "px" },
                "fast");
        };
};

function ScrollUp() {
    if (currentPosition < 0) {
        currentPosition = currentPosition + stepSize;
        allDevices.stop(); //Stops the active animation
        allDevices.animate(
            { top: (currentPosition + 10) + "px" },
            300).animate(
            { top: currentPosition + "px" },
            "fast");
    };
}

//
//Mousewheel support
$(document).bind('mousewheel', function(event, delta) {
    var dir = delta > 0 ? 'Up' : 'Down';
    if (dir == "Up") {
        if (currentPosition < 0) {
            allDevices.stop();
            ScrollUp();
        }
    } else {
        if (currentPosition > allDevicesHeight) {
            allDevices.stop();
            ScrollDown();
        }
    }
});

