﻿function init() {
    PopUpHovers();
    NavigationHovers();
    NavigationColours();
    NavigationCurrentPage();
    PortfolioInit();
    SideBarContactInit();
    SideBarSocialInit();
    SetUpFacebook();
}

function SetUpFacebook() {
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=196756083734202";
        fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
}

function SideBarContactInit() {
    $("#divContactSideBar .tab-button").mouseenter(function() {
        $('#divContactSideBar').css('z-index', "10005");
        $('#divContactSideBar').stop().animate({
            left: '-3px'
        }, 1000, function() {
            // Animation complete.
        });
    });
    $("#divContactSideBar").mouseleave(function() {
        $('#divContactSideBar').stop().animate({
            left: '-187px'
        }, 1000, function() {
            $('#divContactSideBar').css('z-index', "10003");
        });
    });
}

function SideBarSocialInit() {
    $("#divSocialSideBar .tab-button").mouseenter(function() {
        $('#divSocialSideBar').stop().animate({
            left: '-3px'
        }, 1000, function() {
            // Animation complete.
        });
    });
    $("#divSocialSideBar").mouseleave(function() {
        $('#divSocialSideBar').stop().animate({
            left: '-187px'
        }, 1000, function() {
            // Animation complete.
        });
    });
}

var tabs = new Array(".portfolio-buttons .creative", ".portfolio-buttons .print", ".portfolio-buttons .web", ".portfolio-buttons .digital");
var currentIndex = 1;
var isOver = false;
var isAutomatic = false;

function ChangeTab() {
    if (isOver) { return; }
    isAutomatic = true;
    var tab = tabs[currentIndex];
    if (tab == ".portfolio-buttons .creative") {
        PortfolioCreativeOver($(tab));
    } else if (tab == ".portfolio-buttons .print") {
        PortfolioPrintOver($(tab));
    } else if (tab == ".portfolio-buttons .web") {
        PortfolioWebOver($(tab));
    } else if (tab == ".portfolio-buttons .digital") {
        PortfolioDigitalOver($(tab));
    }
    isAutomatic = false;
    currentIndex++;
    if (currentIndex == tabs.length) {
        currentIndex = 0;
    }
}

function PopUpHovers() {
    $("#divPhone").hover(function() { $("#divPhone").css("background-position", "0 -35px"); }, function() { $("#divPhone").css("background-position", "0 0"); });
    $("#divEmail").hover(function() { $("#divEmail").css("background-position", "-925px -1068px"); }, function() { $("#divEmail").css("background-position", "-925px -1027px"); });
    $("#divAddAsContact").hover(function() { $("#divAddAsContactPopUp").fadeIn(); }, function() { $("#divAddAsContactPopUp").fadeOut(); });
}

function NavigationHovers() {
    $("#pageId_824").hover(function() {
        $(this).attr("style", "background-color:#C3C836;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_825").hover(function() {
        $(this).attr("style", "background-color:#C3C836;color:#FFFFFF;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_872").hover(function() {
        $(this).attr("style", "background-color:#C3C836;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_826").hover(function() {
        $(this).attr("style", "background-color:#DB0D7B;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_827").hover(function() {
        $(this).attr("style", "background-color:#263B80;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_828").hover(function() {
        $(this).attr("style", "background-color:#F7BC0F;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_829").hover(function() {
        $(this).attr("style", "background-color:#C3C836;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).removeAttr("style");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
    $("#pageId_848").hover(function() {
        $(this).attr("style", "background-color:#C3C836;border:medium none;");
        $('a', this).attr("style", "color:#FFFFFF;");
    }, function() {
        $(this).attr("style", "border: medium none;");
        $('a', this).removeAttr("style");
        NavigationCurrentPage();
    });
}

function NavigationColours() {
    $("#pageId_848").css("border", "none");
    $("#pageId_826 ul li").attr("style", "background:url('/App_Themes/blahdblah/Images/Navigation/pink.png') repeat-x scroll right top transparent;");
    $("#pageId_827 ul li").attr("style", "background:url('/App_Themes/blahdblah/Images/Navigation/blue.png') repeat-x scroll right top transparent;");
    $("#pageId_828 ul li").attr("style", "background:url('/App_Themes/blahdblah/Images/Navigation/orange.png') repeat-x scroll right top transparent;");

    $(".navit-horiz-item-top > ul").prepend("<li><div class='menu-top-arrow'>&nbsp;</div></li>");

    $("#pageId_826 ul li .menu-top-arrow").attr("style", "background-position:-35px 0");
    $("#pageId_827 ul li .menu-top-arrow").attr("style", "background-position:-71px 0");
    $("#pageId_828 ul li .menu-top-arrow").attr("style", "background-position:-106px 0");
}

function NavigationCurrentPage() {
    var urlParts = location.href.split('/');
    if (urlParts[3] == "creative") {
        $("#pageId_872").attr("style", "background-color:#C3C836;");
        $("#pageId_872 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "about") {
        $("#pageId_825").attr("style", "background-color:#C3C836;");
        $("#pageId_825 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "print") {
        $("#pageId_826").attr("style", "background-color:#DB0D7B;");
        $("#pageId_826 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "web") {
        $("#pageId_827").attr("style", "background-color:#263B80;");
        $("#pageId_827 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "digital") {
        $("#pageId_828").attr("style", "background-color:#F7BC0F;");
        $("#pageId_828 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "news") {
        $("#pageId_829").attr("style", "background-color:#C3C836;");
        $("#pageId_829 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "contact") {
        $("#pageId_848").attr("style", "background-color:#C3C836;border:medium none;");
        $("#pageId_848 a").attr("style", "color:#FFFFFF;");
    }
    else if (urlParts[3] == "" || urlParts[3] == "default.aspx" || urlParts[3].indexOf("#") == 0) {
        $("#pageId_824").attr("style", "background-color:#C3C836;");
        $("#pageId_824 a").attr("style", "color:#FFFFFF;");
        $(".sidebar").css("margin", "-20px 0 0");
        $("#divSocial").css("margin", "150px 0 0");
        $(".portfolio").attr("style", "height:323px;");
    }
}

function PortfolioCreativeOver(sender) {
    $(".portfolio-quotes div").hide();
    $(".portfolio-quotes-large div").hide();
    $("#divCreativeQuoteWrapper").show();

    if (!$(".creative-image").is(":visible")) {
        $(".portfolio-images div").fadeOut(500);
        $(".creative-image").fadeIn(1000);
    }
    $(".portfolio-menus div").hide();
    if (!isAutomatic) {
        $("#divCreativeMenu").slideDown();
    }
    $(".portfolio-buttons div").removeAttr("style");
    if ($(".portfolio-quotes-large").length) {
        sender.attr("style", "height:55px;");
    }
}

function PortfolioPrintOver(sender) {
    $(".portfolio-quotes div").hide();
    $(".portfolio-quotes-large div").hide();
    $("#divPrintQuoteWrapper").show();
    if (!$(".print-image").is(":visible")) {
        $(".portfolio-images div").fadeOut(500);
        $(".print-image").fadeIn(1000);
    }
    $(".portfolio-menus div").hide();
    if (!isAutomatic) {
        $("#divPrintMenu").slideDown();
    }
    $(".portfolio-buttons div").removeAttr("style");
    if ($(".portfolio-quotes-large").length) {
        sender.attr("style", "height:55px;");
    }
}

function PortfolioWebOver(sender) {
    $(".portfolio-quotes div").hide();
    $(".portfolio-quotes-large div").hide();
    $("#divWebQuoteWrapper").show();
    if (!$(".web-image").is(":visible")) {
        $(".portfolio-images div").fadeOut(500);
        $(".web-image").fadeIn(1000);
    }
    $(".portfolio-menus div").hide();
    if (!isAutomatic) {
        $("#divWebMenu").slideDown();
    }
    $(".portfolio-buttons div").removeAttr("style");
    if ($(".portfolio-quotes-large").length) {
        sender.attr("style", "height:55px;");
    }
}

function PortfolioDigitalOver(sender) {
    $(".portfolio-quotes div").hide();
    $(".portfolio-quotes-large div").hide();
    $("#divDigitalQuoteWrapper").show();
    if (!$(".digital-image").is(":visible")) {
        $(".portfolio-images div").fadeOut(500);
        $(".digital-image").fadeIn(1000);
    }
    $(".portfolio-menus div").hide();
    if (!isAutomatic) {
        $("#divDigitalMenu").slideDown();
    }
    $(".portfolio-buttons div").removeAttr("style");
    if ($(".portfolio-quotes-large").length) {
        sender.attr("style", "height:55px;");
    }
}

function PortfolioInit() {
    if (!$(".portfolio-quotes-large").length) {
        $(".portfolio-buttons div").removeAttr("style");
    }

    $(".portfolio-buttons .creative").hoverIntent(function() {
        PortfolioCreativeOver($(this));
    }, function() {
        if (!isAutomatic) {
            currentIndex = 1;
        }
    });

    $(".portfolio-buttons .print").hoverIntent(function() {
        PortfolioPrintOver($(this));
    }, function() {
        if (!isAutomatic) {
            currentIndex = 2;
        }
    });

    $(".portfolio-buttons .web").hoverIntent(function() {
        PortfolioWebOver($(this));
    }, function() {
        if (!isAutomatic) {
            currentIndex = 3;
        }
    });

    $(".portfolio-buttons .digital").hoverIntent(function() {
        PortfolioDigitalOver($(this));
    }, function() {
        if (!isAutomatic) {
            currentIndex = 0;
        }
    });

    $(".portfolio").hover(function() {
        isOver = true;
    }, function() {
        isOver = false;
        $(".portfolio-menus div").fadeOut();
    });

    $(".portfolio-menus div").hover(function() { }, function() {
        $(".portfolio-menus div").fadeOut();
    });

    $(function() {
        if (navigator.appName == "Microsoft Internet Explorer") {
            $(document).bind('focusout', function() {
                isOver = true;
            });

            $(document).bind('focusin', function() {
                isOver = false;
            });
        }
        else {
            $(window).bind('blur', function() {
                isOver = true;
            });

            $(window).bind('focus', function() {
                isOver = false;
            });
        }
    });

    setInterval("ChangeTab()", 5000);
}
