﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

// main.js

var expresspoint = {

    init: function() {
        this.setTargetLinks();
        this.setManualCorners();

        // Home
        if ($("#home-page").length > 0) {
            // Check the version of the user's installed Flash Player.
            //swfobject.registerObject("homePageFeatureSwf", "9");
        }

        // Facilities Page 
        if ($(".facilities-page").length > 0) {
            // Set "resize" event handler for the modal - repositions the modal.
            $(window).resize(function() {
                expresspoint.imageGallery.onWindowResize();
            });

            // Set "click" event handler for image gallery launch link(s).
            $(".imageGalleryLink").click(function() {
                expresspoint.imageGallery.setImageGallery();
                return false;
            });
        }
    },

    setTargetLinks: function() {
        $(".external a").click(function() {
            window.open(this.href);
            return false;
        });
        // Set external links for biopage right-links since code behind doesn't define a new control
        $("a.external").click(function() {
            window.open(this.href);
            return false;
        });
    },

    setManualCorners: function() {
        var settings = {
            tl: { radius: 3 },
            tr: { radius: 3 },
            bl: { radius: 3 },
            br: { radius: 3 },
            antiAlias: true
        }
    }
}

expresspoint.pageOverlay = {

    setPageOverlay: function () {
        $("<div />").attr("id", "pageOverlay").appendTo("body").show();
        //$("#pageOverlay").click(this.unsetPageOverlay);
    },

    unsetPageOverlay: function () {
        $("div#pageOverlay").animate({ opacity: 0.0 }, 1000, function() {
            $("div#pageOverlay").remove();
        });
    }
}

expresspoint.imageGallery = {

    setImageGallery: function() {
        expresspoint.pageOverlay.setPageOverlay();

        $("<div />").attr("id", "imageGallery").appendTo("body").show();

        $("#imageGallery").append('<div id="imageGalleryTrigger"></div>');
        $("#imageGalleryTrigger").click(this.unsetImageGallery);

        $("#imageGallery").append('<div id="imageGalleryContainer"><div id="swfContainer"><p><a href="http://get.adobe.com/flashplayer/">Install Adobe Flash Player</a></p></div></div>');

        // Prepare the configuration for the SWF embed.
        var flashvars = {};
        var params = { x_galleryID: 0 };
        var attributes = { wmode: "transparent" };

        // We assume request URL is unique and matches what the SWF is coded for.
        var locationString = String(window.location);
        var strings = locationString.split("/");
        var lastStringIndex = strings.length - 1;

        // Update params with page-specific values.
        params.x_galleryID = strings[lastStringIndex];

        //alert("params.x_galleryID: " + params.x_galleryID);

        // Use SWFObject to embed the SWF.
        var swf = "/CMSTemplates/ExpressPoint/swf/Gallery.swf";
        swfobject.embedSWF(swf, "swfContainer", "950", "670", "8", flashvars, params, attributes);

        this.setPosition();
    },

    unsetImageGallery: function() {
        $("#imageGallery").hide();
        $("#imageGallery").remove();
        expresspoint.pageOverlay.unsetPageOverlay();
    },

    setPosition: function() {
        var windowCenter = $(window).width() * .5;
        var modalCenter = 475;
        var offset = windowCenter - modalCenter;
        $("#imageGalleryContainer").css("left", offset + "px");
    },

    onWindowResize: function() {
        $("#imageGallery").css("height", $(document).height() + "px");
        $("#imageGalleryTrigger").css("height", $(document).height() + "px");
        // Re-center the modal.
        this.setPosition();
    }
}

$(document).ready(function() {
    expresspoint.init();
});

// EOF
