﻿/// <reference path="jquery-1.3.2-vsdoc.js" />
/// <reference path="jquery.lightbox-0.5.js" />
/// <reference path="jquery.watermarkinput.js" />
/// <reference path="jquery-ui-1.7.1.custom.min.js" />
$(function() {
    $('a.lightbox').lightBox({
        imageLoading: '/library/images/lightbox-ico-loading.gif',
        imageBtnPrev: '/library/images/lightbox-btn-prev.gif',
        imageBtnNext: '/library/images/lightbox-btn-next.gif',
        imageBtnClose: '/library/images/lightbox-btn-close.gif',
        imageBlank: '/library/images/lightbox-blank.gif'
    });

    $('input.search').Watermark("Search...");

    $('.buttonLink').each(function() {
        var currentElement = $(this);
        var color;
        var parentCount = 0;
        do {
            color = currentElement.css("background-color");
            currentElement = currentElement.parent();
            parentCount++;
        } while (color == "transparent" && currentElement != null);


        $(this).data("former-background", color);
        $(this).data("reset-bg", parentCount > 1);
    });
    $('.buttonLink').hover(
	    function() {
	        $(this).animate(
	            { backgroundColor: '#0DB4D5' },
	            { queue: false, duration: 'fast', easing: 'swing' }
	        );
	    },
	    function() {
	        var color = $(this).data("former-background");
	        var resetAfterAnimation = $(this).data("reset-bg");

	        var animateOptions = { queue: false, duration: 'slow' };
	        if (resetAfterAnimation == true) {
	            animateOptions["complete"] = function() { $(this).css("background-color", "transparent"); };
	        }
	        $(this).animate({ backgroundColor: color }, animateOptions);
	        if (resetAfterAnimation == true) {
	            $(this).css("background-color", "transparent");
	        }
	    }
    );
    $('#news-content').height($('#news-latest').height() + 8);
    $("div#flyout-container").dialog({
        autoOpen: false,
        modal: true,
        width: 800,
        height: 600,
        buttons: {
            "Close": function() {
                $(this).dialog("close");
                window.location.reload();
            }
        }
    });
    $('a.flyout-link').click(function() {
        $("div#flyout-container")
            .html('<iframe id="modalIframeId" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />')
            .dialog('option', 'title', this.title)
            .dialog("open");
        $("#modalIframeId").ready(function() {
        });
        $("#modalIframeId").load(function() {
            if ($(this).data("open-parent") == true) {
                var $dialog = $("#modalIframeId");


                $dialog.dialog("close");
                var newLocation = $dialog.get(0).document.location.href;
                window.location.href = newLocation;
                return false;
            } else {
                var existingButtons = $('div#flyout-container').dialog('option', 'buttons')

                $("#modalIframeId").contents().find(":submit.dialog-hosted").each(function() {
                    var button = $(this);
                    if (button.hasClass("open-parent") == true) {
                        button.click(function() {
                            $("#modalIframeId").data("open-parent", true);
                            return true;
                        });
                    }
                    existingButtons[$(this).attr("value")] = function() {

                        button.click();
                    }
                }).hide();
                $('div#flyout-container').dialog('option', 'buttons', existingButtons);
            }
        });
        $("#modalIframeId").attr("src", this.href);

        return false;
    });
    $('div.pop_body').dialog({
        width: 630,
        modal: true,
        autoOpen: false,
        dialogClass: 'pop_body'
    });
    $('a.flyout').click(function() {
        var elementId = $(this).attr("href");
        var $dialog = $(elementId);
        $dialog.dialog('open');
    });
});
