IconView = new ( Class.create({
    
    initialize : function() {},
    
    LoadTo: function(container)
    {
        var thisClass = this;
        
        var pars = null;
        if(IconCategory.SelectedCategory.id == 0)
        {
            pars = { action: 'ShowIconView' };
        }
        else
        {
            pars = { action: 'ShowIconView', currentCategory: IconCategory.SelectedCategory.id };
        }
        
        new Ajax.Updater(
            container,
            'Components/IconView/IconViewActionHandler.php',
            {
                parameters: pars,
                onComplete: function() { thisClass.SetEvents(); thisClass.ResizeContent(); }
            }
        );
    },
    
    SetEvents : function()
    {
        var thisClass = this;
        
        if(Object.isElement($("newIconLink"))) { Event.observe("newIconLink", "click", thisClass.NewIconLinkClicked.bindAsEventListener(thisClass)); }
        
        IconCategory.Generate();
       
        $$('.editButton img').each(
            function(element)
            {
                Event.observe("iconEditButton" + element.alt, "click", thisClass.ModifyIconLinkClicked.bindAsEventListener(thisClass));
            }
        );
        
        $$('.deleteButton img').each(
            function(element)
            {
                Event.observe("iconDeleteButton" + element.alt, "click", thisClass.DeleteIconClicked.bindAsEventListener(thisClass));
            }
        );
        
        Event.observe("newIconButton", "click", thisClass.GetNewIconWindow.bindAsEventListener(thisClass));
        
        $$('.iconButton').each(
            function(element)
            {
                Event.observe(element.id, "click", Icon.IconButtonClicked.bindAsEventListener(Icon));
            }
        );
    },
    
    NewIconLinkClicked : function(event)
    {
        if(IsRoleSuccess()) { Icon.GetNewIconWindow(event); }            
        else { NoRightWindow.Show(event); }
    },
    
    ModifyIconLinkClicked : function(event)
    {
        if(IsRoleSuccess()) { Icon.ModifyIconClicked(event); }
        else { NoRightWindow.Show(event); }
    },
    
    DeleteIconClicked : function(event)
    {
        if(IsRoleSuccess()) { Icon.DeleteIconClicked(event); }
        else { NoRightWindow.Show(event); }
    },
    
    GetNewIconWindow : function(event)
    {
        if(IsRoleSuccess()) { Icon.GetNewIconWindow(event); }
        else { NoRightWindow.Show(event); }
    },
    
    ResizeContent : function()
    {
        var maxWidth = document.viewport.getWidth() - 265;
        //var tabPageWidth = Math.floor(maxWidth / 150) * 150;
        
        var widthString = maxWidth + "px";
        //var tabPageWidthString = tabPageWidth + "px";
        
        $("content").setStyle({width: widthString });
        //$("iconViewTabPage").setStyle({width: tabPageWidthString });
    }
    
}))();
