
Site.Pages.Department = Class.create
(
    Site.Page,
    {
        constructor: function($super)
        {
            $super();
        },
        
        domOnLoad: function($super, event)
        {
            $super(event);
            
            //this.addObservers("lotLinkOnClick", "contactLinkOnClick");
            this.addObservers("lotLinkOnClick", "contactLinkOnClick", "trackSpecialistHover", "trackLocationClick", "show_more_info", "hide_more_info");
            
            // setup the lot links widget
            if($('lots-scroller-items')){
                this.lotLinks = $('lots-scroller-items').select("a");
                this.lotListItems = $('lots-scroller-items').select("li");
                this.lotDetailsPanels = $('sidebar').select("div.lot-details");
            
            
                this.lotLinks.each
                (
                    function(link)
                    {
                        addEvent(link, "click", this.observers.lotLinkOnClick); 
                    },
                    this
                );
                
                this.lotDetailsPanels.each
                (
                    function(div)
                    {
                        if (!div.hasClassName("lot-details-active"))
                            div.hide();
                        else
                            this.activeLotDetailsPanel = div;
                    },
                    this
                );
            }
            
            this.contactLinks = $('contact-selector-links').select('#link-specialist-profiles', 'a.trigger');
                       
            this.contactPanels = $('contact-panels').select('div.panel');
            
            
            /*========*/
            this.specialistBios = $('contact-panels').select("a.contact-trigger");
            this.specialistBios.each
            (
                function(link)
                {
                    addEvent(link, "mouseover", this.observers.trackSpecialistHover); 
                },
                this
            );
            /*========*/
            
            
            
            this.contactLinks.each
            (
                function(link)
                {
                    addEvent(link, "click", this.observers.contactLinkOnClick); 
                    addEvent(link, "click", this.observers.trackLocationClick); 
                },
                this
            );
            
            this.contactPanels.each
            (
                function(div)
                {
                    if (!div.hasClassName("panel-active"))
                        div.hide();
                    else
                        this.activeContactPanel = div;
                },
                this
            );
            
            
            this.interestsTooltip = new Site.Widgets.Tooltip
            (
                $('tooltip-save-to-my-interests'),
                $('trigger-save-to-my-interests'), 
                {
                    anchor: "left"
                }
            );
            
          
            
            this.saleTooltipsController = new Site.Controllers.SaleTooltips($("list-sales").select("a.trigger-sale-details"));

			this.addToCalendarController = new Site.Controllers.Tooltips(
				$("list-sales").select("a.trigger-add-to-calendar"),
				{
					offsetX: 0, 
					offsetY: 0,
					showOnClick: true
				}
			);
			
            this.contactTooltipsController = new Site.Controllers.Tooltips
            (
                $('contact-panels').select("a.contact-trigger"),
                {
                    offsetX: 5,
                    offsetY: 0
                }
            );
            
            if($('more_info_div')){
                addEvent($('more_info_link'), "click", this.observers.show_more_info);
                addEvent($('less_info_link'), "click", this.observers.hide_more_info);
            };

            
        },
        
        trackLocationClick: function(event){
            var element = Event.element(event).innerHTML;
            
            if (element != "Specialist Profiles"){
	        var s=s_gi("christiesprod"); 
	        s.linkTrackVars='eVar29,events,prop19,eVar28'; 
	        s.linkTrackEvents='event11';
	        s.eVar29='Department Location';
	        s.prop19=omnituredeptname +' - '+ element;
	        s.eVar28='Location: '+ omnituredeptname +' - '+ element;
	        s.events='event11';
	        s.tl(this,'o','Download');
	        }
        },
        
        trackSpecialistHover: function(event){
            var element = Event.element(event).innerHTML;
            
	        var s=s_gi("christiesprod"); 
	        s.linkTrackVars='eVar29,events,prop18,eVar47'; 
	        s.linkTrackEvents='event11';
	        s.eVar29='Specialist Profile';
	        s.prop18=omnituredeptname +' - '+ element;
	        s.eVar47=s.prop18;
	        s.events='event11';
	        s.tl(this,'o','Download');
        },
        
        
        destroy: function($super)
        {
            this.saleTooltipsController.destroy();
            this.contactTooltipsController.destroy();
            this.interestsTooltip.destroy();
			this.addToCalendarController.destroy();
            
            if($('lots-scroller-items')){
                this.scroller.destroy();
            
                this.lotLinks.each
                (
                    function(link)
                    {
                        removeEvent(link, "click", this.observers.lotLinkOnClick); 
                    },
                    this
                );
            }
            
            
            this.contactLinks.each
            (
                function(link)
                {
                    removeEvent(link, "click", this.observers.contactLinkOnClick); 
                },
                this
            );
            
            $super();
        },
        
        windowOnLoad: function($super, event)
        {
            // calculate the inner Width of the Exceptions prices scroller

            if($('lots-scroller-items')){
            var panelWidth = $('lots-scroller-items').select("li").inject(0, function(acc, item) { return acc + item.offsetWidth + 3 }) - 4;
            
            
                // setup the scroller for the lot link widget
                this.scroller = new Site.Widgets.Scroller
                (
                    $('lots-scroller'),
                    {
                        direction: "horizontal",
                        panelWidth: panelWidth,
                        increment: 260,
                        method: "click",
                        scrollDuration: 0.5
                    }
                ); 
            }
            
        },
        
        contactLinkOnClick: function(event)
        {
            var element = Event.element(event);
            var a = element.matchUp("a");
            
            if (a)
            {
                try
                {
                    var panelId = a.href.split('#')[1];
                }
                catch(e)
                {
                    return;
                }
                
                if (!a.hasClassName("active"))
                {
                    if (this.activeContactPanel) 
                        this.activeContactPanel.hide();
                        
                    this.activeContactPanel = $(panelId);

                    if (this.activeContactPanel)
                        this.activeContactPanel.show();

                    this.contactLinks.invoke("removeClassName", "active");
                    a.addClassName("active");
                }
            
            }
            
            if (element.blur)
                element.blur();
                
            Event.stop(event);
        },
        
        lotLinkOnClick: function(event)
        {
            var element = Event.element(event);
            var a = element.matchUp("a");
            var li = a.up("li");
            
            if (li && a)
            {
                if (!li.hasClassName("active"))
                {
                    if (this.activeLotDetailsPanel)
                        this.activeLotDetailsPanel.hide();
                        
                    this.activeLotDetailsPanel = $(a.id.replace("link", "details"));
                    
                    if (this.activeLotDetailsPanel)
                        this.activeLotDetailsPanel.show();
                
                    this.lotListItems.invoke("removeClassName", "active");
                    li.addClassName("active");
                }
            
            }
            
            if (element.blur)
                element.blur();
            
            
            Event.stop(event);
        },
        
        show_more_info: function(event)
        {
            //alert('test');
            var element = Event.element(event).id;
            $('more_info_div').show();   
            //$('ellipsis').hide();
            $('more_info_link').hide();     
            Event.stop(event);   
        },
         
        hide_more_info: function(event)
        {
            //alert('test');
            var element = Event.element(event).id;
            element = element.sub('_close', '');
            $('more_info_div').hide();   
            //$('ellipsis').show();
            $('more_info_link').show(); 
            Event.stop(event);
        }
        
        
        
    }
);


