﻿
function deb(str) {
	var deb = $(".debb");
	if (deb.length == 0) {
		var div = document.createElement("div");
		div.className = "debb";
		$(document.body).append(div);
		$(div).css({
			position: "absolute",
			top: 0,
			left:0,
			border: "1px solid red",
			background: "white"
	});
	}
	deb = $(".debb");
	deb.append(document.createElement("div").innerHTML = str);
}
var iaf = {
    currentAlbum: 0,
    albumsLength: 0,
    albumsList: null,
    albumLinks: null,
    preparegallery: function() {
    var _ = iaf;
        var list = _.albumsList = $(".gallery a>img");
        _.albumLinks = $(".gallery a");
        _.albumsLength = list.length;
        list.each(function(i, el) {
            if (i > 0) {
                $(el).css("opacity", 0);
            }
        });
        $("a[title='Previous Album']").click(function() {
            _.changePhoto(-1);
        });
        $("a[title='Next Album']").click(function() {
            _.changePhoto(1);
        });
    },
    changePhoto: function(step) {
    var _ = iaf;
        var temp = _.currentAlbum;
        _.currentAlbum += step;
        _.currentAlbum = _.currentAlbum == _.albumsLength ? 0 : _.currentAlbum < 0 ? _.albumsLength - 1 : _.currentAlbum;
        $(_.albumsList[temp]).animate(
			    { left: step * 300, opacity: 0 },
			    { duration: 300, complete: function() {
			    }
			    });
        $(_.albumsList[_.currentAlbum]).css("left", 18);
        $(_.albumsList[_.currentAlbum]).animate(
			    { opacity: 1 },
			    { duration: 300, complete: function() {
			    }
			    });
			    $(".galleryholder .album-title").attr("href",
			    $(_.albumLinks[_.currentAlbum]).attr("href")
		    );
			    $(".galleryholder .album-title").attr("title",
			    $(_.albumLinks[_.currentAlbum]).attr("title")
		    );
			    $(".galleryholder .footer-title").text(
			    $(_.albumLinks[_.currentAlbum]).attr("title")
		    );
    }
    }
