
var ssm_img_cache=new Array();
var max_photo_height=170; /*280*/
var max_photo_width=260; /*440*/
var ssm_cur_select=1;
var SSM_MAX_SILDES=5;
var ssStartUp=1;
var ssStartTime=9000; /* 9000	*/
var ssRestartTime=4000;
var ssPauseTime=9000;
var sstimer=null;
var cSlide=1;
var ssVidSlide=0;

var xf_select_time=0.25;
var xf_time=1.00;
var xf_fps=20;
var ssDisolveSpeed=300; /*300*/

var xf_frames,xf_delay,xf_interval,xf_iImg,xf_oImg,xf_iTxt,xf_oTxt,xf_timeout;
var xmlDoc;

init_ss_fade(xf_time);

function setSlideCount(count)
{
    SSM_MAX_SILDES=count;
}

function init_ss_fade(time)
{
    xf_frames=time*xf_fps;
    xf_delay=time/xf_frames*ssDisolveSpeed;
    xf_interval=1/xf_frames;
    clearTimeout(xf_timeout);
    if(xf_iImg)
    {
        set_opacity(xf_iImg,1);
        xf_iImg.style.display='none';
    }
    if(xf_oImg)
    {
        set_opacity(xf_oImg,1);
        xf_oImg.style.display='block'; /*block*/
    }
    if(xf_iTxt)
    {
        set_opacity(xf_iTxt,1);
        xf_iTxt.style.display='none';
    }
    if(xf_oTxt)
    {
        set_opacity(xf_oTxt,1);
        xf_oTxt.style.display='block';/*block*/
    }
}
function ssmenu_select(sel)
{
    init_ss_fade(xf_select_time);
    stop_slideshow();
    do_show_ss_item(sel);
    cSlide=sel;
}

function do_show_ss_item(sel)
{
    var preId='ssm'+ssm_cur_select;
    var newId='ssm'+sel;
    if(sel<=SSM_MAX_SILDES-1 && 0!=sel)
    {
        if(!ssm_img_cache[sel])
        {
            ssm_img_cache[sel]=new Image();
            ssm_img_cache[sel].src=document.getElementById("photo_"+(sel)+"_image").src;
        }
        if(!ssm_img_cache[sel+1])
        {
            ssm_img_cache[sel+1]=new Image();
            ssm_img_cache[sel+1].src=document.getElementById("photo_"+(sel+1)+"_image").src;
        }
    }
    document.getElementById(preId).style.color="";
    document.getElementById(newId).style.color="#FFFFFF"; // d52b1e
    disp_ss_data(sel);
}

function set_opacity(element,opacity)
{
    if(null!=xf_oImg.style.MozOpacity)
        element.style.MozOpacity=opacity;
    else if(null!=xf_oImg.style.filter)
    {
        element.style.filter="alpha(opacity="+Math.round(opacity*100)+")";
        if(element.style.opacity)
            element.style.opacity=opacity;
    }
    else if(null!=xf_oImg.style.opacity)
        element.style.opacity=opacity;
}
function doFade(xf_opacity)
{
    if(Math.abs(xf_opacity)>0.99)
        xf_opacity=1;
    set_opacity(xf_oImg,xf_opacity);
    set_opacity(xf_oTxt,xf_opacity);
    set_opacity(xf_iTxt,1-xf_opacity);
}
function fade_ss_photo(sIdx,xf_opacity)
{
    if(xf_opacity<1)
    {
        xf_opacity+=xf_interval;
        doFade(xf_opacity);
        xf_timeout=window.setTimeout("fade_ss_photo("+sIdx+", "+xf_opacity+")",xf_delay);
    }
    else
    {
        complete_disp_ss_data(sIdx);
        set_opacity(xf_iTxt,1);
        set_opacity(xf_iImg,1);
    }
}

function disp_ss_data(sIdx)
{
    xf_iImg=document.getElementById('photo_'+ssm_cur_select+'_media');
    xf_oImg=document.getElementById('photo_'+sIdx+'_media');
    xf_iTxt=document.getElementById('photo_'+ssm_cur_select+'_text');
    xf_oTxt=document.getElementById('photo_'+sIdx+'_text');
    xf_oTxt.style.display='block';
    fix_ssphotocredit_position('photo_'+sIdx+'_text');
    xf_oTxt.style.display='none';
    if(sIdx!=ssm_cur_select)
    {
        xf_oImg.style.display='block';
        xf_oImg.style.opacity=0;
        xf_oImg.style.zIndex=0; //100;
        xf_iImg.style.zIndex=-1; // 1;
        xf_oTxt.style.display='block';
        xf_oTxt.style.opacity=0;
        xf_oTxt.style.zIndex=0; //100;
        xf_iTxt.style.zIndex=-1; // 1;
        ssm_cur_select=sIdx;
        fade_ss_photo(sIdx,0);
    }
    else
    {
        ssm_cur_select=sIdx;
        complete_disp_ss_data(sIdx);
    }
}
function complete_disp_ss_data(sIdx)
{
    clearTimeout(xf_timeout);
    xf_iTxt.style.display='none';
    xf_iImg.style.display='none';
    xf_oTxt.style.display='block';
    xf_oImg.style.display='block';
}
function escapeValue(str)
{
    return encodeURIComponent(str);
}
function onFSCommand(command,args)
{
    if(command=="eval")
    {
        eval(args);
        return;
    }
    if(this[command]==null)
        return;
    var obj=convertToObject(unescape(args));
    if(obj!=null)
    {
        var callback=obj.callback;
        var flashId=obj.flashId;
        if(obj.flashId!=null&&callback!=null)
        {
            callback=obj.flashId+ID_DELIM+callback;
        }
        if(obj.args==null)
        {
            eval(command+"(callback);");
        }
        else
        {
            eval(command+"(obj.args, callback);");
        }
    }
    else
    {
        eval(command+"();");
    }
}
function fix_ssphotocredit_position(divId)
{
    var photoText=document.getElementById(divId);
    var photoTextParagraphs=photoText.childNodes;
    var topOffset=0;
    for(var i=0 in photoTextParagraphs)
    {
        if(photoTextParagraphs[i].offsetHeight)
            topOffset+=photoTextParagraphs[i].offsetHeight;
    }
}
function stripslashes(str)
{
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\\\/g,'\\');
    str=str.replace(/\\0/g,'\0');
    return str;
}
function getCurrentDate()
{
    var today=new Date();
    var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var dayname=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    dateStr=dayname[today.getDay()]+', '+monthname[today.getMonth()]+' '+today.getDate()+', '+today.getFullYear();
    return dateStr;
}
function set_voices_border()
{
    var subcontentDIV=document.getElementById('subcontent');
    var contentDIV=document.getElementById('content');
    var splitleftDIV=document.getElementById('splitcontentleft');
    var splitrightDIV=document.getElementById('splitcontentright');
    var subconh=subcontentDIV.offsetHeight;
    var conh=contentDIV.offsetHeight;
    var splitlefth=splitleftDIV.offsetHeight;
    var splitrighth=splitrightDIV.offsetHeight;
    var splitDiff=splitlefth-splitrighth;
    var newSLH,newSCH;
    if(subconh<conh)
    {
        newSCH=conh;
        newSLH=(0<splitDiff)?splitlefth:splitrighth;
    }
    else
    {
        newSLH=(0<splitDiff)?(splitlefth+Math.abs(subconh-conh)):(splitrighth+Math.abs(subconh-conh));
    }
    if(newSCH)
        subcontentDIV.style.height=newSCH+'px';
    splitleftDIV.style.height=newSLH+'px';
}
function resize_photo()
{
    ih=document.getElementById("ssimage").height;
    iw=document.getElementById("ssimage").width;
    if(iw==max_photo_width && ih==max_photo_height)
    {
        document.getElementById("ssimage").height=max_photo_height;
        document.getElementById("ssimage").width=max_photo_width;
        return;
    }
    if(ih< max_photo_height && iw < max_photo_width)
    {
        hp=max_photo_height/ih;
        wp=max_photo_width/iw;
        if(hp<wp)
        {
            newH=parseInt(ih*hp);
            newW=parseInt(iw*hp);
        }
        else
        {
            newH=parseInt(ih*wp);
            newW=parseInt(iw*wp);
        }
    }
    else
    {
        hp=ih/max_photo_height;
        wp=iw/max_photo_width;
        if(hp<wp)
        {
            if(wp>1)
                hp=1/wp;
            newH=parseInt(ih*hp);
            newW=parseInt(iw*hp);
        }
        else
        {
            if(hp>1)
                wp=1/hp;
            newH=parseInt(ih*wp);
            newW=parseInt(iw*wp);
        }
    }
    document.getElementById("ssimage").height=newH;
    document.getElementById("ssimage").width=newW;
}
function postLoadPage()
{
    set_voices_border();
}
function init_slideshow()
{
    if(cSlide>SSM_MAX_SILDES)
        cSlide=1;
    do_show_ss_item(cSlide);
    if(ssStartUp)
        sstimer=setTimeout("init_slideshow()",ssStartTime);
    else
        sstimer=setTimeout("init_slideshow()",ssPauseTime);
    ssStartUp=0;    
    cSlide++;
}

function toggle_slideshow()
{
    if(sstimer != null)
    {
        stop_slideshow();
    }
    else
    {
        start_slideshow();
    }
}
function stop_slideshow()
{
    if(sstimer != null)
    {
        var imgObj   = document.getElementById('ssm_ctrl_btn');
        var objStyle = imgObj.style;
        clearTimeout(sstimer);
        sstimer=null;
        imgObj.src = "http://augustineinstitute.org/slideshow/images/playBtn.gif";
        imgObj.title = "Play";
        objStyle.marginTop = "3px";
    }
}
function start_slideshow()
{
    if(sstimer == null)
    {
        var imgObj   = document.getElementById('ssm_ctrl_btn');
        var objStyle = imgObj.style;
        sstimer=setTimeout("init_slideshow()",ssRestartTime);
        imgObj.src = "http://augustineinstitute.org/slideshow/images/pauseBtn.gif";
        imgObj.title = "Pause";
        objStyle.marginTop = "3px";
    }
}
