// SeViR Simple Horizontal Accordion @2007
// http://letmehaveblog.blogspot.com
jQuery.fn.extend({
  haccordion: function(params){
    var jQ = jQuery;
    var params = jQ.extend({
      speed: 500,
      headerclass: "header",
      contentclass: "content",
      contentwidth: ( parseInt( $(this).width() * 0.6 ) ),
	  first_item_closed: false  // added by james beattie - a flag to see if the initially opened item has been closed or not
    },params);
    return this.each(function(){
							  
	  // added by james beattie to make first item open by default
	  $( "div:eq(1)", this ).animate({
          width: params.contentwidth + "px"
        }, params.speed);
	 $( "div.header", this ).click( function(){
			  if ( !params.first_item_closed )
			  {
				  params.first_item_closed = true;
				  $( ".haccordion div:eq(1)" ).animate({
					  width: "0px"
					}, params.speed);
			  }
	  });
	  // end added by james beattie to make first item open by default
	  
      jQ("."+params.headerclass,this).click(function(){	  
        var p = jQ(this).parent()[0];
        if (p.opened != "undefined"){
          jQ(p.opened).next("div."+params.contentclass).animate({
            width: "0px"
          },params.speed);
        }
        p.opened = this;
        jQ(this).next("div."+params.contentclass).animate({
          width: params.contentwidth + "px"
        }, params.speed);
      });
    });
  }
});

