








function playO(){
    $(playobject).play();
}

(function($){
    jQuery.fn.createGallery = function(){
        var o = new Object();
        var cache = new Array();
        var thumbCache = new Array();
        var thumbCache2 = 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;
        o["thumbcache"] = thumbCache;
        o["thumbcache2"] = thumbCache2;
        var width = arguments[4];
        var height = arguments[5];
        o["positions"] = arguments[6];
        o["play"] = arguments[7];
        o["speed"] = arguments[8];
        o["withtext"] = arguments[9];
        o["overview"] = false;
        o["overviewloaded"] = false;
        o["actualpage"] = 0;
        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>');        
        htmlobject.append('<div id="phoenixThumbAreaBig"><div id="phoenixLeftArrowFast"></div><div id="phoenixThumbArea"><div id="phoenixThumbAreaMove"></div></div><div id="phoenixRightArrowFast"></div><div class="phoenixClear"></div></div>');
		htmlobject.append('<div style="margin-left:35px;margin-top:25px;"><div id="phoenixLeftArrowOverview" style="display:none;"></div><div id="phoenixThumbAreaOverview" style="display:none;border-style:none;border-width:1px;border-color:#ffffff;width:' + (width*0.9) + 'px;height:' + (496) + 'px;overflow:hidden;"><div id="OverviewMoving"></div></div><div id="phoenixRightArrowOverview" style="display:none;"></div></div>');

		var position = htmlobject.position();

        htmlobject.append('<div id="multiButton" style="position:absolute;"><a id="multiButtonLink" href="javascript:;" name="Gallerieübersicht" title="Gallerieübersicht"><img src="/infoglueDeliverWorking_live/digitalAssets/6/6014_index_icon_.png"></a></div>');
		$("#multiButton").css({'top':(position.top + 535) + 'px','left':(position.left + 440) + 'px'});

        htmlobject.append('<div id="qualityButton" style="position:absolute;"><a id="qualityButtonLink" href="javascript:;" name="Bild in hoher Qualität downloaden" title="Bild in hoher Qualität downloaden"><img src="/infoglueDeliverWorking_live/digitalAssets/6/6015_download_icon_.png"></a></div>');
		$("#qualityButton").css({'top':(position.top + 535) + 'px','left':(position.left + 460) + 'px'});

        $("#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%"});
		$("#OverviewMoving").css({"position":"relative","width":(width*0.9) + "px"});
        $("#phoenixThumbAreaOverview").css({"float":"left","margin-left":"10px","margin-right":"10px"});

        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/fotopirat/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/fotopirat/next.png"></a>');
        $("#phoenixRightArrow").css({"margin-top":(height * 0.5 - ($("#phoenixRightArrow").height()/2)) + "px"});
        $("#phoenixLeftArrowOverview").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/fotopirat/prev.png"></a>');
        $("#phoenixLeftArrowOverview").css({"margin-top":(height * 0.5 - ($("#phoenixLeftArrow").height()/2) + 60) + "px"});
        $("#phoenixRightArrowOverview").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/fotopirat/next.png"></a>');
        $("#phoenixRightArrowOverview").css({"margin-top":(height * 0.5 - ($("#phoenixRightArrow").height()/2) + 60) + "px"});
        $("#phoenixLeftArrowFast").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/fotopirat/fastprev.png"></a>');
        $("#phoenixRightArrowFast").append('<a href="javascript:;"><img src="http://www.phoenix-systems.ch/JavascriptGallerie/images/fotopirat/fastnext.png"></a>');        
        $(o).evaluatePosition();

		if(o["withtext"] != true){
			$('#qualityButton').css({'display':'none'});
			$('#multiButton').css({'display':'none'});
		}

        $("#phoenixLeftArrow").click(function(){
            $("#phoenixLeftArrow").blur();
            if(!$(o).isFirstPic()){
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] -= 1;
                    $(o).evaluatePosition();
                    $(o).changeImage();
                    $(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();
                    $(o).changeImage();
                    $(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()){
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] -= o["fastforward"];
                    $(o).evaluatePosition();
                    $(o).changeImage();
                    $(o).updateCache();
                    $("#phoenixImageTd").fadeIn(o["speed"]);
                    $(o).movePosition();
                });
            }
        });

        $("#phoenixRightArrowFast").click(function(){
            o["possibleNextPict"] = o["actualmoveposition"] + o["fastforward"];
            if(!$(o).isLastPicFast()){
                $("#phoenixImageTd").fadeOut(o["speed"],function(){
                    o["actualposition"] += o["fastforward"];
                    $(o).evaluatePosition();
                    $(o).changeImage();
                    $(o).updateCache();
                    $("#phoenixImageTd").fadeIn(o["speed"]);
                    $(o).movePosition();
                    $(o).checkButtonvisibiliti();
                });
            }
        });

        var i = 0;
        for (var thumb in o["thumbs"]){
            var cacheImagea = document.createElement('img');
            cacheImagea.src = o["thumbs"][thumb];
            var cacheImagea2 = document.createElement('img');
            cacheImagea2.src = o["thumbs"][thumb];
            thumbCache.push(cacheImagea);
            thumbCache2.push(cacheImagea2);
            $("#phoenixThumbAreaMove").append('<table class="phoenixThumbTable" cellspacing="0" cellpadding="0"><tr><td class="phoenixThumbTableTd"><div class="phoenixThumb" id="phoenix_Thumb_' + i + '" pictureid="' + i + '"></div></td></tr></table>');
            $("#phoenix_Thumb_" + i).html(cacheImagea);            
            i++;
        }

        $(".phoenixThumb").click(function(){
            var id = $(this).attr("pictureid");
            $("#phoenixImageTd").fadeOut(o["speed"],function(){
                o["actualposition"] = parseInt(id);
                $(o).evaluatePosition();
				$(o).changeImage();
                $(o).updateCache();
                $("#phoenixImageTd").fadeIn(o["speed"]);
                $(o).movePosition();
                $("#phoenixTextArea div.Text").html(o["positions"][o["actualposition"]]);
            });
        });

        $("#phoenixRightArrowOverview").click(function(){
            if(o["actualpage"] <= (o["thumbs"].length / 24)-1){
                var positionb = $("#OverviewMoving").position();
                $('#OverviewMoving').animate({'top':(positionb.top - 529) + 'px'}, 600, function(){});
                o["actualpage"] += 1;
            }
        });

        $("#phoenixLeftArrowOverview").click(function(){
            if(o["actualpage"] > 0){
                var positionb = $("#OverviewMoving").position();
                $('#OverviewMoving').animate({'top':(positionb.top + 463) + 'px'}, 600, function(){});
                o["actualpage"] -= 1;
            }
        });

		$("#multiButtonLink").click(function(){
            if(o["overview"] == false){
                $("#phoenixBigArea").fadeOut("fast");
                $("#phoenixBigPicture").fadeOut("fast");
                $("#phoenixLeftArrow").fadeOut("fast");
                $("#phoenixRightArrow").fadeOut("fast");
                $("#phoenixThumbAreaBig").fadeOut("fast");
                $("#playButton").fadeOut("fast");
                $("#pauseButton").fadeOut("fast");
                $("#mailButton").fadeOut("fast");
                $("#qualityButton").fadeOut("fast");
                var position = $("#multiButton").position();
                $('#multiButton').animate({'top':(position.top + 120) + 'px','left':(position.left-40) + 'px'}, 600, function(){
                    if(o["overviewloaded"] == false){                                                
                        for(var ixxx = 0; ixxx <= o["thumbcache2"].length - 1; ixxx++){
                            $("#OverviewMoving").append('<table class="phoenixThumbTableOverview" id="phoenix_Thumboverviewtable_' + ixxx + '" cellspacing="0" cellpadding="0"><tr><td class="phoenixThumbTableTd"><a href="javascript:;"><div class="phoenixThumbOverview" id="phoenix_Thumboverview_' + ixxx + '" pictureid="' + ixxx + '"></div></a></td></tr></table>');
                            $("#phoenix_Thumboverview_" + ixxx).html(o["thumbcache2"][ixxx]);
                        }
                        $(o).checkButtonvisibiliti();
                        o["overviewloaded"] = true;
                        $(".phoenixThumbOverview").click(function(){
                            $("#phoenixLeftArrowOverview").fadeOut("fast");
                            $("#phoenixRightArrowOverview").fadeOut("fast");
                            $("#phoenixThumbAreaOverview").fadeOut("fast",function(){
                                $("#phoenixBigArea").fadeIn("fast");
                                $("#phoenixBigPicture").fadeIn("fast");
                                $("#phoenixLeftArrow").fadeIn("fast");
                                $("#phoenixRightArrow").fadeIn("fast");
                                $("#phoenixThumbAreaBig").fadeIn("fast");
                                $("#playButton").fadeIn("fast");
                                $("#pauseButton").fadeIn("fast");
                                $("#mailButton").fadeIn("fast");
                                $("#qualityButton").fadeIn("fast");
                                var positionb = $("#multiButton").position();
                                $('#multiButton').animate({'top':(positionb.top - 120) + 'px','left':(positionb.left+40) + 'px'}, 600, function(){
                                    $("#phoenixThumbAreaOverview").html();
                                    $("#phoenixImageTd").fadeOut(o["speed"],function(){
                                        o["actualposition"] = parseInt(id);
                                        $(o).evaluatePosition();
										$(o).changeImage();
                                        $(o).updateCache();
                                        $("#phoenixImageTd").fadeIn(o["speed"]);
                                        $(o).movePosition();
                                        $(o).checkButtonvisibiliti();
                                    });
                                });
                                o["overview"] = false;
                            });
                            var id = $(this).attr("pictureid");
                        });
                    }
                    $("#phoenixThumbAreaOverview").fadeIn("fast");
                    $("#phoenixLeftArrowOverview").fadeIn("fast");
                    $("#phoenixRightArrowOverview").fadeIn("fast");

                });
                o["overview"] = true;
            }else if(o["overview"] == true){
                $("#phoenixLeftArrowOverview").fadeOut("fast");
                $("#phoenixRightArrowOverview").fadeOut("fast");
                $("#phoenixThumbAreaOverview").fadeOut("fast",function(){
                    $("#phoenixBigArea").fadeIn("fast");
                    $("#phoenixBigPicture").fadeIn("fast");
                    $("#phoenixLeftArrow").fadeIn("fast");
                    $("#phoenixRightArrow").fadeIn("fast");
                    $("#phoenixThumbAreaBig").fadeIn("fast");
                    $("#playButton").fadeIn("fast");
                    $("#pauseButton").fadeIn("fast");
                    $("#mailButton").fadeIn("fast");
                    $("#qualityButton").fadeIn("fast");
                    var positionb = $("#multiButton").position();
                    $('#multiButton').animate({'top':(positionb.top - 120) + 'px','left':(positionb.left+40) + 'px'}, 600, function(){
                        $("#phoenixThumbAreaOverview").html();
                    });
                    o["overview"] = false;
                });
            }
        });

        $("#qualityButtonLink").click(function(){            
            var fileurl = o["bigs"][o["actualposition"]];
            fileurl = fileurl.replace(/Marked_/g,"Quality_");
            fileurl = fileurl.replace(/BigMarked/g,"Hightquality");
            fileurl = fileurl.replace(/&contentId/g,"&modus=highQuality&contentId");
            MeinFenster = window.open(fileurl, "Fotopirat", "width=1,height=1,left=0,top=0,menubar=no,toolbar=no");
            MeinFenster.focus();
        });

        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;
    }

    jQuery.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*107) + 'px'}, 200, function(){});
            return (107*position);
        },
        moveOnlyBar: function(){
            var o = this[0];
            var position = o["actualmoveposition"];
            $('#phoenixThumbAreaMove').animate({'left':-(position*107) + 'px'}, 200, function(){});
            return (107*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(){
            
        },

		checkButtonvisibiliti: function(){
            var o = this[0];
            if(o["activeMail"]){               
                $('#sendmessage').fadeOut("fast");
                o["activeMail"] = false;
            }
        },
		changeImage: function(){
			var o = this[0];
			if(o["cache"][o["actualposition"]] != undefined){
				$("#phoenixImageTd").html(o["cache"][o["actualposition"]]);
			}else{
				var cacheImage = document.createElement('img');
				cacheImage.src = o["bigs"][o["actualposition"]];
				o["cache"][o["actualposition"]] = cacheImage;
				$("#phoenixImageTd").html(cacheImage);
			}
		},
        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);




