
        var scrollable = false;
        var scrolltimer;
        var scrollitems;

        function scrollticker() {
            clearInterval(scrolltimer);
            scrolltimer = setInterval(intervalslide, 8000);
        }

        function firstSlide() {
            switchSlide($("ul#figuren > li:first > a"));
            setWidth();
        }

        function stopticker() {
            clearInterval(scrolltimer);
        }

        function intervalslide() {
            var next = $("ul#figuren > li > a.active").parent().next().children('a');
            if (next.length > 0) switchSlide(next);
            else firstSlide();
        }

        function fillSlide(target) {
            $("#scroll > .container > .content").animate({
                    marginLeft: 500,
                    opacity: 0
                },
                1000,
                "swing",
                function() {
                    $(this).children("div.text").html($(target).siblings("div.description").children("div.text").html());
                    $(this).children("h3").text($(target).siblings("div.description").children("h3").text())
                }
            ).animate({
                    marginLeft: 160,
                    opacity: 1
                },
                1000,
                "swing"
            );


            $("#scroll > .container > img.inset").animate({
                    bottom: -250                },
                1000,
                "swing",
                function() {
                    $(this).attr('src', $(target).siblings("div.description").children("img.image").attr('src'));
                    $(this).attr('alt', $(target).siblings("div.description").children("img.image").attr('alt'));
                }
            ).animate({
                    bottom: 0
                },
                1000,
                "swing"
            );


        }

        function switchSlide(target) {
            fillSlide(target);
            $("ul#scroller > li > ul > li > a").removeClass('active');
            $(target).addClass('active');
        }

        function setWidth() {
            $("ul#scroller > li.active").each(function() {
                var thiswidth = 0;
                $(this).children("ul").children("li").each(function() {
                    thiswidth += $(this).outerWidth();
                });
                $(this).children("ul").width(thiswidth);
                if (thiswidth < $(this).outerWidth()) {
                    $(".arrow").hide();
                    scrollable = false;
                } else {
                    $(".arrow").show();
                    scrollable = true;
                }
            });
        }

        function firstImage() {
            $("ul#foto > li > a:first").each(function() {
                var desc = $(this).siblings('.description');
                $("#images .container").html("").append(desc.clone());
                $("#images a").click(function() {
                    getFoto().open($(this).attr('rel'));
                    getFoto().show(852);
                    return false;
                });
                
                var rel = $(this).attr("rel");
                $("#images .slideshow").html("");
                                        $.getJSON(rel + "&access=public&start-index=1&callback=?", function(data) {
                                            for(var j = 0; j < data.feed.entry.length; j++) {
                                                var item = data.feed.entry[j];
                                                $("#images .slideshow").append('<img height="170" description="' + item['media$group']['media$description']['$t'] + '" src="' + item['media$group']['media$thumbnail'][2]['url'] + '" />');
                                            }
                                            $("#images .slideshow").cycle();
                                        });
                
                return false;
            });
        }

        $(function() {

            $.getJSON('http://gdata.youtube.com/feeds/users/sprookjescamping34/uploads?alt=json-in-script&callback=?', function(data) {

                            $("#youtubeholder").html('<object class="youtube-player" width="320" height="192"><param name="movie" value="http://www.youtube.com/v/' + data.feed.entry[0].id.$t.replace('http://gdata.youtube.com/feeds/videos/','') + '?color1=0x552b81&color2=0x9963d4&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + data.feed.entry[0].id.$t.replace('http://gdata.youtube.com/feeds/videos/','') + '?color1=0x552b81&color2=0x9963d4&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="192"></embed></object>');

                            for(var i = 0; i < 7; i++) {
                                var item = data.feed.entry[i];

                                var id = item.id.$t.replace('http://gdata.youtube.com/feeds/videos/','');
                                var li = $("<li></li>");
                                var a = $("<a></a>")
                                    .attr('href', "http://www.youtube.com/v/" + id + "?color1=0x552b81&color2=0x9963d4&fs=1")
                                    .click(function() {
                                        var link = $(this).attr('href');
                                        $("#youtubeholder").html(" ");
                                        $("#youtubeholder").html('<object class="youtube-player" width="320" height="192"><param name="movie" value="' + link + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + link + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="192"></embed></object>');
                                        return false;
                                    });
                                var img = $("<img />")
                                    .attr('alt', item.title.$t)
                                    .attr('src', item['media$group']['media$thumbnail'][0]['url'])
                                    .attr('width', 80)
                                    .attr('height', 60);

                                a.append(img);
                                li.append(a);
                                $("#video").append(li);
                            }
                        });

                        $.getJSON('http://picasaweb.google.com/data/feed/api/user/statistieken@sprookjescamping.nl?alt=json-in-script&access=public&start-index=1&callback=?', function(data) {
                            
                            var rel = data.feed.entry[0].link[0].href;;
                            //console.log(data);
                            
                            $.getJSON(rel + "&access=public&start-index=1&callback=?", function(data) {
                                /*that.counti++;
                                img.attr('src', data.feed.entry[0]['media$group']['media$thumbnail'][0]['url']);
                                $.each(data.feed.entry, function(i, item) {
                                    var thumbnail = $('<li></li>');
                                    var link = $('<a style="width: 170px; text-align: center;" href="#" rel="' + item['media$group']['media$content'][0]['url'] + '"><img description="' + item['media$group']['media$description']['$t'] + '" src="' + item['media$group']['media$thumbnail'][1]['url'] + '" height="108" /></a>');
                                    link.click(function() {
                                        that.ytiframe.attr('src', $(this).attr('rel'));
                                        that.ytdesc.html($(this).children('img').attr('description').replace(/\n/g,'<br />'));
                                        that.showImagePlayer();
                                        return false;
                                    })
                                    ul.append(thumbnail.append(link));
                                });
                                li.append(ul);
                                that.videoscroller.append(li);
                                if (that.counti == that.countitems) {
                                    that.init();
                                }*/
                
                            });
                            
                            for(var i = 0; i < data.feed.entry.length; i++) {
                                var item = data.feed.entry[i];

                                var li = $("<li></li>");
                                var a = $("<a></a>")
                                    .attr('rel', item.link[0].href)
                                    .attr('href', '#')
                                    .click(function() {
                                        var desc = $(this).siblings('.description');
                                        var rel = $(this).attr("rel");
                                        $("#images .container").html("");
                                        $("#images .slideshow").html("");
                                        $.getJSON(rel + "&access=public&start-index=1&callback=?", function(data) {
                                            for(var j = 0; j < data.feed.entry.length; j++) {
                                                var item = data.feed.entry[j];
                                                $("#images .slideshow").append('<img height="170" description="' + item['media$group']['media$description']['$t'] + '" src="' + item['media$group']['media$thumbnail'][2]['url'] + '" />');
                                            }
                                            $("#images .slideshow").cycle();
                                        });
                                        $("#images .container").append(desc.clone());
                                        $("#images a").click(function() {
                                            showAlbum($(this).attr('rel'))
                                            return false;
                                        });
                                        return false;
                                    });
                                var img = $("<img />")
                                    .attr('alt', item.title.$t)
                                    .attr('src', item['media$group']['media$thumbnail'][0]['url'])
                                    .attr('width', 60)
                                    .attr('height', 60);
                                var desc = $("<div></div>")
                                    .addClass('description');
                                /*var imgbig = $("<img />")
                                    .attr('alt', item.title.$t)
                                    .attr('src', item['media$group']['media$thumbnail'][0]['url'])
                                    .addClass('image');*/
                                var h3 = $("<h3></h3>")
                                    .text(item.title.$t);
                                var text = $("<div></div>")
                                    .addClass('text');
                                var p = $("<p></p>")
                                    .text(item['media$group']['media$description']['$t']);
                                var br = $("<br />");
                                var p2 = $("<p></p>");
                                var popup = $("<a></a>")
                                    .attr('rel', i)
                                    .attr('href', '#')
                                    .addClass('album-start')
                                    .text('Bekijk album');

                                a.append(img);
                                p2.append(popup);
                                text.append(p).append(br).append(p2);
                                desc.append(h3).append(text);
                                li.append(a).append(desc);
                                $("#foto").append(li);
                            }
                            //scrollticker();
                            firstSlide();
                            setWidth();
                    $("#yt").hide()
                    $("#scroll").hide();
                    $("#images").show();
                            firstImage();

                        });
            $(".arrow").click(function() { return false });

            $("ul#scroller > li > ul").mousemove(function(e) {
                scrollticker();
                if (scrollable) {
                    var left = - ((e.pageX - $(this).offset().left) / $(this).outerWidth()) * ($(this).outerWidth() - $(this).parent().outerWidth());
                } else {
                    left = 0;
                }
               $(this).css("marginLeft", left);
            });

            $("ul#scrollmenu > li > a").click(function() {
                if ($(this).hasClass('setvideo')) {
                    firstSlide();
                    stopticker();
                    $("#scroll").hide();
                    $("#images").hide();
                    $("#yt").show();
                } else if ($(this).hasClass('setfiguren')) {
                    $("#yt").hide();
                    $("#images").hide();
                    $("#scroll").show();
                    scrollticker();
                } else if ($(this).hasClass('setfoto')) {
                    firstImage();
                    stopticker();
                    $("#yt").hide()
                    $("#scroll").hide();
                    $("#images").show();
                }
                var index = $("ul#scrollmenu > li").index($(this).parent());
                $("ul#scrollmenu > li.active").removeClass('active');
                $("ul#scroller > li").removeClass('active');
                $($("ul#scroller > li")[index]).addClass('active');
                $(this).parent().addClass('active');
                setWidth();
                return false;
            });

            $("ul#figuren > li > a").click(function() {
                switchSlide(this);
                return false;
            });

        })
