﻿
/*
   buttons_functions: 
   var functions that controls wich information is displayed in the right panel of the landing page on index.aspx. 
   Also controls the interactivity and theming of the buttons of the left panel of the landing page on index.aspx 
*/
var buttons_functions = function() {
   this.contArray  = new Array();
   this.buttons = new Array(); 
}

buttons_functions.prototype.contArray=null;

buttons_functions.prototype.buttons=null;

buttons_functions.prototype.init=function(){
            
            this.contArray  =   [ $("#middle-container #content-right .middle #first") , 
                                  $("#middle-container #content-right .middle #second"), 
                                  $("#middle-container #content-right .middle #third")  ] ; 
                        
            this.buttons =  [ $("#middle-container #content-left #buttons li.purple") , 
                              $("#middle-container #content-left #buttons li.red"), 
                              $("#middle-container #content-left #buttons li.green")  ] ; 
}

buttons_functions.prototype.first = function () {
            $("#middle-container #content-left").removeClass("img-qmark-red img-qmark-green").addClass("img-qmark-purple"); 
             this.showTopic(0,1,2);
            $("#middle-container #content-right a.button").removeClass("red green").addClass("purple");
            $("div#content-right a.button").attr('name', '&lid=OAB Happen as Age Learn About Prescription' );  
}
        
buttons_functions.prototype.second = function () {
            $("#middle-container #content-left").removeClass("img-qmark-purple img-qmark-green").addClass("img-qmark-red"); 
             this.showTopic(1,0,2);
            $("#middle-container #content-right a.button").removeClass("green purple").addClass("red"); 
            $("div#content-right a.button").attr('name', '&lid=Do Children Cause OAB Learn About Prescription' );  
}

buttons_functions.prototype.third=function () {
            $("#middle-container #content-left").removeClass("img-qmark-red img-qmark-purple").addClass("img-qmark-green"); 
            this.showTopic(2,1,0);
            $("#middle-container #content-right a.button").removeClass("red purple").addClass("green"); 
            $("div#content-right a.button").attr('name', '&lid=Treatment for OAB Learn About Prescription' );  
 }
          

buttons_functions.prototype.showTopic=function (showing,hidding_1,hidding_2) {
            $(this.buttons[hidding_1].find('a')).removeClass("selected");
            $(this.buttons[hidding_2].find('a')).removeClass("selected");
            $(this.contArray[hidding_1]).hide(); 
            $(this.contArray[hidding_2]).hide();
            $(this.contArray[showing]).fadeIn(0); 
}

buttons_functions.prototype.showPageName = function (index)  {
  switch (index) {
   case 0:  { return "Does OAB happen as you age?";    }
   case 1:  { return "Does Having Children Cause OAB?";  }  
   case 2:  { return "Is there a treatment for OAB?"; }
   } // switch 
   return "";   
}
       
         

/*
   intersitial: 
   var functions that controls the intersitial layer before leaving the landing page. 
   Launches the intersitial layer when is necesary, set the new window location based on a specified URL 
*/
var intersitial = function() {}

intersitial.prototype.exit_site =  function(url) {
            sendPageTracking("Interstitial Page",null,"Toviaz Unbranded", "Interstitial Page") ; 
            this.interblockLayer(true, '#intersitial');
            $("div.blockUI.blockOverlay").click(function(){ $.unblockUI({ fadeOut: 200 }); });  
            $("div#middle_intersitial a.redirect").attr('href', url );  
       
} 

intersitial.findOutMore = function ()  {
            $("body").fadeOut(200,function() {
               quizLayer.closeQuiz();  
               this.exit_site('http://www.toviaz.com?tovsrc=TOVW10024936&cmp=Web-OAB');        
             }); 
}

intersitial.prototype.interblockLayer = function (shouldBlock, inputElementId)  {
           $.blockUI.defaults.css.border = '0';
           $.blockUI.defaults.css.backgroundColor = 'transparent';
           $.blockUI.defaults.css.width = '366px';
           $.blockUI.defaults.css.height = '378px';
           $.blockUI.defaults.css.overflow = 'auto';
           $.blockUI.defaults.css.margin = '100px 0px 0px -172px';
           $.blockUI.defaults.css.padding = '0px';
           $.blockUI.defaults.css.left = '50%';
           $.blockUI.defaults.css.top = '40px';
           if (shouldBlock === true) {
                 $.blockUI({
                 message: $(inputElementId),
                 css: { top: '40px' } 
          });
          }
}

intersitial.prototype.closeLayer = function () {
          $.unblockUI({ fadeOut: 200 });    
          restorePageName();  
} 
  
var interLayer= new intersitial();    
var buttons=new buttons_functions();


function go_print ()  {    
       var temp= $("#sizer").html(); ; 
       $("#sizer").html(""); 
       window.print();  
       $("#sizer").html (temp);
}

$(document).ready(function() {

     buttons.init();
  
     $(".scodeTracking").click(function() { sendTracking(null, $(this).attr("name"), null, null); });

    $("#buttons li a").mouseover(function(e) {

        e.preventDefault();
         
        
        var index = $("#buttons li").index($(this).parent());
        var pageName = "";
        var channel = "Toviaz Unbranded";
        switch (index) {
            case 0:
                buttons.first();
                break;
            case 1:
                buttons.second();
                break;
            case 2:
                buttons.third();
                break;
        } // switch 
        $(this).addClass("selected");    
      
    });
    
    $("#buttons li a").click (function (e)  {
           e.preventDefault();
           sendTracking(null, $(this).attr("name"), null );
           $(this).addClass("selected");
           var pageName = buttons.showPageName($("#buttons li").index($(this).parent())); 
           sendPageTracking(pageName, null, "Toviaz Unbranded");
    }); 
   
});
