﻿/****************************************
* awearness Script - 08/01/2011
*
* Dependencies: 
*    jquery-1.6.2.min.js
*    jquery.ezbgresize.js
*    settings.js
*****************************************/

var awearness = function () {
    var member = this;
    member.currentTrack = 0;

    $(document).ready(function () {
        awearness.ReadyPage();
    });

    $(window).load(function () {
        //confirm("Simulate long loading time . . .");  // Emulate Long load time.
        awearness.LoadPage();
    });


    return {
        /// <summary>
        /// Initialize dynamically driven page elements when (DOM) is ready.
        /// </summary>
        ReadyPage: function () {
            // Load Priority Images.
            var targetPage = $(awearness.UrlHash()).length > 0 ? awearness.UrlHash() : "#HomePage";
            var background = $(targetPage + ' .BackgroundData').html();
            var $images = $('#Backgrounds .' + background);
            $images.each(function () {
                $this = $(this);
                $this.attr('src', $this.attr('alt'));
            });

            // Set jQuery frame rate (Helps older browsers and mobile devices).
            $.fx.interval = g_settings.frameRate;

            // Hotkeys.
            if (g_settings.Debug) {
                $(window).keyup(function (e) {
                    switch (e.keyCode) {
                        case 192: // ~ key = Hide/Show Debug Monitor
                            $('#Monitor').slideToggle(250);
                            break;
                        case 46: // DEL key = Clear Debug Monitor
                            MOut("");
                            break;
                        case 79: // O key = Toggle imageMap outlines
                            $('#Content, .ImageMap').toggleClass('ImageMapDebug');
                            break;
                        default:
                            //MPrintln(e.keyCode);
                            break;
                    }
                });
            }

            // Init Background.
            $("body").ezBgResize({
                img: "/images/background.jpg"
            });

            // Init awearness Member Variables.
            member.$content = $('#Content');
            member.$loading = $('#Loading');
            member.$loadingPage = $('#LoadingPage');
            member.$logo = $('#Logo');
            member.$mainMenu = $('#MainMenu');
            member.$homePage = $('#HomePage');
            member.$currentPage = member.$homePage;
            member.$issuesArchivePage = $('#IssuesArchivePage');
            member.$changeAgentsPage = $('#ChangeAgentsPage');
            member.$wdysPage = $('#WhereDoYouStand');
            member.$wdysIframe = $('iframe', member.$wdysPage);
            member.$merchandisePage = $('#MerchandisePage');
            member.$contactPage = $('#ContactPage');
            member.$partnerApplication = $('#PartnerApplication');
            member.$productDonation = $('#ProductDonation');
            member.$sweeps = $('#Sweeps');

            member.$sweepsSundance = $('#SweepsSundance');
            member.$sundanceVolunteers = $("#SundanceVolunteers");

            // Init jQuery Style
            member.$content.css('position', 'absolute');
            member.$loadingPage.css('opacity', .75);
            awearness.ResizeContent();

            // Set event handlers.
            window.onhashchange = function () { return false };  // Prevents page jumping to top.
            $(window).resize(awearness.ResizeContent);

            // Yank all the videos out of the Dom and into memory
            awearness.ShowVideo($('#ChangeAgentKennethCole'), false);
            awearness.ShowVideo($('#ChangeAgentSkylar'), false);
            awearness.ShowVideo($('#ChangeAgentCheyenne'), false);
            awearness.ShowVideo($('#ChangeAgentKesha'), false);
            awearness.ShowVideo($('#ChangeAgentCyndi'), false);
            awearness.ShowVideo($('#ChangeAgentRose'), false);
            awearness.ShowVideo($('#ChangeAgentsSarah'), false);
            awearness.ShowVideo($('#ChangeAgentEstelle'), false);
            awearness.ShowVideo($('#ChangeAgentLaurenBush'), false);
            awearness.ShowVideo($('#ChangeAgentsPage'), false);

            // Init mobile gesture handlers.
            // Pinch zoom - reposition slides.
            /*document.addEventListener("gestureend", function () {
            setTimeout(function () { awearness.AdvanceSlides(member.$currentPage, 0) }, 100);
            }, false);

            // Double tap to resize - reposition slides.
            document.addEventListener("touchend", function () {
            if (awearness.touched) {
            setTimeout(function () { awearness.AdvanceSlides(member.$currentPage, 0) }, 100);
            }
            awearness.touched = true;
            setTimeout(function () { awearness.touched = false; }, 250);
            }, false);*/
        },


        /// <summary>
        /// Initialize site when (All Page Content) is ready.
        /// </summary>
        LoadPage: function () {
            // Load Lazy images.
            $('img.LazyLoad').each(function () {
                var $this = $(this);
                $this.attr("src", $this.attr('alt'));
            });

            // Resize Fully Loaded Objects.
            awearness.ResizeElement($('.Resizable'));
            awearness.ResizeText($('.ResizeText'));
            awearness.ResizeArchives();

            // Set event handlers.
            awearness.SetMouseOvers();
            $("#ContactPage .Stage4 .partnerPolicy").click(function () {
                $("#PartnershipPolicyPopup").slideToggle();
            });
            $(window).resize(function () {
                awearness.ResizeElement($('.Resizable'));
                awearness.ResizeText($('.ResizeText'));
                awearness.ResizeArchives();
            });

            // Show contents after initial resizing is complete.
            $('#Header, #Footer, #Backgrounds').css('visibility', 'visible');

            // Animate Site Default Page.
            member.$loading.fadeOut(g_settings.transitionDuration, function () {
                // Load hashed page from URL.
                awearness.UrlPolling();
            });

            // Initialize Scroll Areas.
            $('#PartnerScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#DonationScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#SweepsScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#KeshaScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#CyndiScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#CheyenneScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#SkylarScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#KennethScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#RoseScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#SarahScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#EstelleScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#FrantiScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#WakedScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#LaurenBushScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#CoryBookerScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
            $('#SweepsSundanceScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
        },


        /// <summary>
        /// Resizes archive pages to animate properly.
        /// </summary>
        ResizeArchives: function () {
            $('.ArchiveContent').each(function () {  // Adjust Archive width to fit resized columns.
                $this = $(this);
                $columns = $('.archiveColumn', $this);
                $this.width($columns.length * Math.ceil($columns.width()));
            });
        },


        /// <summary>
        /// Recalculates the size of the content area bases on Settings.js
        /// </summary>
        ResizeContent: function () {
            // Store Original Demensions.
            if (!jQuery.hasData(member.$content[0])) {
                member.$content.data("originalHeight", member.$content.height());
                member.$content.data("originalWidth", member.$content.width());
            }

            // Scale by available X or Y inteligently.
            var screenRatio = $(window).height() / $(window).width() * g_settings.contentScaleY;
            var contentRatio = member.$content.height() / member.$content.width();
            //TODO: include contentScaleX and contentScaleY in this calculation.
            if (screenRatio > contentRatio) {
                var width = $(window).width() * g_settings.contentScaleX;
                width = width > member.$content.data("originalWidth") ? member.$content.data("originalWidth") : width;
                width = width < g_settings.contentMinX ? g_settings.contentMinX : width;
                member.$content.width(width);
                member.$content.height(width * contentRatio);
            }
            else {
                var height = $(window).height() * g_settings.contentScaleY;
                height = height > member.$content.data("originalHeight") ? member.$content.data("originalHeight") : height;
                height = height < g_settings.contentMinY ? g_settings.contentMinY : height;
                member.$content.height(height);
                member.$content.width(height / contentRatio);
            }

            // Set scale for other items.
            member.$content.data("scale", member.$content.width() / member.$content.data("originalWidth"));

            // Center.
            member.$content.css('left', ($(window).width() - member.$content.width()) / 2);
            member.$content.css('top', ($(window).height() - member.$content.height()) / 2);
            if (g_settings.Debug) {
                MOut("content-W: " + member.$content.width() + "<br />content-H: " + member.$content.height() +
                "<br /><br>window-W: " + $(window).width() + "<br />window-H: " + $(window).height());
            }
        },


        /// <summary>
        /// Recalculates the size of elements relative to the content area.
        /// </summary>
        ResizeElement: function (elements) {
            var scale = member.$content.data("scale");
            var $content = member.$content;  // Need to make local pointer to global member for use in jQuery.each()

            $(elements).each(function () {
                $this = $(this);

                // Store Original Demensions.
                if (!jQuery.hasData(this)) {
                    $this.data("originalHeight", $this.height());
                    $this.data("originalWidth", $this.width());
                    $this.data("originalFontSize", parseInt($this.css('font-size')));
                    $this.data("originalLineheight", parseInt($this.css('line-height')));
                }

                // Scale to Content Area.
                $this.width(Math.round($this.data("originalWidth") * scale));
                $this.height(Math.round($this.data("originalHeight") * scale));

                // Scale fonts.
                var newFontSize = scale * $this.data("originalFontSize");
                newFontSize = newFontSize < g_settings.fontSizeMin ? g_settings.fontSizeMin : newFontSize;
                $this.css('font-size', newFontSize + "px");
                $this.css('line-height', scale * $this.data("originalLineheight") + "px");
            });
        },


        /// <summary>
        /// Recalculates the size of text relative to the content area with upper and lower bounds.
        /// </summary>
        ResizeText: function (elements) {
            var scale = member.$content.data("scale");
            var $content = member.$content;  // Need to make local pointer to global member for use in jQuery.each()

            $(elements).each(function () {
                $this = $(this);

                // Store Original Demensions.
                if (!jQuery.hasData(this)) {
                    $this.data("originalFontSize", parseInt($this.css('font-size')));
                    $this.data("originalLineheight", parseInt($this.css('line-height')));
                }

                // Scale fonts.
                var newFontSize = scale * $this.data("originalFontSize");
                newFontSize = newFontSize < g_settings.fontSizeMin ? g_settings.fontSizeMin : newFontSize;
                $this.css('font-size', newFontSize + "px");
                $this.css('line-height', scale * $this.data("originalLineheight") + "px");
            });
        },

        /// <summary>
        /// Toggles video element in and out of the DOM. (Done for i-phone/Vimeo compatibility)
        /// </summary>
        ShowVideo: function ($target, show) {
            if (show)
                $('.ChangeAgentVideo', $target).append($target.data('videoPlayer'));
            else
                $target.data('videoPlayer', $('.Player', $target).detach());
        },

        /// <summary>
        /// Polls URL for navigation changes.
        /// </summary>
        UrlPolling: function (lastHash) {
            var currentHash = awearness.UrlHash();

            if (currentHash.indexOf("#Height_") == 0) {
                var newHeight = parseInt(currentHash.substr(8));
                if (!isNaN(newHeight)) {
                    $('iframe', member.$currentPage).height(newHeight);
                    $('#WDYSScroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
                }
                currentHash = lastHash;
                awearness.UrlHash(lastHash);
            }
            if (currentHash != lastHash) {
                awearness.NavigateTo(currentHash);
                lastHash = awearness.UrlHash();
            }
            setTimeout(function () { awearness.UrlPolling(lastHash) }, g_settings.URLPollingDuration);
        },


        /// <summary>
        /// Sets or gets page marker from the URL.
        /// </summary>
        UrlHash: function (hash) {
            if (hash == undefined) {
                var match = window.location.hash.match(/#Page_(.*)$/);
                return match ? "#" + match[1] : "";
            }
            else {
                window.location.hash = "#Page_" + hash.replace("#", "");
                return hash;
            }
        },


        /// <summary>
        /// Provides intuitive method to navigate via href tags.
        /// </summary>
        SetPage: function (id) {
            if (id == undefined)
                id = '#HomePage';
            awearness.UrlHash(id);
        },


        /// <summary>
        /// Loads page content on demand.
        /// </summary>
        GetPage: function ($targetPage, callback) {
            // Check if content already exists.
            if ($targetPage.is(':empty')) {
                member.$loadingPage.show();
                // Load Content Dynamically.
                $targetPage.load($targetPage.attr('id') + '.htm', function () {
                    $targetPage.waitForImages(function () {
                        // Adjust content once loaded.
                        awearness.ResizeElement($('.Resizable', $targetPage));
                        awearness.ResizeText($('.ResizeText', $targetPage));
                        awearness.ResizeArchives(); //TODO: Change so this is only done when necessary.
                        awearness.InitArchiveViewPorts($targetPage);
                        member.$loadingPage.fadeOut(250);
                        if (callback) callback();
                    });
                });
            } else {
                if (callback) callback();
            }
        },


        /// <summary>
        /// Coordinates Main Site Navigation.
        /// </summary>
        NavigateTo: function (targetPage) {
            var $targetPage;

            // Yank any videos from the dom and place them in memory
            awearness.ShowVideo(member.$currentPage, false);

            // Clear iFrame(s).
            member.$wdysIframe.attr('src', "");

            // Determine animation sequence based on target page.
            switch (targetPage) {
                case '#ChangeAgentKennethCole':
                case '#ChangeAgentSkylar':
                case '#ChangeAgentCheyenne':
                case '#ChangeAgentKesha':
                case '#ChangeAgentCyndi':
                case '#ChangeAgentRose':
                case '#ChangeAgentSarah':
                case '#ChangeAgentEstelle':
                case '#ChangeAgentMichaelFranti':
                case '#ChangeAgentAmrWaked':
                case '#ChangeAgentLaurenBush':
                case '#ChangeAgentCoryBooker':
                    $targetPage = $(targetPage);
                    awearness.GetPage($targetPage, function () {
                        $('#' + ($targetPage.attr('id')) + 'Scroll').mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "fixed", "yes", "yes", 5);
                        // Move the video for this page out of memory and into the dom
                        awearness.ShowVideo($targetPage, true);
                        awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    });
                    break;
                case '#IssuesArchivePage':
                case '#IssuesArchiveHivAidsPage':
                case '#IssuesArchiveCivilLibertiesPage':
                case '#IssuesArchiveFreedomOfExpressionPage':
                case '#IssuesArchiveDisasterPage':
                    $targetPage = $(targetPage);
                    awearness.GetPage($targetPage, function () {
                        awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    });
                    break;
                case '#ChangeAgentsPage':
                    $targetPage = member.$changeAgentsPage;
                    awearness.GetPage($targetPage, function () {
                        awearness.ShowVideo($targetPage, true);
                        awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    });
                    break;
                case '#WDYSNewsPage':
                    $targetPage = member.$wdysPage;
                    if (member.$wdysIframe.attr('src') != g_settings.WdysNewsUrl) {
                        member.$wdysIframe.attr('src', g_settings.WdysNewsUrl);
                    }
                    awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    break;
                case '#WhereDoYouStand':
                    $targetPage = member.$wdysPage;
                    if (member.$wdysIframe.attr('src') != g_settings.WdysUrl) {
                        member.$wdysIframe.attr('src', g_settings.WdysUrl);
                    }
                    awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    break;
                case '#PartnerApplication':
                    $targetPage = member.$partnerApplication;
                    awearness.PageTransition($targetPage, g_settings.transitionDuration, function () {
                        var $iframe = $('iframe', $targetPage);
                        if ($iframe.attr('src') == "") {
                            $iframe.attr('src', "PartnershipApplication.aspx");
                        }
                    });
                    break;
                case '#ProductDonation':
                    $targetPage = member.$productDonation;
                    awearness.PageTransition($targetPage, g_settings.transitionDuration, function () {
                        var $iframe = $('iframe', $targetPage);
                        if ($iframe.attr('src') == "") {
                            $iframe.attr('src', "ProductDonation.aspx");
                        }
                    });
                    break;
                case '#Sweeps':
                    $targetPage = member.$sweeps;
                    awearness.PageTransition($targetPage, g_settings.transitionDuration, function () {
                        var $iframe = $('iframe', $targetPage);
                        if ($iframe.attr('src') == "") {
                            $iframe.attr('src', "Sweeps.aspx");
                        }
                    });
                    break;
                case '#SweepsSundance':
                    $targetPage = member.$sweepsSundance;
                    awearness.PageTransition($targetPage, g_settings.transitionDuration, function () {
                        var $iframe = $('iframe', $targetPage);
                        if ($iframe.attr('src') == "") {
                            $iframe.attr('src', "SweepsSundance.aspx");
                        }
                    });
                    break;
                case '#MerchandisePage':
                    $targetPage = member.$merchandisePage;
                    awearness.GetPage($targetPage, function () {
                        awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    });
                    break;
                case '#ContactPage':
                    $targetPage = member.$contactPage;
                    awearness.GetPage($targetPage, function () {
                        awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    });
                    break;
                default:
                    $targetPage = $(targetPage);
                    if ($targetPage.length == 0) {
                        targetPage = "#HomePage";
                        $targetPage = member.$homePage;
                    }
                    awearness.GetPage($targetPage, function () {
                        awearness.PageTransition($targetPage, g_settings.transitionDuration);
                    });
                    break;
            }

            // Trigger Omniture.
            awearness.OmnitureTrigger($('.OmnitureData', $targetPage).html());
        },

        /// <summary>
        /// Changes the Main Page area with animation effects.
        /// </summary>
        PageTransition: function ($targetPage, duration, callback) {
            var $stages = $('[class^="Stage"]', $targetPage);
            var currentBackground = $('.BackgroundData', member.$currentPage).html();
            currentBackground = currentBackground ? currentBackground : "Mountains";
            var targetBackground = $('.BackgroundData', $targetPage).html();
            var animationStyle = $('.AnimationData', $targetPage).html();
            if (animationStyle && animationStyle.toLowerCase() == 'right')
                $targetPage.css('left', '100%');
            if (currentBackground != targetBackground) {
                var $backgrounds = $('#Backgrounds img');
                var $currentBackground = $backgrounds.filter('.' + currentBackground);
                var $targetBackground = $backgrounds.filter('.' + targetBackground);
                $currentBackground.stop().animate({ left: '-100%' }, duration, function () {
                    $currentBackground.css({ left: '100%' });
                });
                $targetBackground.stop().animate({ left: '0%' }, duration);
            }
            member.$currentPage.stop().animate({ left: '-100%' }, duration, function () {
                // Set all sub animations to start point.
                $stages.each(function () {
                    var $this = $(this);
                    if ($this.data('originalRight') == undefined) {
                        var origRight = $this.css('right').indexOf("%") == -1 ? parseFloat($this.css('right')) / $this.parent().width() * 100 + "%" : $this.css('right');
                        $this.data('originalRight', origRight);
                    }
                    $this.css('right', '-100%');
                });
                $targetPage.delay(duration / 1.5).animate({ left: '0%' }, duration, function () {
                    awearness.SecondaryPageTransition($stages, duration, callback);
                });
                member.$currentPage = $targetPage;
            });
        },

        /// <summary>
        /// Executes secondary animation effects on current page.
        /// </summary>
        SecondaryPageTransition: function ($stages, duration, callback) {
            // Serial animation function.
            function staggerAnimation($stages, index) {
                var $currentStage = $($stages[index]);
                $currentStage.animate({ right: $currentStage.data('originalRight') }, duration / $stages.length, function () {
                    if (++index < $stages.length)
                        staggerAnimation($stages, index);
                    else if (typeof (callback) == "function")
                        callback();

                });
            }

            if ($stages.length > 0) {
                staggerAnimation($stages, 0);
            }
            else {
                if (typeof (callback) == "function")
                    callback();
            }
        },

        /// <summary>
        /// Controlls Viewport left right scrolling viewports
        /// </summary>
        InitArchiveViewPorts: function ($targetPage) {
            var mover;
            var velocity;

            function MouseDown(startVelocity, button) {
                var $viewPort = $(button).parent();
                var $content = $('.ArchiveContent', $viewPort);
                velocity = startVelocity;
                clearInterval(mover);
                $content.stop();

                mover = setInterval(function () {
                    var contentLeft = parseInt($content.css('left'));
                    if (contentLeft <= 0 && velocity > 0 ||
                     contentLeft + $content.width() > $viewPort.width() && velocity < 0) {
                        var newPos = contentLeft + velocity;
                        if (newPos > 0) newPos = 0;
                        if (newPos < ($content.width() - $viewPort.width()) * -1) newPos = ($content.width() - $viewPort.width()) * -1;
                        $content.css('left', newPos);
                    }
                }, g_settings.frameRate);
            }

            function MouseUp() {
                var $viewPort = $(this).parent();
                var $content = $('.ArchiveContent', $viewPort);
                var $columns = $('.archiveColumn', $content);
                var columnWidth = $columns.width() + parseFloat($columns.css('margin-right')) + parseFloat($columns.css('margin-left'));
                // Stop interval mover.
                clearInterval(mover);
                // Animate to a stop with nearest column.
                var nearestColumnPos = parseInt($content.css('left')) / columnWidth;
                nearestColumnPos = velocity < 0 ? Math.floor(nearestColumnPos) : Math.ceil(nearestColumnPos);
                var newPos = nearestColumnPos * columnWidth;
                if (newPos > 0) newPos = 0;
                if (newPos < ($content.width() - $viewPort.width()) * -1) newPos = ($content.width() - $viewPort.width()) * -1;
                $content.animate({ left: newPos }, 750);

            }

            function MouseLeave() {
                clearInterval(mover);
            }

            // Init Needed CSS values.
            $('.ArchiveContent').css('position', 'absolute').css('left', 0);

            // Set Event Handlers.
            var $arrowRight = $('.ArchiveViewPort .ArrowRight', $targetPage);
            $arrowRight.mousedown(function () { MouseDown(-30, this) }).addTouch();
            $arrowRight.mouseup(MouseUp).addTouch();
            $arrowRight.mouseleave(MouseLeave);
            var $arrowLeft = $('.ArchiveViewPort .ArrowLeft', $targetPage);
            $arrowLeft.mousedown(function () { MouseDown(30, this) }).addTouch();
            $arrowLeft.mouseup(MouseUp).addTouch();
            $arrowLeft.mouseleave(MouseLeave);

            // Make Draggable.
            var $archiveContents = $(".ArchiveContent");
            $archiveContents.addTouch();
            $archiveContents.draggable();
            $(".ArchiveContent").mousedown(function () {
                $this = $(this);
                MPrintln($this.closest('.ArchiveViewPort').offset().left);
                MPrintln($this.closest('.ArchiveViewPort').offset().left + $this.width());
                $this.draggable({
                    axis: "x",
                    containment: [$this.closest('.ArchiveViewPort').offset().left - $this.width() + $this.closest('.ArchiveViewPort').width(),
                        null,
                        $this.closest('.ArchiveViewPort').offset().left,
                        null]
                });
            });
            $(".ArchiveContent").mouseup(function () {
                $(this).draggable({ dissabled: true });
            });
        },

        /// <summary>
        /// Allows for easy mouse over with image base.
        /// </summary>
        SetMouseOvers: function () {
            function mouseEnter() {
                var src = $(this).attr('src');
                if (src.indexOf("_over") == -1) {
                    src = src.substr(0, src.length - 4) + "_over" + src.substr(src.length - 4);
                    $(this).attr('src', src);
                }
            }

            function mouseLeave() {
                var src = $(this).attr('src');
                if (src.indexOf("_over") != -1) {
                    src = src.replace("_over", "");
                    $(this).attr('src', src);
                }
            }

            $mouseOvers = $('.MouseOver');
            $mouseOvers.mouseenter(mouseEnter);
            $mouseOvers.mouseleave(mouseLeave);
        },

        /// <summary>
        /// Executes Omniture Code.
        /// </summary>
        OmnitureTrigger: function (pageName) {
            if (s && g_settings.SendOmnitureData) {
                s.server = 'www.awearness.com';
                s.channel = 'awearness';
                s.pageName = pageName;
                s.setLinkInternalFilters('javascript:,awearness.com,kennethcole.com,imageg.net,gspt.net,gsipartners.com,awearnessblog.com,kcpcustomerservice.com');
                s.t();
            }
        }
    };

} ();


/// <summary>
/// Debug Functions
/// </summary>
function MOut(value) {
    $('#Monitor').html(value);
}
function MPrintln(value) {
    $monitor = $('#Monitor');
    $monitor.html($monitor.html() + "<BR>" + value);
}
