﻿// use JQuery to manage the spotlight panel display
// dominic winsor

// bind event to anchor click
var targetDivPrevious = "products";
var categoryMenuVisible = false;

$(document).ready(function() {

    // toggle visibility of category menu
    $("a.filter-menu-link").click(function() {

        // position the category menu 
        var menuPosition = $("#filter-menu").position();

        // correct for offset left as content is centred in viewport
        var leftFudge = $(document).width() - $('#wrapper').width();
        leftFudge = Math.ceil(leftFudge / 2);
        leftFudge = 0;
        $("#filter-menu-list").attr("style", "top:" + (menuPosition.top) + "px; left:" + (menuPosition.left + leftFudge) + "px;");

        // toggle vis
        if (categoryMenuVisible) {
            $("#filter-menu-list").fadeOut();
            categoryMenuVisible = false;
        }
        else {
            $("#filter-menu-list").fadeIn();
            categoryMenuVisible = true;
        }

        // cancel the click
        return false;
    });

    // truncate the intro paragraph
    var story_full = $("#products p").html();
    var story_crop = story_full.slice(0, 500);
    $("#products p").html(story_crop);

    // add a 'more' link which restores the full copy
    $("#products p").append(' <a href="#more">...more</a>');
    $("#products p a").click(function() {
        $("#products p").html(story_full);
    });
});
