(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state == 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/(\d+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(\d+)(px|\%|em|pt)\s(\d+)(px|\%|em|pt)/);
               return [parseFloat(1-res[1]),res[2],parseFloat(res[3]),res[4]];
           }
        }
	});
    
})(jQuery);


var resizeTimer = null;
var width = 800/2;
var dx = 60;



function getWidth() {
    width = 1200 - Math.ceil($(document).width()/2);
	//dx = Math.ceil($(document).width()/10);
};




$(document).ready(function() {



	$(window).bind('resize', function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(getWidth, 100);
	
	}); 
	$(window).load(function(){
    	getWidth();
		$('.tiny_bg').css({backgroundPosition: '-'+(width+dx)+'px 0px'});
		move1();
	});

});




function move1(){

	var tw = width-dx;
	var rand_no = getRand();
	prop = {"backgroundPosition": '(-'+tw+'px 0px)'};
	$('.tiny_bg').animate(prop,rand_no,'',move2);
}
function move2(){


	var tw = width+dx;
	var rand_no = getRand();
	prop = {"backgroundPosition": '(-'+tw+'px 0px)'};
	$('.tiny_bg').animate(prop,rand_no,'',move1);
}


function getRand(){
	var rand_no = Math.random();
	rand_no = (rand_no * 4000) + 4000;
	rand_no = Math.ceil(rand_no);
	return rand_no;
}