﻿$(document).ready(function() {

    // subnav
    var subnav = $("#subnav");
    if (subnav.length > 0) {

        // show selected by traversing the lineage
        var lineage = $("#cur_lin").val();
        var ar = lineage.split(",");
        for (i = ar.length - 1; i > 1; i--) {
            $("#p" + ar[i]).addClass("selected");
        };

        // turn 1st level into images
        subnav.find(">li>a").each(function() {
            var li = $(this).parent();
            $(this).html("<img src='/images/nav/" + li.attr("id") + li.attr("class") + ".jpg' alt='" + $(this).text() + "' />");

        });

    };

    // content area image - style
    if ($("#bd-m").length > 0) {
        $("#bd-m p:first-child img").parent().addClass("section-pic");
    };

    // popups
    $(".popup").click(function() {
        openWindow($(this).attr("href"), 450, 550);
        return false;
    });

    $("#team-explanation").click(function() {
        openWindow($(this).attr("href"), 420, 550);
        return false;
    });

    // team
    $(".add-to-team").click(function() {
        var m = $(this).attr("id");
        var img = $(this).find("img");
        var type;
        if (img.attr("src") == "images/bt_add-to-my-team.jpg") {
            // adding
            type = "add";
            img.attr("src", "images/bt_add-to-my-team_remove.jpg");
        } else {
            // removing
            type = "delete";
            img.attr("src", "images/bt_add-to-my-team.jpg");
        };

        $.ajax({ type: "POST", url: "teamcookie.aspx", data: "m=" + m + "&t=" + type });

        return false;
    });

    // marquee (splash pages only)
    if ($("#whats-new").length > 0) {

        $("marquee").marquee();

        $("#whats-new").click(function() {
            window.location = $(this).find("a").attr("href");
            return false;
        });

    };

    // testimonial page
    if ($("#testimonials-map").length > 0) {

        $("#testimonials-map").mouseleave(function() {
            $("#testimonials-names img").hide();
        });

        $("#testimonials-map area")
            .mouseenter(function(e) {
                $("#testimonials-names img").hide();
                var idx = $("#testimonials-map area").index(this);
                var $img = $("#testimonials-names img:eq(" + idx + ")");
                $img.css("left", (parseInt($(this).attr("coords").split(",")[0]) - 7) + "px"); //offset image to start of area
                $img.show();

                return false;
            })
            .click(function() {
                //alert("/flash/testimonials/" + $("#testimonials-map area").index(this) + ".swf");
            swfobject.embedSWF("/flash/testimonials/" + $("#testimonials-map area").index(this) + ".swf", "play-video", "338", "245", "9.0.18", "");            
                return false;
            });

    };

    // font sizes (non splash pages only)
    if ($("#fonts").length > 0) {

        // get current font size, set style
        var currentSize = $.cookie('cffont');
        if (!currentSize) {
            currentSize = $("#bd-m").css("font-size").replace("px", "");
        };
        if (!currentSize) { currentSize = "12" }; // default
        $("#bd-m").css("font-size", currentSize + "px"); // set style


        $("#fonts area").click(function() {

            currentSize = parseInt(currentSize);

            if ($(this).attr("alt") == "Decrease font size") {
                currentSize -= 1;
            } else {
                currentSize += 1;
            };

            $.cookie('cffont', currentSize, { expires: 365 }); // set cookie to expire in 365 days
            $("#bd-m").css("font-size", currentSize.toString() + "px"); // set style
            return false;

        });


    };

});

function openWindow(href, width, height) {
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    window.open(href, "gallery", "left=" + left + ", top=" + top + ", width=" + width + ", height=" + height + ", scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes");
};