var $j = jQuery.noConflict();

// prepare the form when the DOM is ready 
$j(function() { 
    var options = { 
      url:		'/wp-content/themes/tarski/js/scriptbuilder.php',
      target:		'#ribs'   // target element(s) to be updated with server response
	}; 
 
    // bind form using 'ajaxForm' 
    $j('#scriptbuilder').ajaxForm(options); 
});

$j(function() {
	$j("#msg").hide();
	
	var bindbehaviours = function() {
		$j(".delone").click( function() {
			$j(this).parent().attr("id", "kill");
			$j("*[@id=kill]").hide(800, function(){
				$j("*[@id=kill]").remove();
			});
			return false;
		});
	};
	
	bindbehaviours();
	
	$j(".addone").click(function() {
		var me = this;
		var c = $j(me).attr("cnt") || 2;
		$j(me).attr("cnt", (parseInt(c)+1) );
		var newels = "<li class=\"rem\" style=\"display:none\"><label for=\"imgurl"+c+"\">URL of image</label><input type=\"text\" class=\"med\" name=\"imgurl[]\" id=\"imgurl"+c+"\" value=\"\" /><a href=\"#\" class=\"delone\">delete this image</a></li>";
		
		$j(newels).insertBefore($j(me).parent()).show(800);
		bindbehaviours();
		return false;
	});
	
	$j("#reset").bind("click", function() {
		$j("#ribs").text("");
		$j("li.rem").remove();
		$j("#msg").hide();
	});
});