    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];
        o["withtext"] = arguments[9];
        if(o["withtext"] == true){
            o["high"] = arguments[10];
        }
        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>');
        if(o["withtext"] == true){            
            htmlobject.append('<div id="phoenixTextArea"><div class="Text" style="float:left;margin-right:10px;margin-left:100px;"></div><div><a href="javascript:;" id="phoenixBigImageLink" name="Bild in hoher Qualit&auml;t betrachten" title="Bild in hoher Qualit&auml;t betrachten"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/glasatelier/image.png"></div></div>');
            $("#phoenixTextArea").css({"text-align":"center"});
            htmlobject.append('<div id="phoenixBigImageBackground">&nbsp;</div>');
            htmlobject.append('<div id="phoenixBigImageClose"><a href="javascript:;" id="closePhoenixBigImage"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/glasatelier/close.png"></a></div>');
            htmlobject.append('<div id="phoenixBigImage"><img src=""></div></div>');
            $("#phoenixBigImage").css({"display":"none","position":"absolute","top":"20px","left":"0px","width":"100%","text-align":"center","z-index":"10001"});
            $("#phoenixBigImageBackground").css({"display":"none","position":"absolute","top":"0px","left":"0px","width":"100%","height":"1000px","text-align":"center","z-index":"10000","background-color":"#000000","filter":"alpha(opacity=90)","opacity":"0.9","-moz-opacity":"0.9"});
            $("#phoenixBigImageClose").css({"display":"none","position":"absolute","top":"10px","left":"10px","z-index":"10002"});
            $("#phoenixTextArea div.Text").html(o["positions"][o["actualposition"]]);
        }
        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":(110) + "px"});
        $("#phoenixImageTd").css({"text-align":"center","width:":width + "px","height": height + "px"});
        $(".phoenixPictable").css({"width":"100%","height":"100%"});
        var pos = $("#phoenixBigArea").position();        
        $("#phoenixBigPicture").css({"width":(width) + "px","text-align":"center"});
        $("#phoenixBigPicture").css({"height":(height + (height*0.12)) + "px"});
        $("#phoenixLeftArrow").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/default/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/default/next.png"></a>');
        $("#phoenixRightArrow").css({"margin-top":(height * 0.5 - ($("#phoenixRightArrow").height()/2)) + "px"});
        $(o).evaluatePosition();

        $("#phoenixBigImageLink").click(function(){
            $(o).viewHightQuality();
        });

        $("#closePhoenixBigImage").click(function(){
            $("#phoenixBigImage").css({"display":"none"});
            $("#phoenixBigImageBackground").css({"display":"none"});
            $("#phoenixBigImageClose").css({"display":"none"});
        });

        $("#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();
                    $("#phoenixTextArea div.Text").html(o["positions"][o["actualposition"]]);
                });
            }
        });

        $("#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();
                    $("#phoenixTextArea div.Text").html(o["positions"][o["actualposition"]]);
                });
            }
        });

        $("#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="phoenixThumbTableTd"><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();
                $("#phoenixTextArea div.Text").html(o["positions"][o["actualposition"]]);
            });
        });

        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(){
            
        },
        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();
                });
            }
        },
        viewHightQuality: function(){            
            var o = this[0];            
            var big = document.createElement('img');
            big.src = o["high"][o["actualposition"]];
            $("#phoenixBigImage").html(big);
            $("#phoenixBigImage img").css({"border-style":"solid","border-color":"#ffffff","border-width":"5px"});
            $("#phoenixBigImage").show();
            $("#phoenixBigImageBackground").show();
            $("#phoenixBigImageClose").show();
        }
    });
})(jQuery);



