function openMenu() {
    var html = $(this).html();

    $(this).html("");
    $("<div></div>").appendTo(this).addClass("sub-menu-start");
    $("<div></div>").appendTo(this).addClass("sub-menu-between").html(html).children().filter("ul").slideDown("slow");
    $("<div></div>").appendTo(this).addClass("sub-menu-end");

    $(".sub-menu-between > a").filter(":first").click(closeMenu);
    $(this).unbind("click", openMenu);

    return false;
}

function openMenuId(id){
    id = $(id).parent();
    var html = $(id).html();

    
    $(id).html("");
    $("<div></div>").appendTo(id).addClass("sub-menu-start");
    $("<div></div>").appendTo(id).addClass("sub-menu-between").html(html).children().filter("ul").slideDown("slow");
    $("<div></div>").appendTo(id).addClass("sub-menu-end");

    $(".sub-menu-between > a").filter(":first").click(closeMenu);
    $(id).unbind("click", openMenu);

    return false;
}



function closeMenu(){
    $li = $(this).parent().parent();

    $(this).parent().parent().children().filter(".sub-menu-between").children().filter("ul").slideUp("slow",
        function() {
            var html = $li.children().filter(".sub-menu-between").html();
            $li.html(html);
            $li.children().css("display", "none");
            $li.children().filter(":first").css("display", "block");
        }
        );

    $(this).unbind("click", closeMenu);
    $(this).bind("click", openMenu);

    return false;
}

function fotoWin(url) {
    aawin = window.open(url,"fotogans",'toolbar=no,location=no,screenX=10,left=10,screenY=10,top=10,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=780,height=500');
}

$(document).ready(function(){
    $(".menu > .menu-between > ul > li > ul").css("display", "none").parent().click(openMenu);
    $(".popup").click(function() {
        fotoWin($(this).attr("href"));
        return false;
    });
    $("#slider").easySlider();
    $("#slider-nocontrol").easySlider({
        controlsShow: false
    });

});

$(document).ready(function() {
    var obj = $("#thumb-holder");
    var s = $("li", obj).length;
    var w = $("li", obj).width();
    var h = $("li", obj).height();
    var pic = 2;
    obj.width(w*5);
    obj.height(h);
    obj.css("overflow","hidden");
    $("ul", obj).css('width',s*w);
    $("#prevBtn").hide();
    if(s <= 5) {
        $(".navigateBar").hide();
    }
	
    function animateToPicture(pictureId) {
        $("#prevBtn").show();
        $("#nextBtn").show();
		
        if(pictureId < 2) {
            pictureId = 2;
        }

        if(pictureId > (s-3)) {
            pictureId = (s-3);
        }
				
        if(pictureId < 4) {
            $("#prevBtn").hide();
        }
		
        if(pictureId > (s-4)) {
            $("#nextBtn").hide();
        }
		
        pic = pictureId;

        var ml = ((pictureId-2)*w*-1);

        $("ul", obj).animate({
            marginLeft: ml
        }, 800);
    }

    $(".thumb").click(function() {
        var id = $(this).attr("id");
        var pictureId = id.substr(8);
        animateToPicture(pictureId);
    });
	
    $("#prevBtn").click(function(){
        animateToPicture( parseInt(pic) - 4);
    });
    $("#nextBtn").click(function(){
        animateToPicture( parseInt(pic) + 4 );
    });
});

