var Inventome = {
    AjaxArticleLinks : null,
    AjaxLinks : null,
    CurrentSection : null,
    ToolTipsArticle : null,
    ToolTips : null,
    pmfx : null,
    amfx : null,
    cnfx : null,
    
    
    switchSection : function(thissection)
    {

        //switching to this menu, cm holds the current menu
        if(Inventome.CurrentSection!=thissection)
        {
            var movecontent=false;
            //we need to hide the menu if there is one out already
            switch(Inventome.CurrentSection)
            {
                case "about":       Inventome.amfx.start(202,50);
                                    movecontent=true;
                                    break;
                case "production":  Inventome.pmfx.start(202,50);
                                    movecontent=true;
                                    break;
            }
            if(Inventome.CurrentSection!=null) $(Inventome.CurrentSection+"_link").removeClass("selected");  //need to add the link suffix
            //now open the new one
            switch(thissection)
            {
                case "about":       Inventome.amfx.start(50,202);
                                    if(!movecontent) Inventome.cnfx.start(300,400);
                                    movecontent=false;
                                    break;
                case "production":  Inventome.pmfx.start(50,202);
                                    if(!movecontent) Inventome.cnfx.start(300,400);
                                    movecontent=false;
                                    break;
            }
            if(movecontent) Inventome.cnfx.start(400,300);
            $(thissection+"_link").addClass("selected");                //switch to new one
            Inventome.CurrentSection=thissection;
        }
    },
   
    ajaxClick : function(e)
    {
        e = new Event(e).stop();
        //need to check that the correct menu (category) is active
        if(this.href.contains("s="))
        {
            //there's a section part to it so we extract that and make sure the menu and section css is correct
            var startpos = this.href.indexOf("s=");
            var endpos = this.href.indexOf("&",startpos);
            if(endpos==-1) endpos = this.href.length;
            var thissection = this.href.substring(startpos+2,endpos).toLowerCase();
            Inventome.switchSection(thissection); //it's probably correct already but just to make sure
        }
        //switch the data
        new Ajax(this.href.replace("default.aspx","ajax.aspx"), {  method: 'get', update: $('content'), onComplete: Inventome.prepAjax }).request();
    },
    
    prepAjax : function(response)
    {
        //add the new article links into the fray
        Inventome.AjaxArticleLinks = $$('.artajax');
	    Inventome.AjaxArticleLinks.each(
            function(el, i)
            {
                //remove the events (only the artajax links, not all of them)
                el.removeEvents("click");
                //add new events
                el.addEvent("click", Inventome.ajaxClick);
            }
        );
        //add new tooltips
        Inventome.ToolTipsArticle = new Tips($$('.arttip'), {  fixed: false, offsets : {x:-75,y:-120}, showDelay : 0, hideDelay : 0 });
        //lightbox
        Lightbox.scandocument();
    },
    
    init : function()
    {
        Inventome.pmfx = new Fx.Style($('production_submenu'), 'left', {duration: 300,transition: Fx.Transitions.Quad.easeOut});
        Inventome.amfx = new Fx.Style($('about_submenu'), 'left', {duration: 300,transition: Fx.Transitions.Quad.easeOut});
        Inventome.cnfx = new Fx.Style($('content'), 'padding-left', {duration: 300,transition: Fx.Transitions.Quad.easeOut});
        //framework tips
        Inventome.ToolTips = new Tips($$('.tip'), {  fixed: false, offsets : {x:-75,y:-120}, showDelay : 0, hideDelay : 0 });
        //framework ajax
        Inventome.AjaxLinks = $$('.ajax');
	    Inventome.AjaxLinks.each( function(el, i) { el.addEvent("click", Inventome.ajaxClick); } );
	    //add the article specific links and tooltips if needed
	    Inventome.prepAjax("");
        
    }

    
}


window.addEvent('domready', function()
{

	var menuoptions = $$('#mainmenu a');
	menuoptions.each(
        function(el, i)
        {
            el.addEvent("mouseenter",
                function(event)
                {
                    el.effect('font-size',{duration: 100,transition: Fx.Transitions.Bounce.easeOut}).start(16,24);
                    el.effect('color',{duration: 250,transition: Fx.Transitions.Quad.easeOut}).start('#917a5d','#e79631');
                }
            );
            el.addEvent("mouseleave",
                function(event)
                {
                    el.effect('color',{duration: 500,transition: Fx.Transitions.Quad.easeOut}).start('#e79631','#917a5d');
        	        el.effect('font-size',{duration: 100,transition: Fx.Transitions.Quad.easeOut}).start(24,16);
                }
            );
            el.addEvent("click",
                function(e)
                {   
                    //section name
                    var sectionname = el.id.replace("_link","");
                    if(sectionname!=Inventome.CurrentSection) Inventome.switchSection(sectionname) //if there's no link then the menus will go
                    //e = new Event(e).stop();
                }
            );
        }
    );

    //ajaxify the links, anything with an ajax class gets turned into this
    Inventome.init();
    Inventome.CurrentSection = "home";
});



