/* Copyright (C) YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

jQuery(function($){$('select[name="settings[style]"]').bind("change",function(){$("#form").trigger("submit")});$("button.action.add").bind("click",function(){$.post(widgetkitajax+"&task=item_slideshow",{id:$('input[name="id"]').val()},function(data){$(data).appendTo("#items");$("#order").trigger("update")})});if($('input[name="id"]').val()==0){$("button.action.add").trigger("click")}$("#items").delegate(".box","delete",function(e,button){$(this).fadeOut(300,function(){$(this).remove();$("#order").trigger("update")})});$("#items").delegate("input.title","update",function(){var item=$(this).closest(".item");var value=$(this).val()?$(this).val():"untitled";item.find("h3.title").html(value);$('#order li[rel="'+item.attr("id")+'"]').html(value)});$("#order").sortable({axis:"y",start:function(event,ui){$("#"+ui.item.attr("rel")).addClass("sortactive")},stop:function(event,ui){setTimeout(function(){$("#"+ui.item.attr("rel")).removeClass("sortactive")},800)},update:function(event,ui){var item=$("#"+ui.item.attr("rel"));var next=ui.item.next();var prev=ui.item.prev();item.find(".html-editor").trigger("editor-action-start");if(next.length){item.insertBefore($("#"+next.attr("rel")))}else{item.insertAfter($("#"+prev.attr("rel")))}item.find(".html-editor").trigger("editor-action-stop")}}).bind("update",function(){var $this=$(this);$("li",this).each(function(){if(!$("#"+$(this).attr("rel")).length)$(this).remove()});$("#items > .item").each(function(){var id=$(this).attr("id");if(!$this.find("[rel='"+id+"']").length){$this.append('<li rel="'+id+'"></li>')}$("input.title",this).trigger("update")})}).trigger("update")});