/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * jFlow
 * Version: 1.1 (May 22, 2008)
 * Requires: jQuery 1.2+
 */
(function ($) {
    $.fn.jFlow = function (settings) {
        var E = $.extend({}, $.fn.jFlow.defaults, settings);
		var F = 0;
        var B = $("#slides li").length;

		// dynamic css
		$("#jFlowSlide").css({
			width: E.width,
			height: E.height
		});
		$("#slides").css({
			width: $("#jFlowSlide").width() * $("#slides li").length + "px",
			height: $("#jFlowSlide").height() + "px"
		});
		$("#slides li").css({
			width: $("#jFlowSlide").width() + "px",
			height: $("#jFlowSlide").height() + "px"
		});

		// photoalbum
		var current = $("#nav #current").html();
		var total = $("#nav #total").html();
		
		$(".jFlowPrev").click(function () {
            // photoalbum
			if (current > 1){
				current--;
			}
			if (current > 0){
				$("#nav #current").html(current);
			}
			if (current == 1){
				$(".jFlowPrev").hide()
			}
			else{
				$(".jFlowPrev, .jFlowNext").show()
			}

			if (F > 0) {
                F--;
            }
            $(".jFlowControl").removeClass("jFlowSelected");
            $("#slides").animate({
                marginLeft: "-" + (F * $("#slides li").width() + "px")
            }, 200);
           $(".jFlowControl").eq(F).addClass("jFlowSelected")
        });
        $(".jFlowNext").click(function () {
            // photoalbum
			if (current < total){
				current++;
			}
			if (current <= total){
				$("#nav #current").html(current);
			}
			if (current == total){
				$(".jFlowNext").hide();
			}
			else{
				$(".jFlowPrev, .jFlowNext").show()
			}
			if (F < B - 1) {
                F++;
			}
			$(".jFlowControl").removeClass("jFlowSelected");
            $("#slides").animate({
                marginLeft: "-" + (F * $("#slides li").width() + "px")
            }, 200);
            $(".jFlowControl").eq(F).addClass("jFlowSelected")
        })
		
    };
})(jQuery);
