/*======================================================================*\
|| #################################################################### ||
|| # Drag'nDrop Shop 1.8                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright 2014 JAKWEB All Rights Reserved.                       # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| #   ----------- Drag'nDrop Shop IS NOT FREE SOFTWARE -----------   # ||
|| #                      http://www.jakweb.ch                        # ||
|| #################################################################### ||
\*======================================================================*/

$(document).ready(function() {

	$('nav a[title], a[title]').colorTip({color:'green'});
	
	var mouseX, mouseY, lastX, lastY = 0;
	 
	// This function captures the x and y positions anytime the mouse moves in the document.
	$().mousemove(function(e) { mouseX = e.pageX; mouseY = e.pageY; });
	 
	// Only fire the move when mouseover arrows
	$(".jak_fire_move").mouseover(function() {
		$('.jak_dont_move_out .jak_move_cat').live('mousedown', function (e) {
			lastY = mouseY;
			var table = $(this);
			table.fadeTo('fast', 0.4);
			$('.jak_move_cat', table.parent() ).not(this).mouseenter(function(){
				if (mouseY > lastY) {
						$(this).after(table);
				} else {
						$(this).before(table);
				}
				lastY = mouseY;
			});
	 		$('body').mouseup(function () {
			   table.fadeTo('fast', 1);
			   $('table', table.parent()).unbind('mouseenter');
			   $('body').unbind('mouseup');
	 
			$(document).unbind('selectstart');
	 
			   reorder(); // Get the new order fired into the input field
			   
			});
			
			e.preventDefault();
	 
		// IF Fix in total
		if (need_select_workaround)
			$(document).bind('selectstart', function () { return false; });
			return false;
	 
		}).addClass('movemouse');
		
	$(".jak_fire_move").mouseleave(function() {
		$('.jak_dont_move_out .jak_move_cat').die();
	});
	 
	function reorder () {
			var position = 1;
			$('table.jak_move_cat').each(function () {
				$('.corder', $(this)).val(position);
				$(this).removeClass('row1 row2').addClass(position % 2 ? 'row1' : 'row2');
				position += 1;
			});
		}
		}).mouseleave(function(){
		$('*').die().removeClass('movemouse');
		});

});