﻿$(document).ready(function() {
    // $("ul.pmenu a").removeAttr("href");
    //    $("#sw").click(function() {
    //    
    //        $("div#switching").show();
    //        $("div#"+$(this).parent().parent().parent().parent().attr("id")).hide();

    //    });
    //    $("ul.pmenu a").click(function() {
    //        // var id = $(this).attr("id").substring(3, 5).toLowerCase(); 
    //        //for default11
    //        var id = $(this).attr("id")
    //        $("div#" + $(this).parent().parent().parent().parent().parent().attr("id")).addClass("hide");

    //        $("div.pulldownmenu").hide();
    //        switch (id) {
    //            case "sw":
    //                $("div#switching").removeClass("hide"); $.cookie('hview', 'switch'); break;

    //            case "se":

    //                $("div#seeking").removeClass("hide"); $.cookie('hview', 'infoseeker'); break;
    //            case "ta":
    //                $("div#taking").removeClass("hide"); $.cookie('hview', 'patient'); break;
    //            case "ca":
    //                $("div#caring").removeClass("hide"); $.cookie('hview', 'caretaker'); break;
    //            case "fi":
    //                $("div#filling").removeClass("hide"); $.cookie('hview', 'scriptholder'); break;
    //        }

    //    });



    //    $("p.bluequestion").click(function() {

    //        $("p.answer1").show();
    //        $("p.answer2").hide();
    //    }, function() {
    //    });

    //    $("p.greyquestion").click(function() {
    //        $("p.answer2").show();
    //        $("p.answer1").hide();
    //    });
//$("div.module4").hide();
$("#a3r").click(function() {

    $("div.module4").show();
    $("div.module3").hide();
});

$("#a4l").click(function() {

    $("div.module3").show();
    $("div.module4").hide();
});

  
    $("*").removeClass("nojava");
    $("img.pulldownBtn").removeClass("hide");
    
    //    $("#imgthere").attr("src", "/Images/home/there.gif");
    //    $("#imgdep").attr("src", "/Images/home/depression.gif");
    //    $("#imgisit").attr("src", "/Images/home/isit.gif");
    //    $("#imgis").attr("src", "/Images/home/is.gif");
    //    $("#imgfill").attr("src", "/Images/home/filling.gif");

    $(".pulldownBtn").click(function() {
        $("div.pulldownmenu").toggle();
    });


})

$.address.init(function(event) {
    $("ul.pmenu a").removeAttr("href");
    $("ul.pmenu a#se").attr("href", "/infoseeker");
    $("ul.pmenu a#sw").attr("href", "/switcher");
    $("ul.pmenu a#ca").attr("href", "/caretaker");
    $("ul.pmenu a#fi").attr("href", "/scriptholder");
    $("ul.pmenu a#ta").attr("href", "/patient");


}).change(function(event) {

    var names = $.map(event.pathNames, function(n) {
        return n.substr(0, 1) + n.substr(1);
    }).concat(event.parameters.id ? event.parameters.id.split('.') : []);
    var links = names.slice();

    var qs = window.location.search.substring(1);

    var match
    if (links.length > 0) {
        match = links.shift();
    }
    else if (qs == "") {
        var hview = $.cookie('hview');
        if (hview != null) {
            match = hview;
        }
        else {
            match = 'patient';
        }
    }
    else {
        match = qs;
    }
    // var match = links.length ? links.shift() : 'patient';
    var arr = ["patient", "infoseeker", "switcher", "caretaker", "scriptholder"];
    var flag = new Boolean(false);
    //            jQuery.each(arr, function() {
    //                if (match == this) {
    //                    flag = true;
    //                }
    //            });
    for (var i in arr) {
        if (match == arr[i]) {
            flag = true;
        }

    }
    if (flag == false) {
        match = "patient";
    }

    jQuery.each(arr, function() {

        if ($("#" + this).attr('id') == match) {
            $("#" + match).removeClass('hide');
            $("#" + match + " div.pulldownmenu").hide();
            $.cookie('hview', match);
            Homeload(match);
           
        }
        else {
            if ($("#" + this).attr('class') == '') {
                $("#" + this).addClass("hide");
            }
        }
    });

    //$("div.pulldownmenu").hide();
});

/*function Homeload(n) {
    pic = new Image(1, 1);
    switch (n) {
        case 'caretaker':
            pic.src ="http://view.atdmt.com/action/LEX_Homepage_CaringForAnAdolescent_image"; break;
        case 'scriptholder':
            pic.src = "http://view.atdmt.com/action/LEX_Homepage_FillingLexaproScript_image"; break;
        case 'infoseeker':
            pic.src = "http://view.atdmt.com/action/LEX_Homepage_SeekingGeneralInformation_image"; break;
        case 'switcher':
            pic.src = "http://view.atdmt.com/action/LEX_Homepage_SwitchingToLexapro_image"; break;
        case 'patient':
            pic.src = "http://view.atdmt.com/action/LEX_Homepage_TakingLexapro_image"; break;
    }
}*/
 function Homeload(n) { 

   if (n)

   {      // Get the script element.

      var elnm = "atlas"+n;

      var el = document.getElementById(elnm);

      var base = "http://view.atdmt.com/jaction/";

                  if (el)

                    document.body.removeChild(el);

                  

      el = document.createElement('script');

      el.setAttribute('id',elnm);

      el.setAttribute('type','text/javascript');

      document.body.appendChild(el);

 

                   switch (n) { 

                                 case 'caretaker': 

                                 el.src = base + "LEX_Homepage_CaringForAnAdolescent"; break; 

                                 case 'scriptholder': 

                                 el.src = base + "LEX_Homepage_FillingLexaproScript"; break; 

                                 case 'infoseeker': 

                                 el.src = base + "LEX_Homepage_SeekingGeneralInformation"; break; 

                                 case 'switcher': 

                                 el.src = base + "LEX_Homepage_SwitchingToLexapro"; break; 

                                 case 'patient': 

                                 el.src = base + "LEX_Homepage_TakingLexapro"; break; 

                   } 

                }

}



