﻿(function($) {
    $.fn.slideContact = function(options) {

        var 
		  defaults = {
		      TabFixed: false,
		      SlideEffectIn: 'easeOutBounce',
		      SlideEffectOut: 'easeOutBounce'
		  },
		  settings = $.extend({}, defaults, options);

        this.each(function() {
            var $this = $(this);
            var title = this.title;


            var DefaultHeight = $("#center-column").height();
            DefaultHeight = DefaultHeight + "px";
            $(".DNNPlusContactArea").css('height', '0px');



            $("a.DNNPlusContact,a.DNNPlusContactImg").click(function(event) {
                event.preventDefault();

                if ($(".DNNPlusContactArea").css('height') == '0px') {
                    if (settings.TabFixed) {
                        $('html, body').animate({ scrollTop: 0 }, 'fast');
                    }
                    SlideIn(DefaultHeight);
                }
                else
                { SlideOut(); }
            });

            $("a.DNNPlusSlideContactLink").click(function(event) {
                event.preventDefault();
                if ($(".DNNPlusContactArea").css('height') == '0px') {
                    $('html, body').animate({ scrollTop: 0 }, 'fast');
                    SlideIn(DefaultHeight);
                }
            });



            function SlideIn(DefaultHeight) {
                $(".DNNPlusContactArea").animate({ height: DefaultHeight }, { queue: false, duration: 1700, easing: 'easeOut' + settings.SlideEffectIn });
                $("a.DNNPlusContact, a.DNNPlusContactImg ").animate({ top: DefaultHeight }, { queue: false, duration: 1700, easing: 'easeOut' + settings.SlideEffectIn });

                if ($(".DNNPlusBackgroundPopup") != null) {
                    $(".DNNPlusBackgroundPopup").css({ "opacity": "0.7" });
                    $(".DNNPlusBackgroundPopup").fadeIn("slow");
                }

                if ($(".imgToggle") != null) {
                    if ($(".imgToggle").attr("src") != null) {
                        var newPath = $(".imgToggle").attr("src").replace("open.png", "Close.png");
                        $(".imgToggle").attr("src", newPath);
                    }
                }

                if ($(".DNNPlusBackgroundPopup") != null) {
                    $(".DNNPlusBackgroundPopup").animate({ top: DefaultHeight }, { queue: false, duration: 1700, easing: 'easeOut' + settings.SlideEffectIn });
                }
                if (settings.TabFixed == "True") {
                    $("a.DNNPlusContact,a.DNNPlusContactImg").css({ "position": "absolute" });
                }
            }

            function SlideOut() {
                $(".DNNPlusContactArea").animate({ height: "0px" }, { queue: false, duration: 1700, easing: 'easeOut' + settings.SlideEffectOut });
                $("a.DNNPlusContact, a.DNNPlusContactImg").animate({ top: "0px" }, { queue: false, duration: 1700, easing: 'easeOut' + settings.SlideEffectOut });
                if ($(".DNNPlusBackgroundPopup") != null) {
                    $(".DNNPlusBackgroundPopup").fadeOut("slow");
                }
                if ($(".imgToggle") != null) {
                    if ($(".imgToggle").attr("src") != null) {
                        var newPath = $(".imgToggle").attr("src").replace("Close.png", "open.png");
                        $(".imgToggle").attr("src", newPath);
                    }
                }
                if ($(".DNNPlusBackgroundPopup") != null) {
                    $(".DNNPlusBackgroundPopup").animate({ top: "0px" }, { queue: false, duration: 1700, easing: 'easeOut' + settings.SlideEffectOut });
                }

                if (settings.TabFixed == "True") {
                    $("a.DNNPlusContact,a.DNNPlusContactImg").css({ "position": "fixed" });
                }
            }



        });
        // returns the jQuery object to allow for chainability.
        return this;
    }
})(jQuery);
