﻿/*-------------------------------------------------------------------------------
Create by leo
Version 1.0
usage:
-------------------------------------------------------------------------------*/
(function ($) {
    //0 means hide; 1 means show;
    var popupStatus = 0;

    var methods = {
        myPopupShow: function (options) {
            var settings = {
                'localtion': 'top',
                'background-color': 'blue'
            };
            return this.each(function () {
                var $this = $(this);
                if (options) {
                    $.extend(settings, options);
                }
                $this.mouseenter(function () {
                    if (!jQuery.isEmptyObject($("#tinymask"))) {
                        $("body").prepend(methods.myMask);
                    }

                    $(window).bind("resize", function () {
                        var left = $('#related').position().left;
                        methods._setPosition($("#popbox"), left - 50, 0, 2000);
                        methods._setPosition($("#subbox"), $("#header_middle").position().left, $("#header_middle").position().top, 1500);
                    });

                    // set the position for popbox.
                    var left = $this.position().left;
                    methods._setPosition($("#popbox"), left - 50, 0, 2000);

                    $("#tinycontent").load('/Interstitial/Popup.htm',
                            function (response, status, xhr) {
                                if (status == "success") {
                                    $(".popup_middle div").hover(function () {
                                        var i = $(".popup_middle div").index(this);
                                        $("#subbox").corner("round 9px");
                                        $("#subbox .jquery-corner div").css({ "border-color": "#23a68e", "filter": "alpha(opacity=70)" });
                                        $(".popup_top_current").addClass("popup_top").removeClass("popup_top_current");
                                        switch (i) {
                                            case 0:
                                                {
                                                    $("#subboxcontent", "#subbox").load('/Interstitial/Novolog.htm');
                                                    $(".popup_top").addClass("popup_top_current").removeClass("popup_top");
                                                    $(this).addClass('current0').siblings().removeClass('current1 current2 current3');
                                                }
                                                break;
                                            case 1:
                                                $("#subboxcontent", "#subbox").load('/Interstitial/NovologMix.htm');
                                                $(this).addClass('current1').siblings().removeClass('current0 current2 current3');
                                                break;
                                            case 2:
                                                $("#subboxcontent", "#subbox").load('/Interstitial/NonInsulinTherapy.htm');
                                                $(this).addClass('current2').siblings().removeClass('current0 current1 current3');
                                                break;
                                            case 3:
                                                $("#subboxcontent", "#subbox").load('/Interstitial/Cornerstone4Care.htm');
                                                $(this).addClass('current3').siblings().removeClass('current0 current1 current2');
                                                break;
                                            default:
                                        }
                                        $("#tinymask").fadeTo("fast", 1);
                                        $("#subbox").fadeIn("fast");

                                        methods._setPosition($("#subbox"), $("#header_middle").position().left, $("#header_middle").position().top, 1500);
                                    }).click(function () {
                                        var i = $(".popup_middle div").index(this);
                                        switch (i) {
                                            case 0:
                                                {
                                                    window.open("http://www.novolog.com", "", "menubar=1,resizable=1");
                                                    //parent.location.href = "http://novolog.nnittest.com";
                                                }
                                                break;
                                            case 1:
                                                {
                                                    window.open("http://www.novologmix70-30.com", "", "menubar=1,resizable=1");
                                                    //                                                parent.location.href = "http://Novologmix.nnittest.com";
                                                    break;
                                                }
                                            case 2:
                                                {
                                                    window.open("http://www.Victoza.com", "", "menubar=1,resizable=1");
                                                    // parent.location.href = "http://www.Victoza.com";
                                                    break;
                                                }
                                            case 3:
                                                {
                                                    window.open("http://www.cornerstones4care.com", "", "menubar=1,resizable=1");
                                                    //parent.location.href = "http://www.cornerstones4care.com";
                                                    break;
                                                }
                                            default:
                                        }
                                    });
                                }
                            });


                    $('#tinymask').mouseenter(function () {
                        if ($('#popbox').is(':visible'))
                            methods.myPopupHide();
                    }).css({
                        "height": $(document).height()
                    }).fadeTo("fast", 0, function () {
                        $("#popbox").fadeIn("fast");
                    }); ;


                    $(document).keypress(function (e) {
                        if (e.keyCode == 27 && popupStatus == 1) {
                            methods.myPopupHide();
                        }
                    });

                    popupStatus = 1;
                })
            });
        },
        mySubPopup: function () {

        },
        myContent: function () {
            var tPopup = "";
            return tPopup;
        },
        myMask: function () {
            var mask = "<div id='tinymask'></div>" +
                       "<div id='popbox'><div id='tinycontent'></div></div>" +
                       "<div id='subbox'><div id='subboxcontent'></div></div>";
            return mask;
        },
        myPopupHide: function () {
            $("#subbox,#tinymask,#popbox").remove();
            popupStatus = 0;
            $(window).unbind("resize");
        },
        _setPosition: function (obj, x, y, z) {
            obj.css("left", x);
            obj.css("top", y);
            if (z > 0) {
                obj.css("z-index", z);
            }
        }
    };

    $.fn.myPopup = function (method) {
        // Method calling logic
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.myPopupShow.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.myPopup');
        }
    };

})(jQuery);
