﻿$(document).ready(function() {
    $.getScript("http://twitter.com/statuses/user_timeline/pophristov.json?callback=twitterCallback2&count=1");
});

$(function() {

    $("body#bioBody a.exhibition")
        .hover(function() {
            if ($.browser.msie) {
                $("#" + $(this).attr("id") + " span").css("display", "inline-block");
            }
            else 
            $("#" + $(this).attr("id") + " span").stop().fadeTo("slow", 1);
            
        },
        function() {
            if ($.browser.msie) {
                $("#" + $(this).attr("id") + " span").css("display", "none");
            }
            else
            $("#" + $(this).attr("id") + " span").stop().fadeTo("slow", 0);
        }
    );
        $(".theme-selector span.link-theme")
        .hover(function() {
            $(this).parent().find("span.hover-theme").stop().fadeTo("slow", 1);
        },
        function() {
            $(this).parent().find("span.hover-theme").stop().fadeOut("medium");
        }
    );
        $("body#galleryBody span.link")
        .hover(function() {
            $(this).parent().find("span.hover").stop().fadeTo("medium", 1);
        },
        function() {
            $(this).parent().find("span.hover").stop().fadeOut("medium");
        }
    );

    function hideSubject() {
        $("body#contactBody .ddl").css("display", "none");
    }

    function showSubject() {
        $("body#contactBody .ddl").css("display", "block");
    }

    function setValue(value) {
        if (value != "") {
            $("body#contactBody .selected-value").text(value);
            $("body#contactBody #Subject").attr("value", value);
        } else {
            $("body#contactBody .selected-value").html("&nbsp;");
            $("body#contactBody #Subject").attr("value", "");
        }
    }

    $("body#contactBody .ddl")
        .mouseout(function() {
            if (!$(this).find("li.current input").hasClass("focus")) {
                hideSubject();
            }
        })
        .mouseover(function() {
            showSubject();
        });

    $("body#contactBody .ddl li input")
        .focus(function() {
            $(this).addClass("focus");
        })
        .blur(function() {
            $(this).removeClass("focus");
            if ($(this).parent().hasClass("current")) {
                setValue($(this).attr("value"));
                hideSubject();
            }
        });

    $("body#contactBody .ddl li")
        .mousedown(function() {
            $(this).parent().parent().find("li").removeClass("current");
            $(this).addClass("current");
        });

    $("body#contactBody .ddl li")
        .click(function() {
            if ($(this).parent().hasClass("left") || $(this).parent().hasClass("right")) {
                setValue($(this).text());
                hideSubject();
            }
            else if ($(this).parent().find("li#something-else-holder.current").length > 0) {
                $(this).parent().find("li#something-else-holder.current input").focus();
            }
            else {
                setValue("");
            }
        });

    $("body#contactBody .selected-value")
        .click(function() {
            showSubject();
        }
    );

    // Something else on enter key event handler
    function catchEnter(e) {
        if (e.keyCode == 13) {
            setValue($(this).attr("value"));
            hideSubject();
            $("#Message").focus();
            return false;
        }
    }

    // Something else on enter key set event
    if ($.browser.mozilla) {
        $("body#contactBody .ddl li input").keypress(catchEnter);
    } else {
        $("body#contactBody .ddl li input").keydown(catchEnter);
    }

    //previous & next
    function checkKey(e) {
        switch (e.keyCode) {
            case 37:
                //previous
                if ($("#previous-image").attr("href") != undefined)
                    window.location.href = $("#previous-image").attr("href");
                break;
            case 39:
                //next
                if ($("#next-image").attr("href") != undefined)
                    window.location.href = $("#next-image").attr("href");
                break;
            default:
                break;
        }
    }

    if ($.browser.mozilla) {
        $(document).keypress(checkKey);
    } else {
        $(document).keydown(checkKey);
    }

    //smooth scroll - gallery-menu

    $("body#galleryBody .gallery-menu a")
        .click(function() {
            if (!$(this).hasClass("current")) {
                $('html, body').animate({ scrollTop: $($(this).attr("link")).offset().top }, 1500);
            }
        }
    )

    $("body#galleryBody").ready(function() {
        $(".gallery-menu:not(.standalone) a").each(function() {
            $(this).attr("link", $(this).attr("href"));
            $(this).attr("href", "javascript:;");
        });
    });

});

// set confirm message on each delete link in the page
function applyConfirmOnDelete(deleteLinkSelector, msg) {
    $(deleteLinkSelector).click(function(e) {
        if (!confirm(msg)) {
            e.preventDefault();
        }
    });
}
