﻿var _iCurrentImage = 1;
var _aRotating = new Array();
var _iNewImage = 0;
var _oInterval;
var _bIsAnimating = false;
var _iCurrentSize = 2;

var aList = new Array();
var iCount = 0;
function pageLoad()
{
}

function $$(el) { return document.getElementById(el) }

function isNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    
    return IsNumber;
}

function isEmail(sInput)
{
    var bHasAt=false;
    var bHasPeriod=false;

    if (sInput.length < 6) 
    {
        return false;
    }
    
    for(var i=0 ; i<sInput.length ; i++)
    {
        if(sInput.charAt(i)=='@' && bHasAt) return false;
        if(sInput.charAt(i)=='@' && !bHasAt) bHasAt = true;
        if(sInput.charAt(i)=='.' && bHasAt) bHasPeriod = true;
    }
    
    if(bHasAt && bHasPeriod) 
    {
        return true;
    }
    
    return false;
}

function rotate()
{
    $("#divWhatHappens").fadeOut("slow", function()
    {
        $("#divWhatHappens").get(0).innerHTML = aList[iCount];
        $("#divWhatHappens").fadeIn("slow");
        iCount++;
        
        if(iCount >= aList.length )
        {
            iCount = 0;
        }
    });
    
    window.setTimeout(rotate, 7500);
}

function rotateBanner()
{
    var oCurrent;
    var oNext;
    var oList
    
}

function fadeTo(img, bCancel)
{
    if(_bIsAnimating)
    {
        return false;
    }
    
    if(bCancel)
    {
        window.clearInterval(_oInterval);
    }
    
    if(img == _iCurrentImage)
    {
        return false;
    }
    
    _iNewImage = img;
    
    _aRotating[_iCurrentImage].style.zIndex = 2;
    _aRotating[_iNewImage].style.zIndex = 0;
    _aRotating[_iNewImage].style.xOpacity = 0.99;
    _aRotating[_iNewImage].style.opacity = 0.99;
    _aRotating[_iNewImage].style.MozOpacity = 0.99;
    _aRotating[_iNewImage].style.filter = "alpha(opacity=" + (_aRotating[_iNewImage].style.xOpacity * 100) + ")";
    
    $(_aRotating[_iNewImage]).show();
   
    window.setTimeout(fadeIn, 50);
    
    _bIsAnimating = true;
    
    return false;
}

function fadeIn()
{
    var oOld = _aRotating[_iCurrentImage];
    var oNew = _aRotating[_iNewImage];
    
    if(_iCurrentImage == _iNewImage)
    {
        return;
    }
    
    oOld.xOpacity = oOld.xOpacity - .05;
    
    if(oOld.xOpacity > 0)
    {
        setOpacity(oOld);
        window.setTimeout(fadeIn, 33);
    }
    else
    {
        oOld.xOpacity = 0;
        
        $(_aRotating[_iCurrentImage]).hide();
        
        oNew.xOpacity = 0.99;
        _bIsAnimating = false;
        _iCurrentImage = _iNewImage;
    }
}

function doRoll()
{
    if(_iCurrentImage == (_aRotating.length-1))
    {
        fadeTo(0);
    }
    else
    {
        fadeTo(_iCurrentImage + 1);
    }
}

function setOpacity(obj) 
{
		if(obj.xOpacity>.99) 
		{
			  obj.xOpacity = .99;
		}
		
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

function changeTextSize(iSize)
{
    switch(iSize)
    {
      case 0:
        _iCurrentSize++;
        if(_iCurrentSize > 3)
        {
            _iCurrentSize = 1;
        }
        
        changeTextSize(_iCurrentSize);
        
        break;
      
      case 1:
        $("p,div.content div").css("fontSize", "12pt");
        _iCurrentSize = 1;
        break;
        
      case 2:
        $("p,div.content div").css("fontSize", "14pt");
        _iCurrentSize = 2;
        break;
        
      case 3:
        $("p,div.content div").css("fontSize", "16pt");
        _iCurrentSize = 3;
        break;    
    }
    
    return false;
}

function aDidYouKnow_onclick()
{
    window.open($(this).attr("href"), "Did you know", "width=500,height=500");
    
    return false;
}

function ajaxCall(sUrl, sRequest, fCallback, sType)
{
    if(sType != undefined)
    {
        $.ajax({type: "POST", url: sUrl, data:sRequest, success: fCallback, dataType: sType  });
    }
    else
    {
        $.ajax({type: "POST", url: sUrl, data:sRequest, success: fCallback });
    }
}

function getXmlValue(oNode,sTagName)
{
    try
    {
        return oNode.getElementsByTagName(sTagName)[0].firstChild.nodeValue;
    }
    catch(e)
    {
        return "";
    }
}


$(document).ready(function() 
{
    $("#aDidYouKnow").click(aDidYouKnow_onclick);
    
    $("#_aSmall").click(function() { changeTextSize(1); });
    $("#_aMedium").click(function() { changeTextSize(2); });
    $("#_aLarge").click(function() { changeTextSize(3); });
    $("#_aAuto").click(function() { changeTextSize(0); });
    
//    aList = [
//"your mom stops eating meals?",
//"your dad left the burner on for the 2nd time?",
//"your mom left the door unlocked?",
//"your dad drove into the garage door?",
//"your mom keeps forgetting to take her medication?",
//"your dad stops bathing for weeks?",
//"your mom is repeating the same stories over and over again?",
//"your dad fell in the shower and called out for help?",
//"your moms drivers lic was revoked by the DMV?",
//"your dad stops paying the bills?",
//"<span style='padding-left:40px'><img src='/images/layout/adia50.png' height='50' width='86' alt='Adia'/></span>"];
    //window.setTimeout(rotate, 1000);
    
    if ($(".rotatingbanner").length > 0)
    {
        $(".rotatingbanner img").each(function()
        {
            this.xOpacity = 0.99;
            _aRotating[_aRotating.length] = this;
        });
        
        _iCurrentImage = 0;
	      
	      _oInterval = window.setInterval(doRoll, 5000);
    }
    
    if ($(".rotatingbannersmall").length > 0)
    {
        $(".rotatingbannersmall img").each(function()
        {
            this.xOpacity = 0.99;
            _aRotating[_aRotating.length] = this;
        });
        
        _iCurrentImage = 0;
	      
	      _oInterval = window.setInterval(doRoll, 5000);
    }
    
    $("a.lightbox").lightBox();
    
    $("a.watchvideolink").fancybox();
    
    pageLoad();
});