//
// Startup scripts for City Honda.
//
// @author Tom Ryder <tom@prodev.co.nz>
// @copyright 2010 Professional Development
//
"use strict";
$(window).addEvent("domready", function () {

    // Hover class setup.
    $$(".menu li").each(function (item) {
        item.onmouseover = function () {
            this.addClass("hover");
        };
        item.onmouseout = function () {
            this.removeClass("hover");
        };
    });



    // Flicker for promotions.
    (function () {
        var show = {"display": "block"},
            hide = {"display": "none"};
        $$("#home").each(function (home) {
            home.getElements(".categories>li").each(function (category) {
                var products = category.getElements(".products>li"),
                    current = 0,
                    left = category.getElements(".left"),
                    right = category.getElements(".right"),
                    redraw;
                redraw = function () {
                    products.each(function (product) {
                        product.setStyles(hide);
                    });
                    products[current].setStyles(show);
                };
                left.addEvent("click", function () {
                    if (current > 0) {
                        current -= 1;
                        redraw();
                    }else{
						current=products.length - 1;
						redraw();
					}
                });
                right.addEvent("click", function () {
                    if (current < (products.length - 1)) {
                        current += 1;
                        redraw();
                    }else{
						current=0;
						redraw();
					}
                });
            });
        });
    }());
});

