/**
 * @author owen@jbanetwork.com
 */

$(document).ready(function(){

	$('.sortable ul.localtasks').prepend('<li><span class="handle" title="drag to move"></span></li>');

	var cols = ['#col-1','#col-2'];
	var $cols = $(cols.toString());
	
	$cols.sortable({
		revert: true,
		items: '> .sortable',
		opacity: 0.5,
		handle: '.handle',
		scroll: true,
		scrollSensitivity: 30,
		scrollSpeed: 20,
		connectWith: cols,
		containment: 'document',
		dropOnEmpty: true,
		placeholder: 'sorthelper',
		zindex:1000,
		forcePlaceholderSize: true,
		forceHelperSize: true,
		tolerance: 'pointer', //'fit', 'intersect', 'pointer', 'touch', 'guess'
		//accurateIntersection: true,
		start: function(e,ui){
					ui.item.find('.wrapper .copy').children().hide(0);
					ui.item.find('.localtasks a').hide(0);
					},
		update : function(ser){
					$.post('ajaxProcess.php',
							{ module : "Profile",
							  method : "ajaxUpdateOrder",
							  'col-1[]': $("#col-1").sortable('toArray'),
							  'col-2[]': $("#col-2").sortable('toArray')
								});
					},
		stop : function(e, ui){
					ui.item.find('.wrapper .copy').children().show(0);
					ui.item.find('.localtasks a').show(0);			
					}
		});
	
	$('.sortable .handle').css('cursor', 'move').mousedown(function(e){
		$(this).parents('.sortable').find('.wrapper .copy').children().hide(0);
		$(this).parents('.sortable').find('.localtasks a').hide(0);
	}).mouseup(function(e){
	//	$(this).parents('.sortable').find('.wrapper .copy').children().show(0);
	//	$(this).parents('.sortable').find('.localtasks a').show(0)
	});
	
	// This is to remove the boarder from a tags under images
	$("a img").parent().each(function(){ 
								$(this).css('border-bottom','none');
							}); 

});