var pageVars = {
current:'n'
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}



function templateLoad() {

   
    //default = do nothing	
	/*
	if( document.getElementById("nav") ){
		for( var i=0; (li = document.getElementById("nav").getElementsByTagName("li")[i]); i++ ){
			if ( li.getElementsByTagName("ul") ){
				li.onmouseover = function(){ openSubNav(this); }
				li.onmouseout = function(){ closeSubNav(this); }
			}
		}
}


$("#suzeCalculatorDialog").dialog({
           autoOpen: false,
           modal: true,
           height: 600,
           width: 950,
           buttons: {
				"Close" : function() {
					$( this ).dialog( "close" );
					window.location.href="/suzelanding.aspx?amount=1,000";
				}
			}

       });
    */   
    //Setting value for source code
    var sco=getCookie('sourceCodeTest');
    $('#sCode').val(sco);

    //Initializing Global Nav
    if ($('.globalNav .main').length > 0) {
        $('.main .Information').mouseover(function() {
            $('.main li a').removeClass('active');
            $('.infoAnchor').addClass('active');
            $('.InformationSection').show();
        });

        //Setting About Us Sub nav
        $('.main .AboutUs').mouseover(function() {
            $('.main li a').removeClass('active');
            $('.aboutAnchor').addClass('active');
            $('.AboutUsSection').show();
        });

        //Setting Additional insurance Sub nav
        $('.main .AdditionalInsurance').mouseover(function () {
            $('.main li a').removeClass('active');
            $('.aditionalInsuranceAnchor').addClass('active');
            $('.AdditionalInsuranceSection').show();
        });

        //Setting mouse out for navigation
        $('.main .AboutUsSection, .main .InformationSection').mouseout(function() {
            $('.main li a').removeClass('active');
            $('.subNav').hide();
            setActive();
        });
        $('#header,.ClientCenter,.StartQuote,.heroBox,.formBox,#ABLeft').mouseover(function() {
            $('.main li a').removeClass('active');
            $('.subNav').hide();
            setActive();
        });
    }
    //Suze Global Navigation Behavior
    else if ($('.globalNav .mainSuze').length > 0) {
        $('.mainSuze .Information').mouseover(function() {
            $('.mainSuze li a').removeClass('over');
            $('.infoAnchor').addClass('over');
            $('.mainSuze .InformationSection').show();
        });

        //Setting About Us Sub nav
        $('.mainSuze .AboutUs').mouseover(function() {
            $('.mainSuze li a').removeClass('over');
            $('.aboutAnchor').addClass('over');
            $('.mainSuze .AboutUsSection').show();
        });

        //Setting About Us Sub nav
        $('.mainSuze .AdditionalInsurance').mouseover(function () {
            $('.mainSuze li a').removeClass('over');
            $('.aditionalInsuranceAnchor').addClass('over');
            $('.mainSuze .AdditionalInsuranceSection').show();
        });

        //Setting mouse out for navigation
        $('.mainSuze .AboutUsSection,').mouseleave(function() {
            $('.mainSuze li a').removeClass('over');
            $('.subNav').hide();
            setActive();
        });
        // ======================================
        //Setting mouse out for navigation
        $('.mainSuze .InformationSection,').mouseleave(function () {
            $('.mainSuze li a').removeClass('over');
            $('.subNav').hide();
            setActive();
        });

        //Setting mouse out for navigation
        $('.mainSuze .AdditionalInsurance,').mouseleave(function () {
            $('.mainSuze li a').removeClass('over');
            $('.subNav').hide();
            setActive();
        });
        // ======================================



        $('#header,.Login,.StartAQuote,.heroBox,.formBox,.Chinese,.Home,.videoContainer,#ABLeft').mouseover(function() {
            $('.mainSuze li a').removeClass('over');
            $('.mainSuze .subNav').hide();
            setActive();
        });
    }
    
//Initializing Partner Slides on Suze Home Page
if ($('#homeSlides').length > 0) {
    $('#homeSlides').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 5000,
        pager: '#nav'
    });
}

//Setting Selected value for Global Nav
if ($('.globalNav').length > 0) {
    var active = $('input[name="nav_active"]').val();
    pageVars.current=active;
    if(active!='')
    $('.' + active + ' a:first').addClass('active');
}
var _siteRoot = '/', _root = '/';

//Setting up hover states for the jumpBoxes on home10
if ($('.jumpBox').length > 0) {

    $('.jumpBox .inactive,.startQButton .inactive').mouseover(function() {
        $(this).hide();
        $(this).next('.active').show();
    });

    $('.jumpBox .active,.startQButton .active').mouseout(function() {
        $(this).hide();
        $(this).prev('.inactive').show();
    });
}




    if ($("div#hSlideShow").length > 0) {
        $("div#hSlideShow").slideView();
        setTimeout("playSlideshow()", 8000);
    }
    /*
	page = (window.top.location+"").split("/")[4];
	section = page.split(".")[0];
	section = section.split("_")[0];
	if (section == "learning") MM_swapImage('topnav_learning', '', '/images/nav/topnav_browsing_on.gif', 1);
	if (section == "ready") MM_swapImage('topnav_ready', '', '/images/nav/topnav_ready_on.gif', 1);
	if (section == "client") MM_swapImage('topnav_client', '', '/images/nav/topnav_client_on.gif', 1);
	if (section == "quote") MM_swapImage('topnav_client', '', '/images/nav/topnav_client_on.gif', 1);
	if (section == "about") MM_swapImage('topnav_about', '', '/images/nav/topnav_about_on.gif', 1);
	if (section == "chinese") MM_swapImage('topnav_chinese', '', '/images/nav/topnav_chinese_on.gif', 1);
	if (section == "login") MM_swapImage('topnav_login', '', '/images/nav/topnav_login_on.gif', 1);
    */
	// display login/logout state
	if (readCookie('loggedIn') == '1') {
	    $('#nav_login').hide();
	    $('#nav_logout').show();
	} else {
	    $('#nav_login').show();
	    $('#nav_logout').hide();
    }

}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
    
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openSubNav( obj ){
	if( child = obj.getElementsByTagName("ul")[0] ) child.style.display = "block";
}

function closeSubNav( obj ){
	if( child = obj.getElementsByTagName("ul")[0] ) child.style.display = "none";
}

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

var WindowObjectReferenceOfRequestedPopup;

function OpenRequestedPopup(strUrl) {
    var windowWidth, windowHeight, windowLeft, windowTop;

    if (typeof window.screenX == "number" && typeof window.innerWidth == "number") {
        windowWidth = window.innerWidth * .68;
        windowHeight = window.innerHeight * .68;
        windowLeft = window.screenX + window.innerWidth * .16;
        windowTop = window.screenY + window.innerHeight * .16;
    }
    else if (typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number") {
        windowWidth = document.documentElement.offsetWidth * .68;
        windowHeight = document.documentElement.offsetHeight * .68;
        windowLeft = window.screenLeft + document.documentElement.offsetWidth * .16;
        windowTop = window.screenTop - 50;
    }
    else {
        windowWidth = 500;
        windowHeight = 250;
        windowLeft = 60;
        windowTop = 40;
    };

    if (WindowObjectReferenceOfRequestedPopup == null || WindowObjectReferenceOfRequestedPopup.closed) {
        WindowObjectReferenceOfRequestedPopup = window.open(strUrl, 'calc', "top=" + windowTop + ",left=" + windowLeft + ",scrollbars=0,toolbar=0,status=0,width=765,height=295");
    }
    else {
        if (WindowObjectReferenceOfRequestedPopup.focus) {
            WindowObjectReferenceOfRequestedPopup.location = strUrl;
            setTimeout("WindowObjectReferenceOfRequestedPopup.focus();", 1000);
        };
    };
}

function OpenSuzeQuiz(){

    
        var en;

       
        if(window.location.href.indexOf('www')!=-1)
                en='prod';
        else if(window.location.href.indexOf('webchat')!=-1)
                en='dev';
        else
                en='prod';
        var strUrl='http://www.selectquotequiz.com/index_closedpanel.cfm?re='+en+"&squiz="+$("#sqQuiz").val();
            var windowWidth, windowHeight, windowLeft, windowTop;

    if (typeof window.screenX == "number" && typeof window.innerWidth == "number") {
        windowWidth = window.innerWidth * .68;
        windowHeight = window.innerHeight * .68;
        windowLeft = window.screenX + window.innerWidth * .16;
        windowTop = window.screenY + window.innerHeight * .16;
    }
    else if (typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number") {
        windowWidth = document.documentElement.offsetWidth * .68;
        windowHeight = document.documentElement.offsetHeight * .68;
        windowLeft = window.screenLeft + document.documentElement.offsetWidth * .16;
        windowTop = window.screenTop - 50;
    }
    else {
        windowWidth = 500;
        windowHeight = 250;
        windowLeft = 60;
        windowTop = 40;
    };
    windowWidth=850;
    windowHeight=600;
    if (WindowObjectReferenceOfRequestedPopup == null || WindowObjectReferenceOfRequestedPopup.closed) {
        WindowObjectReferenceOfRequestedPopup = window.open(strUrl, 'calc', "top=" + windowTop + ",left=" + windowLeft + ",scrollbars=yes,toolbar=0,status=0,width=1000,height=720");
    }
    else {
        if (WindowObjectReferenceOfRequestedPopup.focus) {
            WindowObjectReferenceOfRequestedPopup.location = strUrl;
            setTimeout("WindowObjectReferenceOfRequestedPopup.focus();", 1000);
        };
    };
}
function contentWin(url3open, width, height) {
    cWindow = window.open(url3open, 'aWindow', 'width=' + width + ',height=' + height + ',toolbar=no,menubar=no,location=yes,status=no,scrollbars=yes,resizable=yes,left=180,top=20');
    _gat._getTracker('UA-2081734-13')._trackPageview('/calculator');
}



function playSlideshow() {
    if (slideshow.current < slideshow.length) {
        slideshow.current += 1;
        setTimeout("playSlideshow()", 8000);
    }
    else {
        slideshow.current = 0;
        setTimeout("playSlideshow()", 9000);
    }
    

    $('.stripTransmitter li a').eq(slideshow.current).trigger('click');

    if (slideshow.timeout == 3000)
        slideshow.timeout = 2000;
    
}


function setActive() {
 $('.'+pageVars.current+' a:first').addClass('active');

}
var slideshow = {
    current: 0,
    length: 3,
    timeout:3000
}


function omniLinkClick(linkname) {

    s.linkTrackVars = 'events,prop3,eVar3';
    s.linkTrackEvents = 'event15';
    s.prop3 = s.eVar3 = s.pageName + '|' + linkname;
    s.events = 'event15';
    s.tl(this, 'o', s.pageName + '|' + linkname);
}

// Taken from A.js
//

function newMovie(url) {
    alert('gets called');
    var container = $('#movie_container');
    container.empty();

    $(container).append('<div style="width:320px;height:265px;"><object width="320" height="265"><param name="movie" value="' + url + '&rel=0" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="opaque" /><embed src="' + url + '&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="opaque" allowfullscreen="true" width="320" height="265"></embed></object></div>');
}

function newMovieIFrame(url) {
    var container = $('#movie_container');
    container.empty();

    $(container).append('<div style="width:320px;height:265px;"><iframe src="'+url+'&amp;autoplay=1" width="320" height="265" frameborder="0"></iframe></div>');

}


var bCove = {
    account: 'test',
    pid: 105854842001, //88455937001
    vid: 97229131001,
 
    vname:'',
    width: 615,
    autoplay:1,
    height:408,
    resize:false
}
function reloadMovie(url, active, width, height, autoplay, resize) {
    if (resize)
        bCove.resize = true;
    var vid = '';
    var vname = '';
    $('.videoContainer').empty();
    
        $('.videoContainer').append('<div id="flashcontent"></div>');
    
    var a = parseInt(active);

    
        bCove.width = width;
   
        bCove.height = height;
    
        bCove.autoplay = autoplay;
        
    switch (a) {
        case 0:
            bCove.vid = 13037268;
            bCove.vname = 'truthaboutquotes';
            vtext = 'The Truth About Quotes';
            break;
        case 1:
            bCove.vid = 13038959;
            bCove.vname = 'whyselectquote';
            vtext = 'Why SelectQuote?';
            break;

        case 2:

            bCove.vid = 13040828;
            bCove.vname = 'whoneedslifeinsurance';
            vtext = 'Who Needs Life Insurance?';
            break;

        case 3:
            bCove.vid = 13037861;
            bCove.vname = 'howmuchlifeinsurance';
            vtext = 'How Much Life Insurance Do You Need?';
            break;

        case 4:
            bCove.vid = 13036804;
            bCove.vname = 'howlonglifeinsurance';
            vtext = 'How Long Do You Need Life Insurance?';
            break;

        case 5:
            bCove.vid = 13036441;
            bCove.vname = 'whyyouneedachoice';
            vtext = 'Why You Need A Choice Of Companies';
            break;

        case 6:
            bCove.vid = 13038180;
            bCove.vname = 'wholelifeinsurance';
            vtext = 'Term Vs. Whole Life Insurance';
            break;

        case 7:
            bCove.vid = 13037610;
            bCove.vname = 'medicalexam';
            vtext = 'Why A Medical Exam?';
            break;

        case 8:
            bCove.vid = 14362966;
            bCove.vname = 'truthaboutquotes';
            vtext = 'The Truth About Quotes';
            break;

        case 9:
            bCove.vid = 14362636;
            bCove.vname = 'whyyouneedachoice';
            vtext = 'Why You Need A Choice Of Life Insurance Companies';
            break;
        case 10:
            bCove.vid = 20119177;
            bCove.vname = 'joelsecrets';
            vtext = 'Joel Secrets';
            break;
        case 11:
            bCove.vid = 20119475;
            bCove.vname = 'underadollar';
            vtext = 'Under a dollar';
            break;
    }
    


            s.linkTrackVars = 'events,prop34,eVar34';
            s.linkTrackEvents = 'event31';
            
            s.prop34 = s.eVar34 = s.pageName + '|' + bCove.vname;
            s.events = 'event31';
            s.tl(this, 'o', s.pageName + '|' + bCove.vname);
            played.push(bCove.vid);
        

    var container = $('.videoContainer');
    //container.empty();

    //Blue Video Subheader
    $('.videoSubheader').text(vtext);
    
   
    
    var isiPhone= navigator.userAgent.match(/iPhone/i) != null;
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    var isiTouch = navigator.userAgent.match(/iPod/i) != null;
    if (isiPad || isiPhone || isiTouch) {
        //Markup for Iphone and Ipad
        //Gotten from vimeo.  Update clipId with real video
        //var iphone = "<video id='vimeoVideo' src='http://www.vimeo.com/play_redirect?clip_id=" + bCove.vid + "&quality=sd&js_swf_id=vimeoVideo&js_api=1' autoplay='1' controls='controls' width='" + bCove.width + "' height='" + bCove.height + "'></video>";
        var iphone = "<iframe id='fVideo' src='http://player.vimeo.com/video/" + bCove.vid + "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff' width='" + bCove.width + "' height='" + bCove.height + "' frameborder='0'></iframe>";
        $(container).append(iphone);
        var playerIframe = document.getElementById("fVideo");
        /*
        playerIframe.addEvent("onLoad", function(player_id) {
        target = $('#' + player_id).get(0);
        target.addEvent('onPlay', vimeo_on_play);
        target.addEvent('onFinish', vimeo_on_finish);

            });
        */
    }
    else {

        //This is the markup needed for vimeo.  Update with clip_id from top
        //            var mark = '<object width="615" height="408"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + bCove.vid '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' +  + '13037268&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="615" height="408"></embed></object>';
        var mark = "<object  width='" + bCove.width + "' height='" + bCove.height + "'><param name='allowfullscreen' value='true' /><param name='wmode' value='Opaque' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id=" + bCove.vid + "&amp;js_swf_id=vimeoVideo&amp;js_api=1&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=" + bCove.autoplay + "' /><embed src='http://vimeo.com/moogaloop.swf?clip_id=" + bCove.vid + "&amp;js_swf_id=vimeoVideo&amp;js_api=1&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=" + bCove.autoplay + "' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='" + bCove.width + "' height='" + bCove.height + "' wmode='Opaque'></embed></object>";
        //$(container).append(mark);
        var flashvars = {

            clip_id: bCove.vid,
            js_api: 1,
            server: 'vimeo.com',
            fullscreen: 1,
            autoplay: bCove.autoplay,
            js_swf_id: 'flashcontent',
            title: false

        }
        var params = {
            allowfullscreen: true,
            wmode: "Opaque",
            js_onLoad: 'vimeo_player_loaded',
            allowscriptaccess: "always"
        }
        var attributes = {};

        swfobject.embedSWF("http://vimeo.com/moogaloop.swf", "flashcontent", bCove.width, bCove.height, "10.0.0", "/js/expressInstall.swf", flashvars, params, attributes);
    }

        
    $('.videoList li').removeClass('active');
    $('.videoList li').eq(active).addClass('active');
    //brightcove.createExperiences();
}

var played = [];
var completed = [];
function vimeo_player_loaded(swf_id) {
    moogaloop = document.getElementById(swf_id);
    moogaloop.api_addEventListener('onPlay', 'vimeo_on_play');
    moogaloop.api_addEventListener('onFinish', 'vimeo_on_finish');

}


function vimeo_on_play(swf_id) {
    if (played.indexOf(bCove.vid) == -1) {
        s.linkTrackVars = 'events,prop34,eVar34';
        s.linkTrackEvents = 'event31';

        s.prop34 = s.eVar34 = s.pageName + '|' + bCove.vname;
        s.events = 'event31';
        s.tl(this, 'o', s.pageName + '|' + bCove.vname);
        played.push(bCove.vid);

    }


   
}

function vimeo_on_finish(swf_id) {
    //alert(swf_id);
    /*
    if (completed.indexOf(bCove.vid) == -1) {
        s.linkTrackVars = 'events,prop34,eVar34';
        s.linkTrackEvents = 'event32';
        
        s.prop34 = s.eVar34 = s.pageName + '|' + bCove.vname;
        s.events = 'event32';
        s.tl(this, 'o', s.pageName + '|' + bCove.vname);
       
        completed.push(bCove.vid);
    }
    */

    $('.videoContainer').empty();
    if(!bCove.resize)
        $('.videoContainer').append('<div class="flashEnd"><a href="javascript:OpenSuzeQuiz()" class="endQButton" /></div>');
    else if(bCove.resize)
        $('.videoContainer').append('<div style="background:#eee;width: 320px; height: 215px; padding-top:300px;"><a href="javascript:OpenSuzeQuiz()" class="endQButton" />&nbsp;</div>');
        
}

function newMovieTrack(url, vidName, page) {
    _gat._getTracker('UA-2081734-13')._trackEvent("Video", "Selected", vidName, page);
    var container = document.getElementById('movie_container');
    container.innerHTML = '<object width="320" height="265"><param name="movie" value="' + url + '&rel=0" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="opaque" /><embed src="' + url + '&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="opaque" allowfullscreen="true" width="320" height="265"></embed></object></div>';
}
function setDelay(delay) {
    var date = new Date();
    var currentDate = null;

    do { currentDate = new Date(); }
    while (currentDate - date < delay);
}

function openQuiz() {
    window.open("https://www6202.ssldomain.com/DomainID209145/index_closedpanel.cfm","Suze Quiz");


}

function showQuiz(){
   $("#suzeCalculatorDialog").dialog("open");


}
