// spargosus javascript functionality
// developed by ICC -- 2011/02/07

function CurrencyFormatted(amount) {
        var i = parseFloat(amount);
        if(isNaN(i)) { i = 0.00; }
        var minus = '';
        if(i < 0) { minus = '-'; }
        i = Math.abs(i);
        i = parseInt((i + .005) * 100);
        i = i / 100;
        s = new String(i);
        if(s.indexOf('.') < 0) { s += '.00'; }
        if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
        s = minus + s;
        return s;
}

function slider_init() {
$("#viewer").removeClass("js-disabled");

$("<div>").attr("id", "container").css({ position:"absolute"
}).width($(".wrapper").length * 170).height(170).appendTo("div#viewer");

$(".wrapper").each(function() {
  $(this).appendTo("div#container");
});

var duration = $(".wrapper").length * 1000;

var speed = (parseInt($("div#container").width()) + parseInt($("div#viewer").width())) / duration;

var direction = "rtl";

(direction == "rtl") ? $("div#container").css("left", $("div#viewer").width()).addClass("rtl") : $("div#container").css("left", 0 - $("div#container").width()).addClass("ltr");
$("</div>");
}

//animator function
var animator = function(el, time, dir) {
  //which direction to scroll
  if(dir == "rtl") {

    //add direction class
    el.removeClass("ltr").addClass("rtl");

    //animate the el
    el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {

	//reset container position
	$(this).css({ left:$("div#imageScroller").width(), right:"" });

	//restart animation
	animator($(this), duration, "rtl");

	//hide controls if visible
	($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			

    });
  } else {
    //add direction class
    el.removeClass("rtl").addClass("ltr");

    //animate the el
    el.animate({ left:$("div#viewer").width() + "px" }, time, "linear", function() {

      //reset container position
      $(this).css({ left:0 - $("div#container").width() });

      //restart animation
      animator($(this), duration, "ltr");

      //hide controls if visible
      ($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;
    });
  }
}


