$(function() {
    $("#slideshow img").each(function(i, v) {
        $(v).attr("rel", "#cap" + i);
    });
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: "facebook", 
        hideflash: true
    });
    $('#slideshow').cycle({
        fx: "fade",
        pause: true,
        before: function() {
            $("#caption").fadeOut();
        },
        after: function(ce, ne) {
            var r = $(ne).attr("rel");
            var c = $(r).html();
            if (c != null) {
                $("#caption").html(c);
                $("#caption").css("opacity", 0.5);
                $("#caption").fadeIn();
                var pos = $("#slideshow").offset();
                var w = $("#slideshow").width();
                var w = $(ne).width() - 20;
                var t = pos.top + $("#slideshow").height() - 100;
                $("#caption a").css({"color" : "#ffffff"});
                $("#caption").css({"left" : pos.left + "px", "top" : t + "px", "width": w + "px"});
            }
        }
    });
    $(window).resize(function() {
        var pos = $("#slideshow").offset();
        var w = $("#slideshow").width() - 20;
        var t = pos.top + $("#slideshow").height() - 100;
        $("#caption").css({"left" : pos.left + "px", "top" : t + "px", "width": w + "px"});
    });
    $("#links").cycle({
        fx: "scrollDown",
        pause: true
    });
    $("#addthis").click(function() {
        var wnd = window.open("http://www.addthis.com/bookmark.php?v=250&url=" + escape(location.href) + "&title=" + escape("Advocate Gevorg Gyozalyan"), "addthisPopup", "left=" + ((window.screenX || window.screenLeft) + 10) + ",top=" + ((window.screenY || window.screenTop) + 10) + ",height=480px,width=720px,scrollbars=1,resizable=1,alwaysRaised=1");
        window.setTimeout(function(){wnd.focus()}, 300);
    });
});

function ordsToStr(ords) {
    var str = '';
    for (var i = 0; i < ords.length; i++) {
        str += String.fromCharCode(ords[i]);
    }
    return str;
}

function expandMenu(subId) {
    $("#" + subId).toggle();
}
