(function ($) {
    $.fn.makeSlideshow = function (staticInterval, crossInterval, images) {
        for (image in images) {
            var preload = new Image();
            preload.src = image;
        }
        this.each(function () {
            var $this = $(this);
            $this.html(
				"<img class=\"slideshow-image-b\" style=\"position:absolute; top:0px; left:0px; opacity:0;\" src=\"" + images[0] + "\" />" +
                "<img class=\"slideshow-image-a\" style=\"position:absolute; top:0px; left:0px; opacity:1;\" src=\"" + images[0] + "\" />"
			);

            var $a = $this.find(".slideshow-image-a").first();
            var $b = $this.find(".slideshow-image-b").first();

            var newindex = 0;
            var targeta = false;
            var incr = (8 / crossInterval);
            var opaca = 0;
            var opacb = 1;

            $this.newTimer("cross",
				function () {
				    if (targeta) {
				        opaca += incr;
				        opacb -= incr;
				    }
				    else {
				        opaca -= incr;
				        opacb += incr;
				    }

				    $a.css({ opacity: opaca });
				    $b.css({ opacity: opacb });
				},
				{
				    timeout: 8,
				    times: crossInterval
				}
			);
            $this.newTimer("static",
				function () {
				    $this.startTimer({ name: "cross" });
				    $this.delay((crossInterval + 10),
						function () {
						    newindex = ((newindex + 1) % images.length);
						    if (targeta) {
						        $a.css({ opacity: 1 });
						        $b.css({ opacity: 0 });

						        opaca = 1;
						        opacb = 0;

						        $b.attr({ src: images[newindex] });
						    }
						    else {
						        $a.attr({ opacity: 0 });
						        $b.attr({ opacity: 1 });

						        opaca = 0;
						        opacb = 1;

						        $a.attr({ src: images[newindex] });
						    }
						    targeta = !targeta;
						}
					);
				},
				{
				    timeout: (staticInterval + crossInterval + 10),
				    immediate: false,
				    repeat: true
				}
			).startTimer();
        });
    };
})(jQuery)
