Blog = function(){
    var layout, center, morePanel, moreView, cpanel, swapping = false;
    return {
        init : function(){
           YAHOO.ext.state.Manager.setProvider(new YAHOO.ext.state.CookieProvider());
           YAHOO.ext.QuickTips.init();
           
           var hd = getEl('header');
           layout = new YAHOO.ext.BorderLayout(document.body, {
                north: {
                    split:false,
                    initialSize: 65,
                    margins:{left:10,right:10,top:0,bottom:0}
                },
                center: {
                    autoScroll: false,
                    margins:{left:10,right:10,top:0,bottom:10},
                    // safari crashes when moving the blog body with adsense
                    // nice job google.
                    lightweight:true
                }
            });
            layout.beginUpdate();
            layout.add('north', new YAHOO.ext.ContentPanel('header-left', 
                            {fitToFrame:true, adjustments:[-6, 0], resizeEl:'header'}));
                
            center = layout.getRegion('center');
            if(isPost){
                cpanel = center.add(new YAHOO.ext.ContentPanel('content-panel', {fitToFrame:true}));
                cpanel.el.show();
                var moreEntries = getEl('more-entries');
                moreEntries.addHandler('click', true, this.showEntries, this, true);
                setTimeout(function(){
                    var pv = getEl('page-views');
                    if(pv){
                        pv.load({
                            url:'/blog/log_view.php',
                            params: {log: 'true', postId: pv.dom.getAttribute('postId')},
                            text: 'Logging view...'
                        });
                    }
                    Commentable.init();
                    try{
                        urchinTracker();
                    }catch(e){}
                }, 250);
            }else{
                this.showEntries();
            }
            layout.endUpdate();
            Download.init();
            
            var sf = getEl('search-form');
            if(sf){
                sf.swallowEvent('submit', true);
                var searchQ = getEl('search-q');
                searchQ.on('focus', function(){
                    if(this.dom.value == 'Quick Search'){
                        this.dom.value = '';
                    }
                });
                searchQ.on('blur', function(){
                    if(this.dom.value == ''){
                        this.dom.value = 'Quick Search';
                    }
                });
                searchQ.addKeyListener([13,10], function(){
                    YAHOO.util.Connect.setForm(sf.dom);
                    moreView.load({url:'/blog/get-posts.php', 
                        text:'Searching Blog Entries...'});
                });
            }
       },
       
       hideEntries : function(){
           //center.titleEl.hide();
           center.showPanel(0);
           layout.layout();
       },
       
       swapPanels : function(){
           swapping = true;
           getEl('more-entries').update('<div style="position:relative;width:18px;">&nbsp;<div class="loading-indicator" style="width:16px;height:16px;position:absolute;left:-3px;top:-5px;"></div></div>')
           var active = center.getActivePanel();
           var b = center.box;
           var x, x2, text, moveIn;
           if(active.getId() == 'content-panel'){
               moveIn = morePanel;
               text = 'HIDE BLOG ENTRIES';
               x = -b.width;
               x2 = YAHOO.util.Dom.getViewportWidth()+10;
           }else{
               moveIn = cpanel;
               text = 'MORE BLOG ENTRIES';
               x = YAHOO.util.Dom.getViewportWidth();
               x2 = -(b.width+10);
           }
           var activeEl = active.getEl();
           var moveEl = moveIn.getEl();
           activeEl.setStyle('z-index',99);
           moveEl.setStyle('z-index',100);
           moveEl.removeClass('ylayout-inactive-content');
           moveEl.setSize(b.width, b.height);
           moveEl.setXY([x, b.y]);
           activeEl.setXY([x2, b.y], true, .5, null, YAHOO.util.Easing.easeOutStrong);
           moveEl.setBox(b, false, true, .5, function(){
                center.add(moveIn);
                swapping = false;
                getEl('more-entries').update(text);
                getEl('more-entries').highlight('3E72BC', {endColor:'1D3B71', duration:1});
                    
           }, YAHOO.util.Easing.easeOutStrong);
       },
       
       sortEntries : function(){
           if(moreView.jsonData){
               var p = getEl('more-sort').dom.value;
               YAHOO.ext.state.Manager.set('esort', p);
               moreView.jsonData.sort(function(v1, v2){
                   return v2[p] - v1[p];
               });
               moreView.refresh();
           }
       },
       
       swapTemplate : function(){
           var v = getEl('more-desc').dom.checked;
           YAHOO.ext.state.Manager.set('edesc', v);
           moreView.tpl = v ? moreView.longTpl : moreView.shortTpl;
           moreView.refresh();
       },
       
       afterLoad : function(){
           var o = moreView.jsonData;
           if(!o || o.length < 1){
               moreView.el.update('<div style="margin:15px;">Your search did not produce any results. Try using exact matches with quotes (i.e. "YAHOO.ext.Element") or boolean operators (i.e. +grid +autoHeight -foo).</div>');
           }  
       },
       
       showEntries : function(){
           if(swapping){
               return;
           }
           if(!morePanel){
               morePanel = new YAHOO.ext.ContentPanel('more-panel', {
                    fitToFrame:true, 
                    title: 'Blog Entries', 
                    closable:true,
                    preserve:true,
                    autoScroll:true
               });
               
               morePanel.el.show();
               
               var excerptPref = YAHOO.ext.state.Manager.get('edesc');
               getEl('more-desc').dom.checked = excerptPref !== false;
               
               var tpl = new YAHOO.ext.Template(
                    '<div class="entry">' + 
                        '<a class="entry-title" href="{link}">{title}</a><h4>{date} by {author} | {comments} Comments</h4>{description}' +
                    '</div><hr />'
               );
               tpl.compile();
               
               var shortTpl = new YAHOO.ext.Template(
                    '<div class="entry">' + 
                        '<a class="entry-title" href="{link}">{title}</a><h4>{date} by {author} | {comments} Comments</h4>' +
                    '</div><hr />'
               );
               shortTpl.compile();
               
               moreView = new YAHOO.ext.JsonView('entry-list', excerptPref !== false ? tpl : shortTpl, {
                   jsonRoot: 'posts'
               });
               moreView.longTpl = tpl;
               moreView.shortTpl = shortTpl;
               moreView.on('beforerender', this.sortEntries, this, true);
               moreView.el.getUpdateManager().on('update', this.afterLoad, this, true);
               moreView.load({url:'/blog/get-posts.php', params: 'allposts=true',
                        text:'Loading Blog Entries...'});
                        
               var sortPref = YAHOO.ext.state.Manager.get('esort');
               if(sortPref){
                   getEl('more-sort').dom.value = sortPref;
               }
               getEl('more-sort').on('change', this.sortEntries, this, true);
               getEl('more-desc').on('click', this.swapTemplate, this, true);
           }
           if(isPost){
               this.swapPanels();
           }else{
               center.add(morePanel);
           }
       } 
    }
}();
YAHOO.ext.EventManager.onDocumentReady(Blog.init, Blog, true);

/*
 * Legacy code for old examples
 */
var Dom = YAHOO.util.Dom;
var Event = YAHOO.util.Event;


// example code
function doExample1(){
    var el = getEl('example1');
    el.toggle(/*fade*/true);
}

function doExample2(){
    var el = getEl('example2');
    el.setBounds(0, el.getY(), 0, 0, true, .2, seeYaButton);
}
function seeYaButton(){
    var btn = getEl('button2');
    btn.enableDisplayMode();
    btn.setVisible(false, true);
}

function doExample3(){
    var blog = getEl('blogBody');
    var distance = Dom.getViewportHeight();
    blog.setLocation(blog.getX(), blog.getY()-distance, true, 
        .75, rollup, YAHOO.util.Easing.backIn);
}

function rollup(){
    var blog = getEl('blogBody');
    var distance = Dom.getViewportHeight();
    blog.setLocation(blog.getX(), blog.getY()+(distance*2));
    blog.setLocation(blog.getX(), blog.getY()-distance, true, 
        .75, null, YAHOO.util.Easing.backOut);
}

function doExampleLink(){
    try{
        var e = Event.getEvent();
        if(e){
            Event.stopEvent(e);
        }
        var link = Event.getTarget(e);
        showExample(link.href);
    }catch(e){} // if error occurs, standard link should work
}

function showExample(url, width, height){
    var exframe = getEl('exframe');
    exframe.dom.src = url;
    var exdiv = new YAHOO.ext.Actor('example', null, true);
    exdiv.moveIn('top');
    exdiv.play();
}

function hideExample(){
    var exdiv = new YAHOO.ext.Actor('example', null, true);
    exdiv.moveOut('top');
    exdiv.play(clearExample);
}

function clearExample(){
    getEl('exframe').dom.src = 'about:blank';
}
/**
 * Copyright 2006 Jack Slocum
 * Want to use this code on your site? Of course you can!
 * This code, like all code on http://www.jackslocum.com/ is
 * free to modify and distribute as you wish.
 * http://www.opensource.org/licenses/bsd-license.php
 */

if(isPost){
    Commentable = function(){
        /* private variables */
        var cb, blocks, tpl, cn, tabs, wait, list, vlist, error, submit, postBtn;
        var cmResize, viewResize;
        var posting = false;
        var currentIndex, lastIndex;
        
        /* private functions */
        var isOnCommentBar = function(e){
            var eventX = e.getPageX();
            var x = cb.getX();
            return(eventX >= x && eventX <= (x+20));
        };
        
        var setActiveIndex = function(index){
            index = index || 0;
            if(typeof currentIndex != 'undefined'){
                YAHOO.util.Dom.removeClass(blocks[currentIndex].el, 'active-content');
            }
            currentIndex = index;
            YAHOO.util.Dom.addClass(blocks[currentIndex].el, 'active-content');
        };
        
        var onClick = function(e){
            if(isOnCommentBar(e)){
                var p = e.findTarget('content', 'div');
                if(p){
                    e.stopEvent();
                    setActiveIndex(p.contentIndex);
                    Commentable.addComment();
                }
            }
        };
        
        var cancelSelection = function(e){
            if(isOnCommentBar(e)){
                e.preventDefault();
            }
        };
        
        var afterSuccess = function(el){
            blocks[currentIndex].addComment(el);
        }
        
        var commentSuccess = function(o){
            posting = false;
            var text = o.responseText;
            // if we got a comment block back
            if(text.substr(0, 3) == '<li'){
                var el = YAHOO.ext.DomHelper.insertHtml('beforeEnd', list.dom, text);
                wait.removeClass('active-msg');
                cn.hide(afterSuccess.createCallback(el));
            }else{
                getEl('post-error-msg').update(text);
                error.radioClass('active-msg');
            }
        };
        
        var commentFailure = function(o){
            posting = false;
            var msg = getEl('post-error-msg');
            msg.update('Error: Unable to connect.');
            error.radioClass('active-msg');
        };
        
        var loadComments = function(index){
            if(blocks){
                block = blocks[index];
                vlist.innerHTML = '';
                for(var i = 0, len = block.count; i < len; i++){
                    vlist.appendChild(block.comments[i].cloneNode(true));
                }
                vlist.parentNode.scrollTop = 0;
                tabs.getTab('cview-tab').setText('Block Comments ('+block.count+')');
            }
        };
        
        var listClick = function(e){
            var t = e.findTarget('csel');
            if(t){
                var index = t.getAttribute('contentIndex');
                setActiveIndex(index);
                Commentable.scrollIntoView(document.getElementById('content'), blocks[currentIndex].el);
                loadComments(currentIndex);
            }
        };
        
        /* public functions */
        return {
            init : function(){
                wait = getEl('posting-wait');
                error = getEl('post-error');
                submit = getEl('comment-submit');
                
                vlist = document.getElementById('comment-view-list');
                
                cb = getEl('content');
                cb.mon('click', onClick);
                cb.mon('mousedown', cancelSelection);
                cb.mon('selectstart', cancelSelection);
                
                // 11/26 removed yui getElementsByClassName because it was super slow
                blocks = [];
                var paras = cb.dom.getElementsByTagName('div');
                var bindex = -1;
                for(var i = 0, len = paras.length; i < len; i++){
                    if(paras[i].className == 'content' || paras[i].className == 'content content-title'){
                        blocks[++bindex] = new CBlock(paras[i], bindex);
                    }
                }
                
                list = getEl('comment-items');
                list.mon('click', listClick);
                var items = list.dom.getElementsByTagName('li');
                for(var i = 0, len = items.length; i < len; i++){
    				var block = blocks[items[i].getAttribute('contentIndex')];
                    if(block){
    					block.addComment(items[i]);
    				}
                }
                this.initCn.defer(100, this);       
            },
            
            isOpen : function(){
                return cn && cn.isVisible();    
            },
            
            addComment : function(){
                var block = blocks[currentIndex || 0];
                this.showComments(block, 'cform-tab');
            },
            
            addGeneralComment : function(){
                if(!blocks) return; // still initializing
                setActiveIndex(0);
                this.addComment();  
            },
            
            showHelp : function(){
                if(!blocks) return; // still initializing
                setActiveIndex(0);
                this.showComments(blocks[0], 'chelp-tab'); 
            },
            
            submitComment : function(){
                if(posting) return;
                var f = document.getElementById('commentform');
                wait.radioClass('active-msg');          
                YAHOO.util.Connect.setForm(f);
                posting = true;
                YAHOO.util.Connect.asyncRequest('POST', '/blog/wp-comments-post.php', 
                        {success: commentSuccess, failure: commentFailure});          
            },
            
            closeComment : function(){
                wait.removeClass('active-msg');
                error.removeClass('active-msg');
                cn.hide();
            },
            
            showAllComments : function(){
                if(!blocks)return; // still initializing
                setActiveIndex(0);
                this.showComments(blocks[0], 'call-tab');  
            },
            
            commentMarkClick : function(block){
                if(block.index == currentIndex && cn.isVisible()){
                    this.closeComment();
                }else{
                    this.showComments(block);
                } 
            },
            
            initCn : function(){
                if(!cn){
                    cn = new YAHOO.ext.BasicDialog("comment-cn", { 
                            width:600,
                            height:450,
                            shadow:true,
                            minWidth:500,
                            minHeight:350,
                            autoTabs:true,
                            autoScroll:false,
                            tabTag: 'dt',
                            proxyDrag:true,
                            shim:true
                    });
                    // override the proxy anims to animate the the comment bar
                    cn.animShow = function(){
                        var xy = getEl(this.animateTarget).getXY();
                        this.proxy.setSize(20, 20);
                        this.proxy.setXY(xy);
                        this.proxy.show();
                        this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height, 
                                        true, .35, this.showEl.createDelegate(this));
                    };
                    cn.animHide = function(callback){
                        var xy = getEl(this.animateTarget).getXY();
                        this.proxy.show();
                        this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
                        this.el.hide();
                        this.proxy.setBounds(xy[0], xy[1], 20, 20, true, .35, 
                                    this.hideEl.createDelegate(this, [callback]));
                    }
                    cn.on('hide', function(){
                        var block = blocks[currentIndex];
                        if(block){
                         YAHOO.util.Dom.removeClass(block.el, 'active-content');
                        }
                    });
                    var cmt = getEl('comment');
                    cn.on('resize', function(bd, w, h){
                        cmt.setSize(w-50,h-260);
                    });
                    cn.restoreState();
                    cmt.setSize(cn.size.width-50, cn.size.height-260);
                    tabs = cn.getTabs();
                    cn.addKeyListener(27, cn.hide, cn);
                    cn.setDefaultButton(cn.addButton('Close', cn.hide, cn));
                    postBtn = cn.addButton('Post It!', this.submitComment, this);
                    tabs.on('tabchange', function(tp, tab){
                        postBtn.el.setStyle('visibility', tab.id == 'cform-tab' ? 'visible' : 'hidden');
                    });
                }
            },
            
            showComments : function(block, tab){
                setActiveIndex(block.index);
                this.initCn();
                tabs.activate(tab || 'cview-tab');
                tabs.getTab('call-tab').setText('All Comments ('+list.dom.childNodes.length+')');
                var f = document.getElementById('commentform');
                f.elements['contentIndex'].value = currentIndex;
                f.elements['comment'].value = '';
                loadComments(block.index);
                list.dom.parentNode.scrollTop = 0;
                cn.show(block.el);
            },
            
            scrollIntoView : function(container, child){
                var childTop = parseInt(child.offsetTop, 10);
                var childBottom = childTop + child.offsetHeight;
                var containerTop = parseInt(container.scrollTop, 10); // parseInt for safari bug
                var containerBottom = containerTop + container.clientHeight;
                if(childTop < containerTop){
                	container.scrollTop = childTop;
                }else if(childBottom > containerBottom){
                    container.scrollTop = childBottom-container.clientHeight;
                }
            }
        };
    }();
    
    
    CBlock = function(el, index){
        this.el = el;
        el.contentIndex = index;
        this.index = index;
        this.count = 0;
    };
    
    CBlock.prototype = {
        addComment : function(commentItem){
            if(!this.comments){
                this.comments = [];
            }
            this.comments.push(commentItem);
            this.count++;
            this.updateMark();
        },
        
        updateMark : function(){
            if(this.mark == null){
                this.mark = getEl(YAHOO.ext.DomHelper.append(this.el, 
                    {tag : 'span', cls: 'comment-mark', id: 'mark-' + this.index, contentIndex: this.index, children: [
                        {tag : 'span', cls: 'comment-mark-text'}
                    ]}));
                this.mark.mon('click', this.onClick, this, true);
            }
            this.mark.dom.firstChild.innerHTML = this.count;
            this.mark.dom.title = this.count == 1 ? '1 comment' : this.count + ' comments';
        },
        
        getXY : function(){
            return YAHOO.util.Dom.getXY(this.el);
        },
        
        onClick : function(e){
            e.stopEvent();
            this.mark.setOpacity(.5);
            Commentable.commentMarkClick(this);
        }
    };
}
var Download = function(){
    // private vars
    var dialog, showBtn, lookup = {};
    var detailTpl, dlBtn, dlInfo;
    
    // private functions
    var buildRequires = function(file, o){
        if(file.requires){
            for(var i = 0, len = file.requires.length; i < len; i++){
                var f = file.requires[i];
                o[f] = lookup[f];
                buildRequires(lookup[f], o);
            }
        }
    };
    
    var formatSize = function(size){
        if(size < 1024) {
            return size + " bytes";
        } else {
            return (Math.round(((size*10) / 1024))/10) + " KB";
        }
    };
    
    var updateSize = function(){
        var size = 0;
        for(var key in lookup){
            if(lookup[key].cb.checked) size += lookup[key].size;
        }
        dlInfo.update(formatSize(size));
    };
    
    // public functions
    return {
        init : function(){
            showBtn = getEl('downloads-link');
            showBtn.addHandler('click', true, this.showDialog, this, true);
            dlInfo = getEl('dl-info');
            
        },
        
        getDownload : function(){
            getEl('file-form').dom.submit(); 
        },
        
        showDialog : function(){
			alert('Download of yui-ext .33 has been discontinued. Ext 1.0 will be available very soon. You can download a pre-release from the Ext 1.0 discussion forum.');
			window.location = 'http://www.yui-ext.com/forum/viewforum.php?f=8';
			return;
            if(!dialog){
                dialog = new YAHOO.ext.LayoutDialog("download-dlg", { 
                        modal: true,
                        shim:true,
                        width:600,
                        height:450,
                        shadow:true,
                        minWidth:500,
                        minHeight:350,
                        autoTabs:true,
                        autoScroll:false,
                        center:{
                            tabPosition: 'top',
	                        alwaysShowTabs: true
                        },
                        proxyDrag:true
                });
                dialog.addKeyListener(27, dialog.hide, dialog);
                dialog.setDefaultButton(dialog.addButton('Close', dialog.hide, dialog));
                dlBtn = dialog.addButton('Build It!', this.getDownload, this);
                var innerLayout = new YAHOO.ext.BorderLayout('dl-inner', {
                    east: {
                        initialSize: 200,
                        autoScroll:true,
                        split:false
                    },
                    center: {
                        autoScroll:true
                    }
                });
                innerLayout.beginUpdate();
                innerLayout.add('east', new YAHOO.ext.ContentPanel('dl-details'));
                innerLayout.add('center', new YAHOO.ext.ContentPanel('selection-panel'));
	            innerLayout.endUpdate(true);
	            
                var layout = dialog.getLayout();
                dialog.beginUpdate();
                var sp = layout.add('center', new YAHOO.ext.ContentPanel('standard-panel', 
                                    {title: 'Download the Source', fitToFrame:true}));
	            sp.on('activate', function(){
	                dlBtn.getEl().setStyle('display', 'none');
	                dlInfo.hide();
	            });
	            var p = layout.add('center', new YAHOO.ext.NestedLayoutPanel(innerLayout, 
	                       {title: 'Build your own yui-ext.js'}));
	            p.on('activate', function(){
	                dlBtn.getEl().setStyle('display', '');
	                dlInfo.show();
	                if(!detailTpl){
	                    this.render();
	                }
	            }, this, true);
	            layout.getRegion('center').showPanel(sp);
	            dialog.endUpdate();
            }
            if(typeof Commentable != 'undefined' && Commentable.isOpen()){
                Commentable.closeComment();
                this.showDialog.defer(200, this);
                return;
            }
            dialog.show(showBtn.dom);
        },
        
        showDetails : function(){
            //if(!this.details){
                var l = '<ul class="dl-req-list"><li>YAHOO.ext Core</li>';
                var rq = {};
                buildRequires(this, rq);
                for(var name in rq) {
                    var cls = lookup[name].cb.checked ? 'dl-req-ok' : 'dl-req-missing';
                	l += '<li class="'+cls+'">' + rq[name].name + "</li>";
                }
                l += "</ul>";
                this.depends = l;
                var fl = "<ul>";
                if(this.file instanceof Array){
                    for(var i = 0; i < this.file.length; i++) {
                    	fl += "<li>" + this.file[i] + "</li>";
                    }
                }else{
                    fl += "<li>" + this.file + "</li>";
                }
                fl += "</ul>";
                this.fileList = fl;
                this.details = detailTpl.applyTemplate(this);
            //}
            var info = getEl('dl-details');
            info.update(this.details);
        },
        
        // render everything from the JSON response -> DomHelper is so fast!
        render : function(){
            var um = getEl('selection-panel').getUpdateManager();
            um.setRenderer({
                render : function(el, o){
                    var data = YAHOO.ext.util.JSON.decode(o.responseText);
                    el.update('');
                    var hdt = new YAHOO.ext.Template('<div class="dl-group-hd">{0}<div class="dl-expand-icon"></div></div>')
                    hdt.compile();
                    var bdt = new YAHOO.ext.Template('<div class="dl-group-bd"></div>');
                    bdt.compile();
                    var itemTpl = new YAHOO.ext.Template(
                        '<div class="dl-group-child"><div class="dl-selection">' +
                        '<input type="checkbox" id="file-{id}" name="files[]" value="{id}" />' +
                        '<span>&nbsp;{name}</span><br /><div>{desc}</div>' +
                        '</div></div>'
                    );
                    itemTpl.compile();
                    detailTpl = new YAHOO.ext.Template(
                        '<ul>' +
                        '<li class="detail-part"><h3>{name}</h3><span>{desc}</span></li>' +
                        '<li class="detail-part"><h3>Size</h3><span>{formatSize}</span></li>' +
                        '<li class="detail-part"><h3>Dependencies</h3><div>{depends}</div></li>' +
                        '<li class="detail-part"><h3>Files</h3><div>{fileList}</div></li></ul>'
                    );
                    detailTpl.compile();
                    var cbTpl = new YAHOO.ext.Template();
                    for(var g in data){
                        var group = data[g];
                        var hd = hdt.append(el.dom, [g], true);
                        hd.dom.title = group.desc;
                        var bd = bdt.append(el.dom, [], true);
                        new Collapser(hd, bd);
                        for(var i = 0, len = group.files.length; i < len; i++) {
                        	var f = group.files[i];
                        	f.formatSize = formatSize(f.size);
                        	f.group = g;
                        	lookup[f.id] = f;
                        	var item = itemTpl.append(bd.dom, f, true);
                        	if((i+1) % 2 == 0) item.addClass('dl-selection-alt');
                        	var cb = item.dom.firstChild.firstChild;
                        	f.cb = cb;
                        	cb.checked = (g == 'YAHOO.ext Core');
                        	cb.disabled = (g == 'YAHOO.ext Core');
                        	item.mon('click', function(e){
                        	    if(e.getTarget() != this.cb && !this.cb.disabled){
                        	       this.cb.checked = !this.cb.checked;
                        	    }
                        	    updateSize();
                        	}, f, true);
                        	item.on('mouseover', Download.showDetails, f, true);
                        	item.addClassOnOver('dl-selection-over');
                        }
                    }
                    updateSize();
                }
            });
            um.update('/build/download-compile.php', 'foo=bar');
        }
    };
}();

var Collapser = function(clickEl, collapseEl){
    this.clickEl = getEl(clickEl);
    this.collapseEl = getEl(collapseEl);
    this.clickEl.addClass('collapser-expanded');
    this.clickEl.mon('click', function(){
        this.collapsed === true ? 
            this.expand() : this.collapse();
    }, this, true);
};

Collapser.prototype = {
    collapse : function(){
        this.collapseEl.clip();
        this.collapseEl.setHeight(1, true, .35, this.afterCollapse.createDelegate(this), YAHOO.util.Easing.easeOut);
    },
    
    afterCollapse : function(){
        this.collapsed = true;
        this.collapseEl.setDisplayed(false);
        this.clickEl.replaceClass('collapser-expanded','collapser-collapsed');
    },
    
    expand : function(){
        this.collapseEl.setDisplayed(true);
        this.collapseEl.autoHeight(true, .35, this.afterExpand.createDelegate(this), YAHOO.util.Easing.easeOut);
    },
    
    afterExpand : function(){
        this.collapsed = false;
        this.collapseEl.unclip();
        this.collapseEl.setStyle('height', '');   
        this.clickEl.replaceClass('collapser-collapsed','collapser-expanded');
    }
};
