
function newPage (newM1) {
  if (newM1 != activePage) {
    $('#'+activePage).hide();
    $('#'+newM1).show();
    activePage=newM1;
    
$.log("activePage -> #"+activePage,"err");
  }  
}

/*
  user made a menu selection
  m1=Our_Events&m2=Impact&m3=Media_Gallery
  m1=About_Us&m2=Our_Leaders&m3=Elders&m4=Duane_Fancher
*/

var m;

function fnDDMenu (str, href) { //,hash
	window.location= href;
	return false;

  str=str.replace("_&amp;_", "_#_");
  str=str.replace("'", "");
  m=$.unserialize(str);


$.log("fnDDMenu "+href+" m1="+m.m1+" m2="+m.m2+"\n"+theSite+"->"+thePage);
/*
  if (!hash) {
    // put state into history
    if (m.m4) {
      $.bbq.pushState({ m1:m.m1, m2:m.m2, m3:m.m3, m4:m.m4 });
    } else if (m.m3) {
      $.bbq.pushState({ m1:m.m1, m2:m.m2, m3:m.m3 },2);
    } else if (m.m2) {
      $.bbq.pushState({ m1:m.m1, m2:m.m2 },2);
    } else  {
      $.bbq.pushState({ m1:m.m1 },2);
    }
    ddsmoothmenu.close({mainmenuid: "mainMenu"});
    return false;
  }
  */
	// thePage= bsi, bsm, bspm, bsr
switch (m.m1) {
    case "Home":

      newPage ("m1_"+m.m1);
    break;
    
    case "About_Us":
      if (m.m2) {
        switch (m.m2) {
          case "Our_Leaders":
            if (m.m4) {
$.log("m3="+m.m3)

              setTab(m.m4,"m3_"+m.m3,"77"); // specific elder, deacon
            }
            // fall into default
          
          default:
            newPage ("m2_"+m.m2);
            break;
        }
      }  else {
        newPage ("m1_"+m.m1);        
      }
    break;
  
    case "SERVICES":
      if (m.m3) {
        setTab(m.m3,"m2_"+m.m2,"88"); // specific event, activity
      }
    
      if (m.m2) {
        newPage ("m2_"+m.m2);
      } else {
        newPage ("m1_"+m.m1);        
      }
      break;
  
  }
  ddsmoothmenu.close({mainmenuid: "mainMenu"});
  return false;
}

function trim12 (str) {
	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

/*
 main document.ready code
*/
  $(document).ready(function() {
		$('.slideshow').cycle({ // bsm home
			fx:'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			timeout: 3000
		});

		$('.introsplash').cycle({ // star
			fx:'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			autostop: true,
			autostopCount: 5,
			delay:-900,
			timeout: 900,
			end: fnStart
		});

		pix=$("a[rel^='prettyPhoto']");
//		console.log("pix:");	
//		console.log(pix);	
		$("a[rel^='prettyPhoto']").prettyPhoto( {overlay_gallery: false} );
//{theme: 'facebook',slideshow:5000, autoplay_slideshow:false}

/*
	images = ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg'];
	titles = ['Title 1','Title 2','Title 3'];
	descriptions = ['Description 1','Description 2','Description 3']
	$.prettyPhoto.open(images,titles,descriptions);
	
	/*
		$("#bottomest a[rel]").click( function() {
			r=$(this).attr("rel");
			$("body").attr("id",r);
			return false;
		});
	*/
		$("#login_back").hide();


		$("#xby").hover( function() {
			$(this).html("<?=$jake?>");
			},
				function () {
			$(this).html("&nbsp;.&nbsp;");
		});
	
		$("#btn_info").click( function() {
			alert("More info");
		});
  
		$(".bService, #left_callout, #jerryjones").hover (
			function () {
				$(this)
					.find(".learn").css("text-decoration","underline")
					.css("color","black")
				;
			}, 
			function () {
				$(this)
					.find(".learn").css("text-decoration","none")
					.css("color","#999999")
				;
			}
		);

		$("#topStar, #topTitle").click (function() {
	//		var loc=$(this).css("background-image");
	//		loc=loc.substr(-8,3);
			window.location= "index.php?d=bsm&c=home";
			return false;
		});		

		$("#bPhysician").click (function() {
			window.open("https://bsiencompass.dallascowboys.net/");
			return false;
		});		

		$("#bPatient").click (function() {
//			alert ("Patient login/payment");
			window.open("https://www.ezmedinfo.com/Login.aspx");
			return false;
		});		

		$("#bClient").click (function() {
//			alert ("Client login");
			window.open("https://bsiencompass.dallascowboys.net/");
			return false;
		});		

		$("#bsr #left_callout").click (function() {
			window.location="index.php?d=bsr&c=radiologists";
			return false;
		});		

		$("#jerryjones").click (function() {
			window.location="index.php?d=bsi&c=jerryjones";
			return false;
		});		

		$("#bsi #sidebar li"
			).click (function() {
			loc=(this.id).substr(3);
	window.location="index.php?d=bsi&c="+loc;
			return false;
		});		

		$(".bService").click (function() {
			loc=(this.id).substr(3);
			window.location="index.php?d=bsi&c="+loc;
			return false;
		});		

		$("#bsi #_home #rightcol").click (function() {
      window.location="index.php?d=bsi&c=scheduling";
			return false;
		});

    /* log in codes */
    $("#btn_login").click( function() {
      sec=$(this).text();
      if (sec=="Log out") {
        window.location ="admin/inc/logouteic.php";
      } else {
        $("#login_back").show("slow");
      }
      return false;
    });
  
    $("#bLogCancel").click( function() {
      $("#login_back").hide("slow");
      return false;
    });
  
  /*   */
    function doLogin(flag, msg) {
      sUser=$("#txtUser").val();
      sPass=$("#txtWord").val();

      if (sUser) {
        sUser=hex_sha1(sUser);
      } else {
        $("#tjAlertMsg").html(msg);        
        $("#btn_tjAlertE").trigger("click");
        return false;
      }
      if (sPass) {
        sPass=hex_sha1(sPass);
      }

//alert ("tjPass user="+sUser+" pass="+sPass);
      window.location='site/loginer.php?user='+sUser+'&word='+sPass+'&f='+flag; //+'&f='+m.flag;
      return;
    }
    
    $("#bLogin").click(function() {
      doLogin("log","Enter your email and password.");
      return false;
    });

    $("#bLogRegister").click(function() {
      doLogin("reg","Please enter your email and a password, and then click Register.");
      return false;
    });

    $("#bLogForgot").click(function() {      
      doLogin("forgot","Enter your email address and a new password will be sent to you.");
//      alert ("Your password has been emailed to the address above.");
      return false;
    });

//    $(window).trigger( 'hashchange' );
  });

/*
  process modals
*/
function tjModals (rez) {

$.log("rez:"+rez,"err");

    m=$.unserialize(rez);
    switch (m.id) {
      case "tjPass":
        
        sPass=hex_sha1(m.pwd);
$.log (m.flag);        
$.log("tjPass log:"+m.login+" pass:"+m.pwd+" > "+sPass);
        window.location='site/loginer.php?user='+m.login+'&word='+sPass+'&f='+m.flag;
      break;

      break;
      
      default:
       $.log("other id:"+m.id+"\n"+rez);       
    }
  return false;
}
