/* Po kazdorazowej zmienie kolejnosci elementow w lisci #id_articles_list przesyla
   ich zserializowana nowa kolejnosc pod adres "adres_biezacej_strony+'reorder_albums'"
 */
Event.observe(window, 'load', function() {
	var articles_list = $('id_articles_list')
	if (articles_list.hasClassName('sortable')) {
		if (document.all && !window.opera) { // obejscie 'hover' dla IE
			articles_list.select('li').each(function(el) {
				el.observe('mouseover', function() {this.addClassName('hover')})
				el.observe('mouseout', function() {this.removeClassName('hover')})
			})
		}
		Sortable.create(articles_list, {hoverclass: 'hover_under', onUpdate: function(el) {
			new Ajax.Request(location.href + 'reorder_albums/', {
				//asynchronous: false,
				method: 'post',
				parameters: Sortable.serialize(el, {'name':'ids'}),  // serializacja (+nazwa klucza)
				onFailure: function(resp) {
					try {
						document.documentElement.innerHTML = resp.responseText;
					} catch(e) {
						document.body.innerHTML = resp.responseText;
					}
				}
			})
		}})
	}
})
