var InventomeArt = {
    AjaxArticleLinks : null,
    AjaxLinks : null,
    CurrentSection : null,
    ToolTipsArticle : null,
    ToolTips : null,
    christosfx : null,
    amfx : null,
    cnfx : null,
    
    
    switchSection : function(thissection)
    {

        //switching to this menu, cm holds the current menu
        if(InventomeArt.CurrentSection!=thissection)
        {
            var movecontent=false;
            //we need to hide the menu if there is one out already
            switch(InventomeArt.CurrentSection)
            {
                case "christos":    InventomeArt.christosfx.start(58,-48);
                                    movecontent=true;
                                    break;
            }
            if(InventomeArt.CurrentSection!=null) $(InventomeArt.CurrentSection+"_link").removeClass("selected");  //need to add the link suffix
            //now open the new one
            switch(thissection)
            {
                case "christos":    InventomeArt.christosfx.start(-48,58);
                                    //if(!movecontent) InventomeArt.cnfx.start(300,400);
                                    movecontent=false;
                                    break;
            }
            //if(movecontent) InventomeArt.cnfx.start(400,300);
            $(thissection+"_link").addClass("selected");                //switch to new one
            InventomeArt.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();
            InventomeArt.switchSection(thissection); //it's probably correct already but just to make sure
        }
        //switch the data
        new Ajax(this.href.replace("art.aspx","artajax.aspx"), {  method: 'get', update: $('content'), onComplete: InventomeArt.prepAjax }).request();
    
    },
    
    prepAjax : function(response)
    {
    
        //add the new article links into the fray
        InventomeArt.AjaxArticleLinks = $$('.artajax');
	    InventomeArt.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", InventomeArt.ajaxClick);
            }
        );
       
        
        //add new tooltips
        InventomeArt.ToolTipsArticle = new Tips($$('.arttip'), {  fixed: false, offsets : {x:-90,y:8}, showDelay : 0, hideDelay : 0 });
    },
    
    init : function()
    {
        InventomeArt.christosfx = new Fx.Style($('christos_submenu'), 'top', {duration: 300,transition: Fx.Transitions.Quad.easeOut});
        //InventomeArt.amfx = new Fx.Style($('about_submenu'), 'left', {duration: 300,transition: Fx.Transitions.Quad.easeOut});
        //InventomeArt.cnfx = new Fx.Style($('content'), 'padding-left', {duration: 300,transition: Fx.Transitions.Quad.easeOut});
        //framework tips
        InventomeArt.ToolTips = new Tips($$('.tip'), {  fixed: false, offsets : {x:-90,y:8}, showDelay : 0, hideDelay : 0 });
        //framework ajax
        InventomeArt.AjaxLinks = $$('.ajax');
	    InventomeArt.AjaxLinks.each( function(el, i) { el.addEvent("click", InventomeArt.ajaxClick); } );
	    //add the article specific links and tooltips if needed
	    InventomeArt.prepAjax("");
        
    }

    
}


window.addEvent('domready', function()
{

	var menuoptions = $$('#mainmenu a');
	menuoptions.each(
        function(el, i)
        {
            el.addEvent("mouseenter",
                function(event)
                {
                    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.addEvent("click",
                function(e)
                {   
                    //section name
                    var sectionname = el.id.replace("_link","");
                    if(sectionname!=InventomeArt.CurrentSection) InventomeArt.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
    InventomeArt.init();
    InventomeArt.CurrentSection = "welcome";
});



