﻿/******************************************/
/* kitchencurries.com.au Javascript       */
/* Dependencies: mootools-release-1.11.js */
/* Author: James Ducker, StudioJ Design   */
/* http://www.studioj.net.au/             */
/******************************************/

// Handles the product range box and its AJAX calls.
window.addEvent("domready", function() {
    if ($chk($("productMenu"))) {
        var activeEl=null;
        $$(".categoryLink").each(function(el, index) {
            el.addEvent("click", function() {
                if (activeEl != null) {
                    activeEl.removeClass("active");
                }
                this.addClass("active");
                activeEl = this;
                $("productSelector").setHTML("<p>Now loading your selection...</p>");
                var urlArray = el.getAttribute("href").split("/");
                var hashArray = urlArray[urlArray.length-1].split("#");
                var url = "/prodparts/" + hashArray[hashArray.length-1] + ".html";
                var prodAjax = new Ajax(url, {
                    method: 'get',
                    update: $('productSelector'),
                    timeout: 10000,
                    onTimeout: function() {
                        $('productSelector').setHTML('<p class="error"><strong>Error loading menu. Please try again.</strong><br />If this problem persists, please click '+ notifyWebmaster() +' to notify the webmaster.</p>');
                        this.removeClass('active');
                        activeEl = null;
                    }
                }).request();
            }.bind(el));
        });
    }
});

window.addEvent("domready", function() {
    if ($chk($("GMapContainer")) && GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("GMapContainer"));
        map.addControl(new GLargeMapControl());
        map.setCenter(new GLatLng(-33.833842,151.229387), 14);
        var point = new GLatLng(-33.833842,151.229387);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml("<strong>Kitchen Curries</strong><br /><br />10 Reginald St<br />Mosman NSW 2088");
    }
});

window.addEvent("unload", function() {
    GUnload();
});

function notifyWebmaster() {
    var e1, e2, e3;
    e1 = "webmaster";
    e2 = "@kitchencurries.";
    e3 = "com.au";
    return "<a href=\"" + "mailto:" + e1 + e2 + e3 + ">here</a>";
}