$(document).ready(function () {

	//stretch floating menu
	$(".floatMenu").css("width", window.innerWidth + "px");
	$(window).resize(function() {
		$(".floatMenu").css("width", window.innerWidth + "px");
	});

    //deep linking
    if (document.location.hash) {

        //smooth scroll for deeplinking
        var deepLink = window.location.hash;

        //make into function
        var destination = $(deepLink).offset().top;
        $("html,body").animate({ scrollTop: destination }, "easeInQuad");

        //deep linking
        var pageLink = window.location.hash.substring(1, 3);
        var subLink = window.location.hash.substring(4);

        ep.showPanel(pageLink);
        window.setTimeout(function () {
            $("#" + subLink).slideDown("slow");
        }, 500);

        resetNavColor();
        changeNavColor();
    }

    //add animation when clicking on article summary
    $(".miniArticle, .project").click(function () {
        var destination = $(this).offset().top - 200;
        $("html,body").animate({ scrollTop: destination }, "easeInQuad");
    });

	//scroll to top when clicking on links
    $(".mainNav, .mainNavOn, .pressPanelLink, .articlePanelLink, .projectPanelLink, .partnerPanelLink, .strategicPanelLink, .trainingFeaturePanelLink, .trainingBlogPanelLink").click(function () {
        $("html,body").animate({ scrollTop: 0 }, "easeInQuad");
    });

	
    //change the hash
    /*
    $(".miniArticle").click(function () {
    document.location.hash = $(this).attr("id");
    });
    */



    //resize for android fix
    var ua = navigator.userAgent.toLowerCase();
    var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
    if (isAndroid) {
        $("#epBody").css("width", screen.width + "px");
    }

    //enable swipe navigation for touchscreens
    $(".SlidingPanels").touchwipe({
        wipeLeft: function () {
            ep.showNextPanel();
            resetNavColor();
            changeNavColor();
            return false;
        },
        wipeRight: function () {
            ep.showPreviousPanel();
            resetNavColor();
            changeNavColor();
            return false;
        }
    });


    //highlight first item
    $(".first").find(".thumb").css("border-color", "#faa71a");
    $(".first").find(".triangle").css("background-image", "url(images/selectTriangle.png)");
    $(".first").find("h3").css("color", "#faa71a");
    $(".first").find("div").css("color", "#fff");
    $(".first").find("a").css("color", "#faa71a");


    //form validation
    $("#commentForm").validate();
    $("#registrationForm").validate();

    var currentPage = ep.getCurrentPanel();


    //prev and next links
    $("#mainPrev").click(function () {
        ep.showPreviousPanel();
        resetNavColor();
        changeNavColor();
        //alert($(this).attr('id'));
        //alert(currentPage.id);
        return false;
    });
    $("#mainNext").click(function () {
        ep.showNextPanel();
        resetNavColor();
        changeNavColor();
        return false;
    });


    //change color for links
    $("#nav1, #p1").click(function () {
        ep.showPanel('p1');
        resetNavColor();
        changeNavColor();
        currentPage = ep.getCurrentPanel();
        if (($(this).attr('id')) != currentPage.id) {
            return false;
        };
    });
    $("#nav2, #p2").click(function () {
        ep.showPanel('p2');
        resetNavColor();
        changeNavColor();
        currentPage = ep.getCurrentPanel();
        if (($(this).attr('id')) != currentPage.id) {
            return false;
        };
    });
    $("#nav3, #p3").click(function () {
        ep.showPanel('p3');
        resetNavColor();
        changeNavColor();
        currentPage = ep.getCurrentPanel();
        if (($(this).attr('id')) != currentPage.id) {
            return false;
        };
    });

    $("#nav4, #p4").click(function () {
        ep.showPanel('p4');
        resetNavColor();
        changeNavColor();
        currentPage = ep.getCurrentPanel();
        if (($(this).attr('id')) != currentPage.id) {
            return false;
        };
    });

    $("#nav5, #p5").click(function () {
        ep.showPanel('p5');
        resetNavColor();
        changeNavColor();
        currentPage = ep.getCurrentPanel();
        if (($(this).attr('id')) != currentPage.id) {
            return false;
        };
    });

    //open links
    $(".ButtonViewDemo").click(function () {
        window.open('http://www.eikospartners.com/epCatalyst/', '_blank', '');
        return false;
    });
    $("#linkSite1").click(function () {
        window.open('http://www.eikospartners.com/gallery.html', '_blank', '');
        return false;
    });
    $("#linkSite2").click(function () {
        window.open('http://rd.eikospartners.com/', '_blank', '');
        return false;
    });



    //for expanding LINK
    $("#linkSite1, #linkSite2").click(function () {
        collapseAllLink();
        $(this).find(".triangle").css("background-image", "url(images/selectTriangle.png)");
        $(this).find(".thumb").css("border-color", "#faa71a");
        $(this).find("h3").css("color", "#faa71a");
        $(this).find("a").css("color", "#faa71a");
        $(this).css("color", "#fff");
    });



});


function collapseAllLink() {

    //reset LINK colors
    $("#link").find("h3").css("color", "#959595");
    $("#link").find("div").css("color", "#ccc");
    $("#link").find(".thumb").css("border-color", "#2c2c2c");
    $("#link").find(".triangle").css("background-image", "none");

}

function resetNavColor() {
    $("#nav1").attr('class', 'mainNav');
    $("#nav2").attr('class', 'mainNav');
    $("#nav3").attr('class', 'mainNav');
    $("#nav4").attr('class', 'mainNav');
    $("#nav5").attr('class', 'mainNav');
}

function changeNavColor() {
    var current = ep.getCurrentPanel();

    if (current.id == "p1") {
        $("#nav1").attr('class', 'mainNavOn');
    }
    if (current.id == "p2") {
        $("#nav2").attr('class', 'mainNavOn');
    }
    if (current.id == "p3") {
        $("#nav3").attr('class', 'mainNavOn');
    }
    if (current.id == "p4") {
        $("#nav4").attr('class', 'mainNavOn');
    }
    if (current.id == "p5") {
        $("#nav5").attr('class', 'mainNavOn');
    }
}
