jQuery.fn.extend({
	drag: function(params){
		var jQ = jQuery;
		return this.each(function(){
			var clicked = false;
			var isIE;
			var drag_div = this;
				
			//hide the image & add as bg image
			bgimg = jQuery('#'+this.id + ' img');
			imgx = bgimg.width();			
			imgy = bgimg.height();
			marginLeft = Math.round((screen.width)*0.07);
			//jQuery(this).css('background', "url('"+bgimg.attr('src')+"') no-repeat "+ marginLeft +" 0"); LRO20090612
			jQuery(this).css('background', "url('"+bgimg.attr('src')+"') no-repeat 0 0");
			bgimg.css('display', 'none');
			
			//mouse down
			jQuery(this).mousedown(function(e){
				jQuery(this).css('cursor', 'move');
				clicked = true;
				start_x = Math.round(e.pageX - jQuery(this).eq(0).offset().left);
				start_y = Math.round(e.pageY - jQuery(this).eq(0).offset().top);
			});
			
			//mouse up
			jQuery(this).mouseup(function(e){
				jQuery(this).css('cursor', 'move');
				clicked = false;
			});
			
			//mouse move
			jQuery(this).mousemove(function(e){
				if(clicked){ //as we only want this to work while they have clicked	
					bg = jQuery(this).css('background-position');				
					if (bg == null){ 
						isIE =true;
						bg= jQuery(this).css('background-position-x')+ ' '+jQuery(this).css('background-position-y')
					}				
					if(bg.indexOf('%')>1){
						leftpos = (jQuery(this).width()/2) - (imgx/2);
						toppos = (jQuery(this).height()/2) - (imgy/2);
					}else{
						bg = bg.replace("px", "").replace("px", "").split(" ");
						leftpos = parseInt(bg[0]);
						toppos = parseInt(bg[1]);	
					}
					
					var mouse_x = Math.round(e.pageX - jQuery(this).eq(0).offset().left) - start_x;
					var mouse_y = Math.round(e.pageY - jQuery(this).eq(0).offset().top) - start_y;					
					var x = leftpos + (mouse_x);
					var y = toppos + (mouse_y);					
					start_x = Math.round(e.pageX - jQuery(this).eq(0).offset().left);
					start_y = Math.round(e.pageY - jQuery(this).eq(0).offset().top);	

					if (isIE){
						jQuery(drag_div).css('background-position-x',x + "px");
						jQuery(drag_div).css('background-position-y',y + "px");
					}else{
						jQuery(drag_div).css('background-position', x+ "px " + y + "px");
					}		
				}
		    });			
        });
    }
});