var PREV_SS_XML = 'hptcms/prev-atlidx-slideshow.xml';
var PROD_SS_XML = 'hptcms/atlidx-slideshow.xml';

// slideshow variables
var ssm_cur_select = 1;
var ssPauseTime = 9000;  // slideshow pause time in milliseconds
var sstimer;
var cSlide = 1;


var xmlDoc;

// Doubleclick random number generator
var ord=Math.random()*10000000000000000;

function ssmenu_select(sel)
{
    stop_slideshow();
    do_show_ss_item(sel);
}

function do_show_ss_item(sel)
{
    preImgId = 'ssm' + ssm_cur_select;
    preImgName = 'menus/ssm_' + ssm_cur_select + '_off.png';

    newImgId = 'ssm' + sel;
    newImgName = 'menus/ssm_' + sel + '_on.png';

    document.getElementById(preImgId).src = preImgName;
    document.getElementById(newImgId).src = newImgName;

    ssm_cur_select = sel;

    disp_ss_data(sel);
}

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 disp_ss_data(sIdx)
{
	document.getElementById("sscap").innerHTML = document.getElementById('photo_' + sIdx + '_text').innerHTML;
	document.getElementById("ssmedia").innerHTML = document.getElementById('photo_' + sIdx + '_media').innerHTML;
}

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()
{
    subconh = document.getElementById('subcontent').offsetHeight;
    conh = document.getElementById('content').offsetHeight;
    newSCH = subconh;

    if(subconh < conh)
        newSCH = conh + 'px';
    else
        newSCH = subconh + 'px';

    document.getElementById('subcontent').style.height = newSCH;
}

function resize_photo()
{
    maxh = 300;
    maxw = 420;

    ih = document.getElementById("ssimage").height;
    iw = document.getElementById("ssimage").width;

    if(iw == maxw && ih == maxh) {
        document.getElementById("ssimage").height = maxh;
        document.getElementById("ssimage").width = maxw;
        return;
    }

    if(ih < maxh && iw < maxw) {
        hp = maxh / ih;
        wp = maxw / iw;

        if(hp < wp){
            newH = parseInt(ih * hp);
            newW = parseInt(iw * hp);
        } else {
            newH = parseInt(ih * wp);
            newW = parseInt(iw * wp);
        }
    } else {
        hp = ih / maxh;
        wp = iw / maxw;

        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()
{
    displayMainMenu();
    set_voices_border();
	init_slideshow();		
}

function init_slideshow()
{
    if(cSlide == 6)
        cSlide = 1;

    do_show_ss_item(cSlide);
    sstimer = setTimeout("init_slideshow()", ssPauseTime)
    cSlide++;
}

function stop_slideshow()
{
    clearTimeout(sstimer);
}
