﻿$(function () {

    initNavigation();
    initServices();
    initCases();
    initNews();
    initContact();
    initSocial();

    initStickyHeaders();

    window.onhashchange = OnRouteChanged;
    OnRouteChanged();
});

function initStickyHeaders() {
    setupStickyHeaders();
    $('#what-we-do > .content-header').clone(true).appendTo($('#sticky-header').empty());
}

function setupStickyHeaders() {
    var $stickyHeader = $('#sticky-header');
    var $headers = $('.content-header');
    var zIndex = 12;

    $headers.each(function () {
        $(this).css({ 'z-index': zIndex++ });
    });

    $(window).scroll(function () {
        $headers.each(function () {
            var headerTop = $(this).position().top;
            var containerTop = -($('html').position().top) + 110;

            if (headerTop < containerTop) {
                $(this).clone(true).appendTo($stickyHeader.empty());
                $stickyHeader.css({ 'z-index': parseInt($(this).css('z-index')) + 1 });
            }
        });
    });
}

function initNavigation() {
    $('#social-share img').each(function () {
        $(this).hover(
            // mouseover
            function () {
                this.src = this.src.replace('_icon.png', '_icon_blue.png');
            },
            // mouseout
            function () {
                this.src = this.src.replace('_icon_blue.png', '_icon.png');
            });
    });
    $('#social-share').hover(function () { $(this).show(); }, function () { $(this).hide(); });
    $('#navigation > .share a').hover(function () { $('#social-share').show(); }, function () { $('#social-share').hide(); });
}

function initContact() {
    $('.direct').click(function () {
        window.location.href = "mailto:john@ironcreative.com";
    });
}
