/* Author: Westbrook Johnson*/
function MM_openBrWindow_(theURL, winName, features) {
    window.open(theURL, winName, features);
}


function addFloodlight(tagcat, tagsrc, tagtype) {
 var axel = Math.random() + "";
 var a = axel * 10000000000000;
 if (arguments[1] == null)
     tagsrc = '2644366';
 if (arguments[2] == null)
     tagtype = 'andro995';
 var src = "http://fls.doubleclick.net/activityi;src=" + tagsrc + ";type=" + tagtype + ";cat=" + tagcat + ";ord=" + a + "?";
 
 var iframe = document.createElement("iframe");
	iframe.setAttribute("src", src);
	iframe.setAttribute("width", "1");
	iframe.setAttribute("height", "1");
	iframe.setAttribute("frameborder", "0");
	iframe.setAttribute("style", "display:none");
	document.body.appendChild(iframe);			
 return false;
}


var stopSpeed = 8000;
var featureStop = 0;
var featureTime = setInterval('featureSwitch()', stopSpeed);
$(document).ready(function() {
    $.fn.placeholder = function() {

        // quit if there's support  for html5 placeholder
        if (this[0] && 'placeholder' in document.createElement('input')) return;

        return this
            .live('focusin', function() {
                if ($(this).val() === $(this).attr('placeholder')) {
                    $(this).val('');
                }
            }).live('focusout', function() {
                if ($(this).val() === '') {
                    $(this).val($(this).attr('placeholder'));
                }
            }).focusout();
    }
    $('input[placeholder]').placeholder();
    $('.utility .small a').click(function(event) {
        event.preventDefault();
        $('.utility a').removeClass('current');
        $(this).addClass('current');
        $('#main').css('font-size', '13px');
    });
    $('.utility .medium a').click(function(event) {
        event.preventDefault();
        $('.utility a').removeClass('current');
        $(this).addClass('current');
        $('#main').css('font-size', '14px');
    });
    $('.utility .large a').click(function(event) {
        event.preventDefault();
        $('.utility a').removeClass('current');
        $(this).addClass('current');
        $('#main').css('font-size', '15px');
    });
    $('.features-nav a').click(function(event) {
        event.preventDefault();
        clearInterval(featureTime);
        $('.features-nav a').removeClass('active');
        $(this).addClass('active');
        $('div.androgel').attr('class', 'androgel').addClass($(this).attr('rel'));
        featureStop = $('.features-nav a').index(this) - 1;
        featureTime = setInterval('featureSwitch()', stopSpeed);
    });





    $('.isi-nav a').click(function(event) {
        event.preventDefault();
        $('.isi-nav a').removeClass('active');
        $(this).addClass('active');
        $('.isi-content li.isi-set').removeClass('active').css('margin-top', 0);
        $('.isi-content li.isi-set:eq(' + $('.isi-nav a').index(this) + ')').addClass('active');

    });

    //AndroGel 1 Safe Facts


    $('.isi-nav-sec a').click(function(event) {
        event.preventDefault();
        $('.isi-nav-sec a').removeClass('active');
        $(this).addClass('active');
        $('.isi-content-sec li.isi-set-sec').removeClass('active').css('margin-top', 0);
        $('.isi-content-sec li.isi-set-sec:eq(' + $('.isi-nav-sec a').index(this) + ')').addClass('active');

    });

    $("#162Tab").click(function() {
        $("#162Tab").attr("class", "on");
        $("#1Tab").attr("class", "");
        $("#1Holder").css("display", "none");
        $("#162Holder").css("display", "");
        return false;
    });

    $("#1Tab").click(function() {
        $("#1Tab").attr("class", "on");
        $("#162Tab").attr("class", "");
        $("#162Holder").css("display", "none");
        $("#1Holder").css("display", "");
        return false;
    });



//    $('.print-isi').mouseover(function() {
//        $(this).attr('href', 'pdf/FINAL_851-468203_AndroGel_Safety_Facts-MRLappvd111710.pdf');
//    });


    $('.facts-print-print').live('click', function() {
        setTimeout("$('body').removeClass('isi-print')", 500);
    });

    $(".faq_question").click(function() {
        $(this).toggleClass('faq_selected');
        $(this).next(".faq_answer").slideToggle("slow");
        s.linkTrackVars = 'prop4'; s.prop4 = this.text; (s.tl(this, 'o', 'Common Questions'));
        return false;
    });

    $(".application a").click(function(event) {
        event.preventDefault();
        $('#videoContent').show();
        $('#videoContent').css('top', $(this).position().top);
        $('#videoContent').css('left', $(this).position().left);

        swfobject.embedSWF("/swf/androgel_demo_shell.swf", "video", "600", "240", "9.0.0", "/swf/expressInstall.swf");
        // see closeDHTML function below to modify closing functionality
    });

    $('.diabetes_yes').click(function() {
        $('#q2_alternate').show();
        $('.diabetes_no').click(function() {
            $('#q2_alternate').hide();
        });
    });

    $('.asthma_yes').click(function() {
        $('#q3_alternate').show();
        $('.asthma_no').click(function() {
            $('#q3_alternate').hide();
        });
    });

    $("a[href*='adobe.com'], a[href*='pparx.org'], a[href*='fda.gov'], a[href*='aace.com'], a[href*='aafp.org'], a[href*='endo-society.org'], a[href*='aaksis.org'], a[href*='diabetes.org']").click(function(evt) {
        evt.preventDefault();
        var vw = {
        html: '<div id="wol-copy"><p>You are leaving the AndroGel.com website to a site that is not under the control of Abbott. Abbott is not responsible for the content of any such site or any further links from such site. Abbott is providing these links to you only as a convenience, and the inclusion of any link does not imply the endorsement of the linked site by Abbott. You should also be aware that the linked site may be governed by its own set of terms and conditions and privacy policy for which Abbott has no responsibility.</p><p>Conversely, the presence of this link does not imply the linked site&#39;s endorsement of AndroGel.com or Abbott.</p></div><div class="wol-btn-wrap"><p>Do you wish to leave this site?</p><div style="margin-top:10px;"><img src="' + applicationRoot + '/Common/images/exit_site_yes.png" class="linkProceed"  alt="YES" style="display:inline;cursor:pointer;"/><img src="' + applicationRoot + '/Common/images/exit_site_no.png" alt="NO" class="linkCancel"/></div></div>'
        };
        var srcObject = this;
        androgelUtil.modalWindow.onLoad = { callback: function(srcObj) {
            $('.linkProceed').click(function() {
                androgelUtil.modalWindow.closeModalWindow();
                //location.href = $(srcObj).attr('href');
                MM_openBrWindow_($(srcObj).attr('href'), '', '');
            });
            $('.linkCancel').click(function() { androgelUtil.modalWindow.closeModalWindow(); });
        },
            callbackData: srcObject
        };
        androgelUtil.modalWindow.showModalContent(vw, { width: 540, height: 384, "margin-left": -270, "background": "#ebfbff" });
    });


    $("a[rel='video']").click(function(evt) {
        evt.preventDefault();
        var videoP = {
        html: '<div id="wol-copy"><p>The video that will appear from this callout is currently routing as its own project for approval under project number 852-584822. Once approved, that video will be available through these callouts.</p></div>'
        };

        androgelUtil.modalWindow.showModalContent(videoP, { width: 540, height: 384, "margin-left": -270, "background": "#ebfbff" });
    });

    $("a[rel='hcpExit']").click(function(evt) {
        evt.preventDefault();
        var vw = {
        html: '<div id="wol-copy"><p>You are about to enter a site that is for U.S. Healthcare Professionals only. By selecting &quot;Yes&quot; below, you certify that you are a Healthcare Professional and that you wish to proceed to the Healthcare Professionals Only section of this site. Products or treatments described on this site are available in the U.S. but may not be available in all other countries. I am a licensed Healthcare Professional and wish to proceed to the Healthcare Professionals Only section of this site.</p></div><div class="wol-btn-wrap"><div style="margin-top:10px;"><img src="'+applicationRoot+'/Common/images/exit_site_yes.png" class="linkProceed"  alt="YES" style="display:inline;cursor:pointer;"/><img src="'+applicationRoot+'/Common/images/exit_site_no.png" alt="NO" class="linkCancel"/></div></div>'
        };
        var srcObject = this;
        androgelUtil.modalWindow.onLoad = { callback: function(srcObj) {
            $('.linkProceed').click(function() {
                androgelUtil.modalWindow.closeModalWindow();
                location.href = $(srcObj).attr('href');
            });
            $('.linkCancel').click(function() { androgelUtil.modalWindow.closeModalWindow(); });
        },
            callbackData: srcObject
        };
        androgelUtil.modalWindow.showModalContent(vw, { width: 540, height: 384, "margin-left": -270, "background": "#ebfbff" });
    });
    
    
//    $(".utility .print a").click(function() {

//        if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
//            window.open("Print.aspx?url=" + window.location.pathname, "Print");
//        }
//        else {
//            $("#printContent").val(escape($("#main").html()));
//            document.forms['printContentForm'].submit();
//        }

//        return false;
//    });    
});

var featureSwitch = function() {
    featureStop++;
    $('.features-nav a').removeClass('active');
    $('.features-nav a:eq(' + featureStop + ')').addClass('active');
    $('div.androgel').attr('class', 'androgel').addClass($('.features-nav a:eq(' + featureStop + ')').attr('rel'));
    if (featureStop == 2) {
        featureStop = -1;
    }
}

var closeDHTML = function(type) {
    $('#videoContent').hide();
}

// Added modal: 10/25/2010
// Wes Reid
var androgelUtil = {
    modalWindow: {

        screen: null,

        showScreen: function() {
            if (!this.screen) {
                this.screen = $("<div id=\"OverlayScreen\" class=\"overlayScreen closeModal\"></div>");
                $(this.screen).css({ opacity: .75, height: $(document).height() });
                $(this.screen).appendTo("body");
            }
            $(this.screen).show();
        },

        hideScreen: function() {
            if (this.screen)
                $(this.screen).hide();
        },
        onLoad: { callback: null, callbackData: null },
        onClose: null,

        modalContentContainer: null,
        modalViewStack: [],
        modalView: {
            container: null,
            onLoad: { callback: null, callbackData: null },
            onClose: null,
            view: null,
            html: null,
            css: null
        },

        showModalContent: function(view, css) {

            this.modalView.onClose = this.onClose;
            this.modalView.onLoad = this.onLoad;
            this.modalView.view = view;
            this.modalView.css = css;
            this.modalViewStack.push($.extend({}, this.modalView));

            this.modalViewStack[this.modalViewStack.length - 1].container = $('<div id="' + ('modal' + (new Date()).getTime().toString()) + '" class="overlayScreenContentContainer"></div>');
            this.modalViewStack[this.modalViewStack.length - 1].container.css({ top: ($(document).scrollTop() + 20) });
            this.modalViewStack[this.modalViewStack.length - 1].container.appendTo("body");
            androgelUtil.modalWindow.modalContentContainer = this.modalViewStack[this.modalViewStack.length - 1].container;
            if (this.modalViewStack.length > 1)
                this.modalViewStack[this.modalViewStack.length - 2].container.hide();

            var renderCallback = function(data) {
                if (androgelUtil.modalWindow.modalViewStack.length == 1)
                    androgelUtil.modalWindow.showScreen();
                data = "<a href=\"#\" class=\"closeModal\">X</a>" + data;
                $(androgelUtil.modalWindow.modalContentContainer).html(data);
                if (css)
                    $(androgelUtil.modalWindow.modalContentContainer).css(css);
                $(androgelUtil.modalWindow.modalContentContainer).show();
                if (typeof androgelUtil.modalWindow.onLoad.callback === "function") {
                    androgelUtil.modalWindow.onLoad.callback(androgelUtil.modalWindow.onLoad.callbackData);
                    androgelUtil.modalWindow.onLoad.callback = null;
                    androgelUtil.modalWindow.onLoad.callbackData = null;
                }
                $(".closeModal").click(androgelUtil.modalWindow.closeModalWindow);
                androgelUtil.modalWindow.onLoad = { callback: null, callbackData: null };
                androgelUtil.modalWindow.onClose = null;
            };
            if (view.src)
                $.get(view.src, renderCallback);
            else if (view.html)
                renderCallback(view.html);
        },

        reviveContainer: function() {
            $(androgelUtil.modalWindow.modalViewStack[androgelUtil.modalWindow.modalViewStack.length - 1].container).fadeIn(500);
        },

        closeModalWindow: function() {
            if (androgelUtil.modalWindow.modalViewStack.length > 0) {
                androgelUtil.modalWindow.modalView = androgelUtil.modalWindow.modalViewStack.pop();
                androgelUtil.modalWindow.onClose = androgelUtil.modalWindow.modalView.onClose;
                androgelUtil.modalWindow.onLoad = androgelUtil.modalWindow.modalView.onLoad;
                androgelUtil.modalWindow.modalContentContainer = androgelUtil.modalWindow.modalView.container;

                if (typeof androgelUtil.modalWindow.onClose === "function") {
                    androgelUtil.modalWindow.onClose();
                    androgelUtil.modalWindow.onClose = null;
                }
                if (androgelUtil.modalWindow.modalContentContainer) {
                    $(androgelUtil.modalWindow.modalContentContainer).fadeOut(500);
                    $(androgelUtil.modalWindow.modalContentContainer).remove();
                }
                if (androgelUtil.modalWindow.screen && androgelUtil.modalWindow.modalViewStack.length == 0)
                    $(androgelUtil.modalWindow.screen).fadeOut(500);
                else
                    androgelUtil.modalWindow.reviveContainer();
            }
        }

    }
}
