    function playO(){
        $(playobject).play();
    }

(function($){
    $.fn.createGallery = function(){
        var o = new Object();
        var cache = new Array();
        o["thumbs"] = arguments[0];
        o["bigs"] = arguments[1];
        o["actualposition"] = arguments[2];
        o["actualmoveposition"] = arguments[2];
        o["fastforward"] = arguments[3];        
        o["cache"] = cache;
        var width = arguments[4];
        var height = arguments[5];
        o["positions"] = arguments[6];
        o["play"] = arguments[7];
        o["speed"] = arguments[8];        
        var htmlobject = $(this[0]);
        htmlobject.css({"width":(width + (width*0.12)) + "px"});
        htmlobject.html('<div id="phoenixBigArea"><div id="phoenixLeftArrow"></div><div id="phoenixBigPicture"><table class="phoenixPictable" cellpadding="0" cellspacing="0"><tr><td id="phoenixImageTd"><img id="phoenixImgSrc" src="' + o["bigs"][o["actualposition"]] + '"></td></tr></table></div><div id="phoenixRightArrow"></div></div><div class="phoenixClear"></div>');
        htmlobject.append('<div id="phoenixThumbAreaBig"><div id="phoenixThumbArea"><div id="phoenixThumbAreaMove"></div></div><div class="phoenixClear"></div></div>');
        $("#phoenixThumbArea").css({"width":(width) + "px"});
        $("#phoenixThumbAreaMove").css({"width":(120 * (o["thumbs"].length + 1)) + "px"});
        $("#phoenixThumbAreaMove").css({"height":(50) + "px"});
        var pos = $("#phoenixBigArea").position();
        htmlobject.append('<div id="selector" style="position:absolute;top:428px;_top:431px;left:46px;_left:48px;width:61px;height:60px;border-style:solid;border-color:#cdcdcd;border-width:1px;;"></div>');
        $("#phoenixBigPicture").css({"width":(width) + "px"});
        $("#phoenixBigPicture").css({"height":(height + (height*0.12)) + "px"});
        $("#phoenixLeftArrow").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/prev.png"></a>');
        $("#phoenixLeftArrow").css({"margin-top":(height * 0.5 - ($("#phoenixLeftArrow").height()/2)) + "px"});
        $("#phoenixRightArrow").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/forw.png"></a>');
        $("#phoenixRightArrow").css({"margin-top":(height * 0.5 - ($("#phoenixRightArrow").height()/2)) + "px"});
        $(o).evaluatePosition();
        $("#phoenixLeftArrow").click(function(){            
            $("#phoenixLeftArrow").blur();
            if(!$(o).isFirstPic()){
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] -= 1;                    
                    $(o).evaluatePosition();
                    $("#phoenixImageTd").html(cache[o["actualposition"]]);
                    $(o).updateCache();
                    $("#phoenixImageTd").fadeIn(o["speed"]);
                    $(o).movePosition();
                });
            }
        });

        $("#phoenixRightArrow").click(function(){            
            $("#phoenixLeftArrow").blur();
            if(!$(o).isLastPic()){
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] += 1;                    
                    $(o).evaluatePosition();
                    $("#phoenixImageTd").html(cache[o["actualposition"]]);
                    $(o).updateCache();
                    $("#phoenixImageTd").fadeIn(o["speed"]);
                    $(o).movePosition();
                });
            }
        });

        $("#phoenixLeftArrowFast").click(function(){
            o["possibleNextPict"] = o["actualmoveposition"] - o["fastforward"];
            if(!$(o).isFirstPicFast()){                
                o["actualmoveposition"] -= o["fastforward"];
                $(o).moveOnlyBar();                
            }
        });

        $("#phoenixRightArrowFast").click(function(){
            o["possibleNextPict"] = o["actualmoveposition"] + o["fastforward"];
            if(!$(o).isLastPicFast()){                
                o["actualmoveposition"] += o["fastforward"];
                $(o).moveOnlyBar();
            }
        });

        var i = 0;
        for (var thumb in o["thumbs"]){
            $("#phoenixThumbAreaMove").append('<table class="phoenixThumbTable" cellspacing="0" cellpadding="0"><tr><td class="phoenixThumbTable"><div class="phoenixThumb" pictureid="' + i + '"><img src="' + o["thumbs"][thumb] + '"></div></td></tr></table>');
            i++;
        }

        $(".phoenixThumb").click(function(){
            var id = $(this).attr("pictureid");
            $("#phoenixImageTd").fadeOut(o["speed"],function(){
                o["actualposition"] = parseInt(id);                
                $(o).evaluatePosition();                
                $("#phoenixImageTd").html(cache[o["actualposition"]]);                
                $(o).updateCache();
                $("#phoenixImageTd").fadeIn(o["speed"]);
                $(o).movePosition();                
            });
        });

        for (var ix = 0; ix <= o["bigs"].length - 1; ix++) {
            if(ix < 6){
                var cacheImage = document.createElement('img');
                cacheImage.src = o["bigs"][ix];
                cache.push(cacheImage);
            }
        }

        if(o["play"]){
            playobject = o;
            var aktiv = window.setInterval("playO()", 4000);
        }

        return o;
    }

    $.fn.extend({
        prevPicture: function(){
            var o = this[0];
            o["actualposition"] -= 1;
            return o["bigs"][o["actualposition"]];
        },
        nextPictureFast: function(){
            var o = this[0];
            o["actualposition"] += o["fastforward"];
            return o["bigs"][o["actualposition"]];
        },
        prevPictureFast: function(){
            var o = this[0];
            o["actualposition"] -= o["fastforward"];
            return o["bigs"][o["actualposition"]];
        },
        isLastPic: function(){
            var o = this[0];
            if(o["actualposition"] >= o["thumbs"].length-1){
                return true;
            }else{
                return false;
            }
        },
        isFirstPic: function(){
            var o = this[0];
            if(o["actualposition"] <= 0){
                return true;
            }else{
                return false;
            }
        },
        isFirstPicFast: function(){
            var o = this[0];
            if(o["possibleNextPict"] < 0){
                return true;
            }else{
                return false;
            }
        },
        isLastPicFast: function(){
            var o = this[0];
            if(o["possibleNextPict"] > o["thumbs"].length-1){
                return true;
            }else{
                return false;
            }
        },
        movePosition: function(){
            var o = this[0];
            var position = o["actualposition"];
            o["actualmoveposition"] = o["actualposition"];
            $('#phoenixThumbAreaMove').animate({'left':-(position*102) + 'px'}, 200, function(){});
            return (102*position);
        },
        moveOnlyBar: function(){
            var o = this[0];
            var position = o["actualmoveposition"];
            $('#phoenixThumbAreaMove').animate({'left':-(position*102) + 'px'}, 200, function(){});
            return (102*position);
        },
        updateCache: function(){
            var o = this[0];
            for (var i = 0; i <= 6; i++) {
                if(o["cache"][o["actualposition"] + i] == undefined && (o["actualposition"] + i) < o["thumbs"].length -1){
                  var cacheImage = document.createElement('img');
                  cacheImage.src = o["bigs"][o["actualposition"] + i];
                  o["cache"][o["actualposition"] + i] = cacheImage;
                }
            }
            for (var ia = 6; ia >= 0; ia--) {
                if(o["cache"][o["actualposition"] + ia] == undefined && (o["actualposition"] + ia) >= 0){
                  var cacheImagea = document.createElement('img');
                  cacheImagea.src = o["bigs"][o["actualposition"] + ia];
                  o["cache"][o["actualposition"] + ia] = cacheImagea;
                }
            }
        },
        evaluatePosition: function(){
            var o = this[0];
            var position = o["positions"][o["actualposition"]];
            if(position == "links"){
                $("#phoenixImageTd").css({"text-align":"left","padding-left":"20px","padding-right":"0px"});
            }else if(position == "rechts"){
                $("#phoenixImageTd").css({"text-align":"right","padding-right":"20px","padding-left":"0px"});
            }else{
                $("#phoenixImageTd").css({"text-align":"center","padding-right":"0px","padding-left":"0px"});
            }
        },
        play: function(){
            var o = this[0];
            if(!$(o).isLastPic()){
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] += 1;
                    $(o).evaluatePosition();
                    $("#phoenixImageTd").html(o["cache"][o["actualposition"]]);
                    $(o).updateCache();
                    $("#phoenixImageTd").fadeIn(o["speed"]);
                    $(o).movePosition();
                });
            }else{
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] = 0;
                    $(o).evaluatePosition();
                    $("#phoenixImageTd").html(o["cache"][o["actualposition"]]);
                    $(o).updateCache();
                    $("#phoenixImageTd").fadeIn(o["speed"]);
                    $(o).movePosition();
                });
            }
        }
    });
})(jQuery);


