var AppBehavior = Class.create();
AppBehavior.Load = function() {
	OS.RegisterBehaviour(AppBehavior.Rules);
}
AppBehavior.Rules = {
    '#Cnt_Content': function(element) {
        Event.observe(window, 'resize', _OnResize);
    },
    '.command': function(element) {
        Application.SetRollover(element);
    },
    '#Cnt_Content a': function(element) {
        Application.SetRollover(element);
    },
    '.togglable': function(element) {
        Application.SetTogglableBehavior(element, null, _OnResize);
    },
    '#Nav_Main .navItem': function(element) {
        Application.SetRollover(element);
    },
    '#Nav_Contact .navItem': function(element) {
        Application.SetRollover(element);
    },
    '#Nav_Footer .navItem': function(element) {
        Application.SetRollover(element);
    },
    '#Pv_Rates .navItem': function(element) {
        Application.SetRollover(element, null, {
            onActive: function(id) {
                var eActive = $(id);
                var eNav = eActive.up('.navigation');
                eNav.select('.navItem').each(function(navItem) {
                    if (navItem != eActive) Element.removeClassName(navItem, 'active');
                });
            }
        });
    },
    '.viewSplash #Dv_Rates': function(element) {
        Event.observe(element, 'click', function() {
            top.location.href = '/residential-natural-gas-rates';
        });
    },
    '#Pv_Rates': function(element) {
        Application.SetPanelViewBehavior(element, _OnResize);
    },
    '#Media_ServiceAreaMap': function(element) {
        swfobject.embedSWF("flash/serviceAreaViewer.swf", 'Media_ServiceAreaMap', "629", "438", "9.0.0", "flash/expressInstall.swf", null, { wmode: 'transparent' }, null);
    },
    '#Mod_Tip': function(element) {
        if (!Element.hasClassName(element, 'keyTip')) return;
        Event.observe(element, 'click', function() {
            top.location.href = '/natural-gas-energy-saving-tips';
            return;
        });
    },
    '#Media_GasUsers': function(element) {
        swfobject.embedSWF("flash/HomePageHolder.swf", 'Media_GasUsers', "964", "449", "9.0.0", "flash/expressInstall.swf", null, { wmode: 'transparent' }, null);
    },
    'body': function(element) {
        Event.observe($(document), 'click', function(e) {
            $$('.autocomplete').each(function(autocomplete) {
                if (Position.within(autocomplete, e.pointerX(), e.pointerY())) return;
                Element.hide(autocomplete);
            });
        });
    }
};

AppBehavior.NavigateTo = function(section) {
    if (section) section = section.toLowerCase();
    if ($('Pv_Contact')) {
        ContactBehavior.NavigateTo(section);
    }
}
AppBehavior.OnChangeHistory = function(hash) {
    if (hash.length == 0 && Application.CurrentHash) {
        Application.CurrentHash = null;
    }
    if (Application.CurrentHash != hash) {
        var arrItem = hash.split('|');
        //if (arrItem.length < 2) return;
        Application.CurrentHash = hash;
        AppBehavior.NavigateTo(arrItem[0]);
    }
    if (Prototype.Browser.IE) setTimeout(function() { Application.SetTitle(Application.Title); }, 0);
}

AppBehavior.ShowAutocompleter = function(autocompleter) {

    autocompleter.changed = true;
    autocompleter.hasFocus = true;
    if (autocompleter.observer) clearTimeout(autocompleter.observer);
    autocompleter.observer =
		setTimeout(autocompleter.onObserverEvent.bind(autocompleter), autocompleter.options.frequency * 1000);
}

AppBehavior.Load();

