﻿jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
};

var alreadyMemberTimeOut;


$(document).ready(function() {
    // lightbox overlay bindings
    $('#ctl00_ContentPlaceHolder3_child_only_module').mouseover(function() {
        $(this).css({ 'background-position': 'bottom' })
    }).mouseout(function() {
        $(this).css({ 'background-position': 'top' })
    });


    $.fn.fancybox.defaults.callbackOnStart = function() {

        var temp = $("#fancy_frame").attr("src");
        $("#fancy_frame").attr("src", "").attr("src", temp);

    }
    $.fn.fancybox.defaults.callbackOnShow = function() {

        var temp = $("#fancy_frame").attr("src");
        $("#fancy_frame").attr("src", "").attr("src", temp);

    }

    if($.trim($('#divRateInfo').text()) != "") {
        $("#master-footer-spacer").hide();
    }

    $("#ctl00_ContentPlaceHolder3_child_only_module").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 980,
		    'frameHeight': 500,
		    'centerOnScroll': false,
		    'title': 'Need coverage for a child under the age of 19?'
		});

	   $("#details_only_module").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 980,
		    'frameHeight': 500,
		    'centerOnScroll': false,
		    'title': 'Need coverage for a child under the age of 19?'
		});

		
    $(".openCalc").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 600,
		    'frameHeight': 600,
		    'centerOnScroll': false
		});

    $(".openQuestions").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 700,
		    'frameHeight': 500,
		    'centerOnScroll': false,
		    'hideOnOverlayClick': false
		});

    $(".openLocations").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 950,
		    'frameHeight': 500,
		    'centerOnScroll': false
		});

    /*$(".myHealthManager").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 1005,
		    'frameHeight': 685,
		    'centerOnScroll': false
		});*/

    $(".openEnrollmentKit").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 650,
		    'frameHeight': 450,
		    'centerOnScroll': false
		});

    $(".openExploreRegions").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 500,
		    'frameHeight': 400,
		    'centerOnScroll': false
		});

    $(".link-connected-video").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 620,
		    'frameHeight': 500,
		    'centerOnScroll': false
		});


    $(".nav-explore").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 400,
		    'frameHeight': 300,
		    'centerOnScroll': false
		});
    //    $(".apply_explore").fancybox(
    //		{ 'hideOnContentClick': false,
    //		    'frameWidth': 400,
    //		    'frameHeight': 300,
    //		    'centerOnScroll': false
    //		});
    $(".btnO").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 400,
		    'frameHeight': 300,
		    'centerOnScroll': false
		});
    $("#home-coverage-and-costs").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 400,
		    'frameHeight': 300,
		    'centerOnScroll': false
		});

    $(".explore-regions-popup").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 400,
		    'frameHeight': 300,
		    'centerOnScroll': false
		});

    $("a[href='locations.aspx?iframe']").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 900,
		    'frameHeight': 500,
		    'centerOnScroll': false
		});
    $("a[href='QuestionAnswers.aspx?iframe']").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 700,
		    'frameHeight': 600,
		    'centerOnScroll': false
		});
    $("a[href='EnrollmentKit.aspx?iframe']").fancybox(
		{ 'hideOnContentClick': false,
		    'frameWidth': 420,
		    'frameHeight': 600,
		    'centerOnScroll': false
		});

    // questions and answers expanding/shrinking function

    $(".question").click(function() {
        var num = $(this).attr("question");

        if ($(this).hasClass("open")) {
            $(this).removeClass("open");
            $("div[question='" + num + "']").removeClass("open");
        }
        else {
            $(this).addClass("open");
            $("div[question='" + num + "']").addClass("open");
        }
        toggleAnswer(num);

    });


    $("#divQA img").click(function() {
        var num = $(this).attr("question");
        if ($(this).hasClass("open")) {
            $(this).removeClass("open");
            $("div[question='" + num + "']").removeClass("open");
        }
        else {
            $(this).addClass("open");
            $("div[question='" + num + "']").addClass("open");
        }
        toggleAnswer(num);

    });

    $(".nav-explore-selected").click(function() {
        return false;
    });


    function toggleAnswer(num) {
        if ($("div[answer='" + num + "']").is(":visible")) {
            $("div[answer='" + num + "']").slideUp("fast");
            $("img[question='" + num + "']").attr('src', '/healthinsurance/assets/images/plus.jpg');
        }
        else {
            $("div[answer='" + num + "']").slideDown("fast");
            $("img[question='" + num + "']").attr('src', '/healthinsurance/assets/images/minus.jpg');
        }
    }


    // Learn more popup

    $(".alreadyMemberHover").mouseover(function() {
        var p = $(".alreadyMemberHover").position();
        //			$( ".alreadyMember" ).css( "left", p.left + 100 );
        //			
        $(".alreadyMember").show();
        clearAlreadyMemberTimeOut();
    });

    $(".alreadyMember").mouseover(function() {
        clearAlreadyMemberTimeOut();
    });

    $(".alreadyMemberHover").mouseout(function() {
        startAlreadyMemberFadeOut();
    });

    $(".alreadyMember").mouseout(function() {
        startAlreadyMemberFadeOut();
    });



    window.over = false;


    $(".footerLink a").eq(4).mouseover(function() {
        var p = $(".footerLink:last").position();
        $(".learnMore").css({ "left": (p.left - 350),
            "top": (Number(p.top) - 330)
        }).show();
    }).mouseout(function() {

        setTimeout(function() {

            if (over)
                return;
            else
                $(".learnMore").hide();

        }, 500);

    });

    $(".learnMore").hover(

        function() {

            over = true;

            $(this).show();

        },

        function() {

            over = false;

            $(this).hide();

        }
    );


    $(".openLocations").mouseover(function() {
        var p = $(".openLocations").position();
        $(".tooltip-text").html($(".openLocations").attr("tooltip"));


        $(".tooltip").css("left", 475);
        $(".tooltip").css("top", 37);

        $(".tooltip").show();
    });

    $(".openLocations").mouseout(function() {
        $(".tooltip").fadeOut();
    });



    $(".openQuestions").mouseover(function() {
        var p = $(".openQuestions").position();
        $(".tooltip-text").html($(".openQuestions").attr("tooltip"));


        $(".tooltip").css("left", 570);
        $(".tooltip").css("top", 37);

        $(".tooltip").show();
    });

    $(".openQuestions").mouseout(function() {
        $(".tooltip").fadeOut();
    });



    $(".chat_image").live('click', function() {
        trackPage('channel=BUYKP:,pagename=BUYKP: Chat Now,events=event14');
        dcsMultiTrack('DCS.dcsuri', '/ChatNow.html', 'WT.ti', 'BuyKP: Click to Chat', 'WT.dl', '40', 'WT.z_st', 'ChatNow', 'WT.dl', '0', 'WT.ti', 'BuyKP: Click to Chat')
    });

    startSlideShow();

    if (typeof (openOverlay) != "undefined") {
        switch (openOverlay) {
            case "locations":
                setTimeout("$('.openLocations').click();", 500);
                break;
            case "questions-and-answers":
                setTimeout("$('.openQuestions').click();", 500);
                break;
            case "enrollment-kit":
                setTimeout("$('.openEnrollmentKit').click()", 500);
                break;
            case "explore-regions-select":
                setTimeout("$('#explore_id').click()", 500);
                break;
        }
    }

});


function startAlreadyMemberFadeOut()
{
	alreadyMemberTimeOut = setTimeout( "alreadyMemberFadeOut()", 2000 );
}

function alreadyMemberFadeOut()
{
	$( ".alreadyMember" ).fadeOut();
}

function clearAlreadyMemberTimeOut()
{
	clearTimeout( alreadyMemberTimeOut );
}

function displayInfo(current) 
{
    if ($(current).next().is(":hidden")) {
        $(current).next().slideDown("slow");
    }
    else 
    {
        $(current).next().slideUp("slow");
    }
}


function toggleCoordinatedCare()
{
	if ( $( ".coordinateCareContent" ).is( ":visible" ) )
	{
		$( ".coordinateCareContent" ).slideUp( "fast" );
	}
	else
	{
		$( ".coordinateCareContent" ).slideDown( "fast" );
	}
	
	return false;
	
}



function slideSwitch() 
{
    var active = jQuery('#slideshow img.active');
	
	active.fadeOut(1000);

    if ( active.length == 0 ) active = jQuery('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var next =  active.next().length ? active.next()
        : jQuery('#slideshow img:first');

    active.addClass('last-active');

		
	next.addClass('active')
        .fadeIn( 1000, function() 
        {
            active.removeClass('active last-active');
        });
}

function startSlideShow()
{
	$( '#slideshow img.active' ).show();
	startInterval();
	setTimeout("startInterval()", 5000);
}
	
function startInterval()
{
	setInterval( "slideSwitch()", 6000 );
}


