$(document).ready(function () {
$("#block").delay(2000).animate({
    left: '+=300'
}, 2000, function () {
    $("#block").animate({
        height: '0'
    }, 2000, function () {
		$("#block").css("display", "none");
    });
});
if (navigator.userAgent.indexOf('iPhone') != -1) {
        addEventListener("load", function () {
            setTimeout(hideURLbar, 0);
        }, false);
    }

    function hideURLbar() {
        window.scrollTo(0, 1);
    }
    $.fancybox.init();
    $(".artwork a").fancybox({
        'titlePosition': 'outside'
    });
    $('h1 a').hover(function () {
        startRotation();
    }, function () {
        stopRotation();
    });
    var counter = 0;
    var patterns = ["-61px", "-122px", "-183px", "-244px", "-305px", "-366px", "-427px", "-488px", "-549px", "-610px", "-671px", "-732px", "-793px", "-854px"];

    function showDiv() {
        if ($(document).width() > 600) {
            var rand = Math.floor(Math.random() * patterns.length);
            $('h1').css("background-position-y", patterns[rand]);
        }
    }
    var timerId = null;

    function startRotation() {
        if (timerId) {
            return;
        }
        timerId = setInterval(showDiv, 50);
    }

    function stopRotation() {
        if (!timerId) {
            return;
        }
        clearInterval(timerId);
        timerId = null;
    }
    $("#displayM a").click(function () {
        $("nav").slideToggle('slow', function () {
            if ($("nav").is(':visible')) {
                $("#displayM a").css("background", "url(assets/imgs/arrowUp.gif)");
            } else {
                $("#displayM a").css("background", "url(assets/imgs/arrowDown.gif)");
            }
        });
    });
    $("nav a").click(function () {
        if ($("nav").is(":hidden")) {
            $("#displayM a").css("background", "url(assets/imgs/arrowUp.gif)");
        } else {
            if ($(document).width() <= 600) {
                $("nav").slideUp('slow', function () {
                    $("#displayM a").css("background", "url(assets/imgs/arrowDown.gif)");
                });
            }
        }
    });
    $(".artwork a").hover(

    function () {
        $(this).find("img").animate({
            opacity: "0.5"
        }, {
            duration: 300
        });
    }, function () {
        $(this).find("img").animate({
            opacity: "1"
        }, {
            duration: 300
        });
    });
    $('ul.filter li').first().addClass('current');
    $('ul.filter a').click(function () {
        $(this).css('outline', 'none');
        $('ul.filter .current').removeClass('current');
        $(this).parent().addClass('current');
        var filterVal = $(this).text().toLowerCase().replace(' ', '-');
        if (filterVal == 'timeline') {
            $('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
        } else {
            $('ul#portfolio li').each(function () {
                if (!$(this).hasClass(filterVal)) {
                    $(this).fadeOut('normal').addClass('hidden');
                } else {
                    $(this).fadeIn('slow').removeClass('hidden');
                }
            });
        }
        return false;
    });
});
