/**
 * Template for a js project.
 * @author NOSE
 * 
 * @version 1.0.0 initial version
 *
 */
var vMove;
var vWidth = 0;
var ImageStrip = {
    defaults : {
        active:false,
        timerID:0,
		moveItem:'#movestrip',
		stripContainer:'#imagestrip',
		moveDirection:'left',
		clipSpeed:70
    },
	/**
	 * Initialize.
	 */
	initialize : function(op){
    
        vMove = jQuery(ImageStrip.defaults.moveItem);
        // vMove.css("visibility", "hidden");
        ImageStrip.defaults.active = true;
	},
	
    getWidth : function() {
        if (ImageStrip.defaults.active){
	        // jQuery.log($('ul li img', vMove).length);
	        for (var x=0; x <jQuery('ul li img', vMove).length; x++) {
	            vWidth += jQuery('ul li img', vMove).width();
	            // jQuery.log(jQuery('ul li img', vMove).width());
	        }
	        jQuery('ul', vMove).width(vWidth+"px");
	        jQuery.log(jQuery('ul', vMove).width());
	        vWidth = vWidth - jQuery(ImageStrip.defaults.stripContainer).width();
	    }
    },
	
    startMove : function() {
        if (ImageStrip.defaults.active){
            // vMove.css("visibility", "visible");
	        ImageStrip.defaults.timerID = setTimeout("ImageStrip.moveMe()",ImageStrip.defaults.clipSpeed);
	    }
    },
	moveMe : function() {
        if(ImageStrip.defaults.timerID) {
            clearTimeout(ImageStrip.defaults.timerID);
        }
   
        var vL = vMove.css("left");
        var vN = Number(vMove.css('left').substring(0, vL.length -2));
        // jQuery.log(vL+"; "+vN+": w"+vWidth+"; "+(vN > -vWidth));
   
        if (vN >= -vWidth && ImageStrip.defaults.moveDirection == "left") {
	        vMove.css("left", (String((vN-1)+"px")));
        } else if (vN < 0 && ImageStrip.defaults.moveDirection == "right") {
	        vMove.css("left", (String((vN+1)+"px")));
        } else {
            jQuery.log("Reset");
            ImageStrip.defaults.moveDirection = (ImageStrip.defaults.moveDirection == "right") ? "left" : "right";
        }
   
	    ImageStrip.defaults.timerID = setTimeout("ImageStrip.moveMe()",ImageStrip.defaults.clipSpeed);
    }
}
$(window).load(function() {
	   ImageStrip.getWidth();
	   ImageStrip.startMove();
	   $.log("log: "+ImageStrip.defaults.active+"; speed:"+ImageStrip.defaults.clipSpeed);
});
