
var pageRequest = false;
var currentPage = "homebutton";
var _gaq = _gaq || [];

var homeString1 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"homesuccess\")>Success Stories</a>";
var homeString2 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"homeworks\")>How it Works</a>";
var homeString3 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"homewhynow\")>Why Now?</a>";

var helpString1 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"helpthrive\")>Thriving Couples</a>";
var helpString2 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"helpfailure\")>Struggling Couples</a>";
var helpString3 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"helpsamesex\")>Same Sex Couples</a>";
var helpString4 =       "<a href=\"javascript:void(0)\" onclick=processLink(\"helpchanges\")>Making Changes</a>";

var parentString1 =     "<a href=\"javascript:void(0)\" onclick=processLink(\"parentthree\")>Baby Makes 3</a>";
var parentString2 =     "<a href=\"javascript:void(0)\" onclick=processLink(\"parentbaby\")>Bringing Baby Home</a>";

var aboutString1 =      "<a href=\"javascript:void(0)\" onclick=processLink(\"aboutjennyfer\")>Jennyfer's Credentials</a>";
var aboutString2 =      "<a href=\"javascript:void(0)\" onclick=processLink(\"aboutphilosophy\")>Philosophy</a>";
var aboutString3 =      "<a href=\"javascript:void(0)\" onclick=processLink(\"tbd\")>Testimonials</a>";

var resourceString1 =   "<a href=\"javascript:void(0)\" onclick=processLink(\"resourceslinks\")>Links</a>";
var resourceString2 =   "<a href=\"javascript:void(0)\" onclick=processLink(\"resourcesreading\")>Recommended Reading</a>";
var resourceString3 =   "<a href=\"javascript:void(0)\" onclick=processLink(\"resourcesevents\")>Events</a>";
//var resourceString3 =   "<a href=\"javascript:void(0)\" onclick=processLink(\"resourcesnewsletter\")>Newsletter</a>";
//var resourceString4 =   "<a href=\"javascript:void(0)\" onclick=processLink(\"resourcesblog\")>Blog</a>";
//var resourceString5 =   "<a href=\"javascript:void(0)\" onclick=processLink(\"resourcesmovies\")>Movies</a>";

var contactString1 =    "<a href=\"javascript:void(0)\" onclick=processLink(\"contactsession\")>Schedule a free 30 minute session</a>";
var contactString2 =    "<a href=\"javascript:void(0)\" onclick=processLink(\"contactlegal\")>Legal</a>";

var bloglocation = 	"http://blog.healthycouples.org";

function onLoad()
{
    changeSoftNav( "homebutton" );
    goDim( "form1", "homebutton" );
    goClick( "form1", "homebutton" );

    _gaq.push(['_setAccount', 'UA-889934-1']);
    _gaq.push(['_setCustomVar', 1, 'Section', 'home', 3]);
    _gaq.push(['_trackPageview']);

    
    var ga = document.createElement("script");
    ga.src = ("http://www.google-analytics.com/ga.js");
    ga.setAttribute("async", "true");
    document.documentElement.firstChild.appendChild(ga);
}

function processLink( ID )
{
    _gaq.push(['_setAccount', 'UA-889934-1']);
    _gaq.push(['_setCustomVar',1, 'Section', ID, 3]);
    _gaq.push(['_trackPageview']);

    var ga = document.createElement("script");
    ga.src = ("http://www.google-analytics.com/ga.js");                                                                    ga.setAttribute("async", "true");
    document.documentElement.firstChild.appendChild(ga);

    if ("homesuccess" == ID)
    {
        loadData( rootdomain + "/content/home-success.htm", "main" );
        changeSoftNav( currentPage, 1 );
    }
    else if ("homeworks" == ID)
    {
        loadData( rootdomain + "/content/home-howitworks.htm", "main" );
        changeSoftNav( currentPage, 2 );
    }
    else if ("homewhynow" == ID)
    {
        loadData( rootdomain + "/content/home-whynow.htm", "main" );
        changeSoftNav( currentPage, 3 );
    }
    else if ("helpthrive" == ID)
    {
        loadData( rootdomain + "/content/help-thrive.htm", "main" );
        changeSoftNav( currentPage, 1 );
    }
    else if ("helpfailure" == ID)
    {
        loadData( rootdomain + "/content/help-failure.htm", "main" );
        changeSoftNav( currentPage, 2 );
    }
    else if ("helpsamesex" == ID)
    {
        loadData( rootdomain + "/content/help-samesex.htm", "main" );
        changeSoftNav( currentPage, 3 );
    }
    else if ("helpchanges" == ID)
    {
        loadData( rootdomain + "/content/help-changes.htm", "main" );
        changeSoftNav( currentPage, 4 );
    }
    else if ("parentbaby" == ID)
    {
        loadData( rootdomain + "/content/parents-baby.htm", "main" );
        changeSoftNav( currentPage, 2 );
    }
    else if ("parentthree" == ID)
    {
        loadData( rootdomain + "/content/parents-three.htm", "main" );
        changeSoftNav( currentPage, 1 );
    }
    else if ("aboutjennyfer" == ID)
    {
        loadData( rootdomain + "/content/about-jennyfer.htm", "main" );
        changeSoftNav( currentPage, 1 );
    }
    else if ("aboutphilosophy" == ID)
    {
        loadData( rootdomain + "/content/about-philosophy.htm", "main" );
        changeSoftNav( currentPage, 2 );
    }
    else if ("resourceslinks" == ID)
    {
        loadData( rootdomain + "/content/resources-links.htm", "main" );
        changeSoftNav( currentPage, 1 );
    }
    else if ("resourcesreading" == ID)
    {
        loadData( rootdomain + "/content/resources-reading.htm", "main" );
        changeSoftNav( currentPage, 2 );
    }
    else if ("resourcesevents" == ID)
    {
        loadData( rootdomain + "/content/resources-events.htm", "main" );
        changeSoftNav( currentPage, 3 );
    }
    else if ("resourcesnewsletter" == ID)
    {
        loadData( rootdomain + "/content/resources-newsletter.htm", "main" );
        changeSoftNav( currentPage, 3 );
    }
    else if ("resourcesblog" == ID)
    {
        loadData( rootdomain + "/content/resources-blog.htm", "main" );
        changeSoftNav( currentPage, 4 );
    }
    else if ("resourcesmovies" == ID)
    {
        loadData( rootdomain + "/content/resources-movies.htm", "main" );
        changeSoftNav( currentPage, 5 );
    }
    else if ("contactsession" == ID)
    {
        loadData( rootdomain + "/content/contact-free.htm", "main" );
        changeSoftNav( currentPage, 1 );
    }
    else if ("contactlegal" == ID)
    {
        loadData( rootdomain + "/content/contact-legal.htm", "main" );
        changeSoftNav( currentPage, 2 );
    }
    else if ("tbd" == ID)
    {
        loadData( rootdomain + "/content/newcontent.htm", "main" );
    }
}

function changeSoftNav( BTN, LOC )
{
    if (BTN == "homebutton")
    {
        var htmlString;
        if (LOC == 0)
            htmlString = homeString1 + " &bull; " + homeString2 + " &bull; " + homeString3;
        else if (LOC == 1)
            htmlString = "<b>" + homeString1 + "</b> &bull; " + homeString2 + " &bull; " + homeString3;
        else if (LOC == 2)
            htmlString = homeString1 + " &bull; <b>" + homeString2 + "</b> &bull; " + homeString3;
        else if (LOC == 3)
            htmlString = homeString1 + " &bull; " + homeString2 + " &bull; <b>" + homeString3 + "</b>";
        getElementById_s( "softnav" ).innerHTML = htmlString;
    }
    if (BTN == "helpbutton")
    {
        var htmlString;
        if (LOC == 0)
            htmlString = helpString1 + " &bull; " + helpString2 + " &bull; " + helpString3 + " &bull; " + helpString4;
        else if (LOC == 1)
            htmlString = "<b>" + helpString1 + "</b> &bull; " + helpString2 + " &bull; " + helpString3 + " &bull; " + helpString4;
        else if (LOC == 2)
            htmlString = helpString1 + " &bull; <b>" + helpString2 + "</b> &bull; " + helpString3 + " &bull; " + helpString4;
        else if (LOC == 3)
            htmlString = helpString1 + " &bull; " + helpString2 + " &bull; <b>" + helpString3 + "</b> &bull; " + helpString4;
        else if (LOC == 4)
            htmlString = helpString1 + " &bull; " + helpString2 + " &bull; " + helpString3 + " &bull; <b>" + helpString4 + "</b>";
        getElementById_s( "softnav" ).innerHTML = htmlString;
    }
    if (BTN == "parentsbutton")
    {
        var htmlString;
        if (LOC == 0)
            htmlString = parentString1 + " &bull; " + parentString2;
        else if (LOC == 1)
            htmlString = "<b>" + parentString1 + "</b> &bull; " + parentString2;
        else if (LOC == 2)
            htmlString = parentString1 + " &bull; <b>" + parentString2 + "</b>";
        getElementById_s( "softnav" ).innerHTML = htmlString;
    }
    if (BTN == "aboutbutton")
    {
        var htmlString;
        if (LOC == 0)
            htmlString = aboutString1 + " &bull; " + aboutString2 + " &bull; " + aboutString3;
        else if (LOC == 1)
            htmlString = "<b>" + aboutString1 + "</b> &bull; " + aboutString2 + " &bull; " + aboutString3;
        else if (LOC == 2)
            htmlString = aboutString1 + " &bull; <b>" + aboutString2 + "</b>" + " &bull; " + aboutString3;
        else if (LOC == 3)
            htmlString = aboutString1 + " &bull; " + aboutString2 + " &bull; <b>" + aboutString3 + "</b>";
        getElementById_s( "softnav" ).innerHTML = htmlString;
    }
    if (BTN == "resourcesbutton")
    {
        var htmlString;

        if (LOC == 0)
            htmlString = resourceString1 + " &bull; " + resourceString2 + " &bull; " + resourceString3;// + " &bull; " + resourceString4 + " &bull; " + resourceString5;
        else if (LOC == 1)
            htmlString = "<b>" + resourceString1 + "</b> &bull; " + resourceString2 + " &bull; " + resourceString3;// + " &bull; "; + resourceString4 + " &bull; " + resourceString5;
        else if (LOC == 2)
            htmlString = resourceString1 + " &bull; <b>" + resourceString2 + "</b> &bull; " + resourceString3;// + " &bull; " + resourceString4 + " &bull; " + resourceString5;
        else if (LOC == 3)
            htmlString = resourceString1 + " &bull; " + resourceString2 + " &bull; <b>" + resourceString3 + "</b>";// &bull; " + resourceString4 + " &bull; " + resourceString5;
//        else if (LOC == 4)
//            htmlString = resourceString1 + " &bull; " + resourceString2 + " &bull; " + resourceString3 + " &bull; <b>" + resourceString4 + "</b> &bull; " + resourceString5;
//        else if (LOC == 5)
//            htmlString = resourceString1 + " &bull; " + resourceString2 + " &bull; " + resourceString3 + " &bull; " + resourceString4 + " &bull; <b>" + resourceString5 + "</b>";
        getElementById_s( "softnav" ).innerHTML = htmlString;
    }
    if (BTN == "contactbutton")
    {
        var htmlString;
        if (LOC == 0)
            htmlString = contactString1 + " &bull; " + contactString2;
        else if (LOC == 1)
            htmlString = "<b>" + contactString1 + "</b> &bull; " + contactString2;
        else if (LOC == 2)
            htmlString = contactString1 + " &bull; <b>" + contactString2 + "</b>";
        getElementById_s( "softnav" ).innerHTML = htmlString;
    }
}

function goLite( FRM, BTN )
{
    window.document.forms[FRM].elements[BTN].style.backgroundColor = "#000000";
}

function goDim( FRM, BTN )
{
    if (BTN == currentPage)
        window.document.forms[FRM].elements[BTN].style.backgroundColor = "#3d3d3d";
    else
        window.document.forms[FRM].elements[BTN].style.backgroundColor = "#920000";
}

function goMouseDown( FRM, BTN )
{
    window.document.forms[FRM].elements[currentPage].style.backgroundColor = "#920000";
    window.document.forms[FRM].elements[BTN].style.backgroundColor = "#3d3d3d";
}

function goClick( FRM, BTN )
{
    if (BTN == "blogbutton")
    {
	location.href = bloglocation;
    }
    else
    {
        currentPage = BTN;
        changePhotos( BTN );
        changeSoftNav( BTN, 0 );
        fetchData( BTN );
    }
}

function goSimClick( simBTN, softNav )
{
    goMouseDown( "form1", simBTN );
    goClick( "form1", simBTN );
    if (softNav != "NULL")
        processLink( softNav );
}

function changePhotos( BTN )
{
    var photoString;

    if (BTN == "homebutton" ||
        BTN == "resourcesbutton")
    {
        photoString = "<img class=\"photobar\" src=\"images/family/family" +
            Math.round( Math.random() * 10 + 1 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/couple/couple" +
            Math.round( Math.random() * 14 + 1 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/parent/parent" +
            Math.round( Math.random() * 7 + 1 ) + ".jpg\" height=165>";
    }
    else if (BTN == "helpbutton")
    {
        photoString = "<img class=\"photobar\" src=\"images/couple/couple" +
            Math.round( Math.random() * 4 + 1 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/couple/couple" +
            Math.round( Math.random() * 4 + 6 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/couple/couple" +
            Math.round( Math.random() * 4 + 11 ) + ".jpg\" height=165>";
    }
    else if (BTN == "parentsbutton")
    {
        photoString = "<img class=\"photobar\" src=\"images/family/family" +
            Math.round( Math.random() * 5 + 1 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/family/family" +
            Math.round( Math.random() * 4 + 7 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/parent/parent" +
            Math.round( Math.random() * 7 + 1 ) + ".jpg\" height=165>";
    }
    else if (BTN == "contactbutton" ||
             BTN == "aboutbutton")
    {
        photoString = "<img class=\"photobar\" src=\"images/office/office" +
            Math.round( Math.random() * 3 + 1 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/office/office" +
            Math.round( Math.random() * 2 + 5 ) + ".jpg\" height=165>" +
            "<img class=\"photobar\" src=\"images/office/office" +
            Math.round( Math.random() * 1 + 8 ) + ".jpg\" height=165>";
    }

    getElementById_s( "photobar" ).innerHTML = photoString;
}

function fetchData( objectID )
{
    if (objectID == "homebutton")
    {
        loadData( rootdomain + "/content/home-base.htm", "main" );
    }
    if (objectID == "helpbutton")
    {
        loadData( rootdomain + "/content/help-base.htm", "main" );
    }
    if (objectID == "parentsbutton")
    {
        loadData( rootdomain + "/content/parents-base.htm", "main" );
    }
    if (objectID == "aboutbutton")
    {
        loadData( rootdomain + "/content/about-base.htm", "main" );
    }
    if (objectID == "resourcesbutton")
    {
        loadData( rootdomain + "/content/resources-base.htm", "main" );
    }
    if (objectID == "contactbutton")
    {
        loadData( rootdomain + "/content/contact-base.htm", "main" );
    }
}

var rootdomain = document.URL
function loadData( url, containerid )
{
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest();
    else if (window.ActiveXObject)
    {
        try 
        {
            page_request = new ActiveXObject( "Msxml2.XMLHTTP" );
        } 
        catch (e)
        {
            try
            {
                page_request = new ActiveXObject( "Microsoft.XMLHTTP" );
            }
            catch (e)
            {
            }
        }
    }
    else
        return false;

    page_request.onreadystatechange = function()
    {
        loadpage( page_request, containerid );
    }
    page_request.open( 'GET', url, true )
    page_request.send( null )
}

function loadpage( page_request, containerid )
{
    if (page_request.readyState == 4 && 
        (page_request.status == 200 || 
         window.location.href.indexOf("http") == -1))
    getElementById_s( containerid ).innerHTML = page_request.responseText;
}

function getElementById_s( id )
{
    var obj = null;
    if (document.getElementById)
    {
        /* Prefer the widely supported W3C DOM method, if
        available:-
        */
        obj = document.getElementById( id );
    }
    else if (document.all)
    {
        /* Branch to use document.all on document.all only
        browsers. Requires that IDs are unique to the page
        and do not coincide with NAME attributes on other
        elements:-
        */
        obj = document.all[id];
    }

    return obj;
}

