$(document).ready(function() {
			
	// delete the block
	$('.jq_block_delete').bind("click",function(){
	  blocks_layoutID = $(this).attr('name');
	  $('#ajax').load( SUB_FOLDER + "system/application/ajax_delete_block.php" , { "blocks_layoutID" : blocks_layoutID } , function(){
		 location.reload(true);
	  });
	});

    $('#drpanel').hover(
      function () {
        $(this).removeClass("panel_closed");
      }, 
      function () {
        $(this).addClass("panel_closed");
      }
    );

	$('#drpanel')
			.bind('drag',function( event ){
					$( this ).css({
							top: event.offsetY,
							left: event.offsetX
							});
					});

		$('.dr_block')
				.bind( "dragstart", function( event ){
				
						block_id = $( this ).attr("block_id");
						
						// ref the "dragged" element, make a copy
						var $drag = $( this ), $proxy = $drag.clone();
						// modify the "dragged" source element
						$drag.addClass("outline");
						// insert and return the "proxy" element                
						return $proxy.appendTo( document.body ).addClass("ghost");
						
						})
				.bind( "drag", function( event ){
				
						// update the "proxy" element position
						$( event.dragProxy ).css({
								left: event.offsetX,
								top: event.offsetY
								});
						})
		        .bind( "dragend", function( event ){
						// remove the "proxy" element
						$( event.dragProxy ).fadeOut( "normal", function(){
								$( this ).remove();
						});
						// if there is no drop AND the target was previously dropped
						//if ( !event.dropTarget && $(this).parent().is(".drop") ){
						// output details of the action
						//		$('#log').append('<div>Removed <b>'+ this.title +'</b> from <b>'+ this.parentNode.title +'</b></div>');
						// put it in it's original div...
						//		$('#nodrop').append( this );
						//}
						// restore to a normal state
						//$( this ).removeClass("outline");      
               
                });


	// drop a block
	$(".jq_drop")
        .bind( "dropstart", function( event ){
                // don't drop in itself
                if ( this == event.dragTarget.parentNode ) return false;
                // activate the "drop" target element
                $( this ).addClass("active");
                })
        .bind( "drop", function( event ){
			    $("#ajax").load( SUB_FOLDER + "system/application/ajax_insert_block.php" , { "block_id" : block_id , "section" : $( this ).attr("section"), "drop_order" : $( this ).attr("drop_order") , "layout_id" : $( this ).attr("layout_id") } , function(){
				  location.reload(true);
				});

                // if there was a drop, move some data...
                //$( this ).append( event.dragTarget );       
                })
        .bind( "dropend", function( event ){
                // deactivate the "drop" target element
                $( this ).removeClass("active");
         });
});

