window.addEvent('domready', function()
{
    myAccordion = new Accordion('div.toggler', 'div.element',
    {
	    opacity: false,
	    height: false,
	    width: true,
	    fixedWidth: 530
    });
});

window.addEvent('domready', function()
{
    var totInc = new Array();
    var item_lists = new Array;
    var increment = 300;
    var dur = 800;
    var fxs = new Array();
    var lists = $$(".list_items");
    
    lists.each(function(item, index)
	{
	    var id = item.getProperty("id");
	    item_lists[index] = item;
	    totInc[index] = 0;
	    fxs[index] = new Fx.Tween(id, { duration: dur, transition: Fx.Transitions.Back.easeInOut, wait: true });
	    pbutton_id = 'previous_' + id;
	    $(pbutton_id).addEvents({'click' : function()
		{
		    totInc[index] = totInc[index] + increment;
		    fxs[index].pause();
		    if (totInc[index] <= 0)
		    {
			fxs[index].start('margin-left', totInc[index]);
		    }
		    else totInc[index] = totInc[index] - increment;
		}
	    });
	    nbutton_id = 'next_' + id;
	    $(nbutton_id).addEvents({'click' : function()
		{
		    totInc[index] = totInc[index] - increment;
		    fxs[index].pause();

		    /*max = item_lists[index].getStyle("width");
		    max = max.replace("px", "");
		    max = max - 600;*/
		    var max = -870;
		    var lists_li = $$("#"+id+" li");
		    lists_li.each(function(item)
		    {
			t = item.getStyle("width");
			t = parseInt(t.replace("px", "")) + 30;
			max = max + t;
		    });
		    max = max - 30;
		    temp_compare = totInc[index];
		    testcheck = temp_compare + max;
		    //alert(max + "(max) " + " + " + temp_compare + "(temp_compare)" + " = " + testcheck);
		    if (testcheck >= 0)
		    {
			fxs[index].start('margin-left', totInc[index]);
		    }
		    else totInc[index] = totInc[index] + increment;
		}
	    });
	}
    );
});
