// Javascript class to hold a slideshow photo object
function slidePhoto( sPht, sCap )
{
    this.Photo = sPht;
    this.Caption = sCap;
    this.Image = new Image();
    this.Image.src = sPht;

	// IMM 06.19.08: Store filename only
	aPhtEle = sPht.split("/");
	this.FileName = aPhtEle[aPhtEle.length-1];
}

// Location of slideshow control images
g_sConPth = "/a/i/";

g_iSldPos = 0;

g_iPlyHdl = 0;      // Handle to play-pause interval object
g_iFrmCnt = 0;      // Animation frame counter
g_iAnmHdl = 0;      // Handle to animation interval object
g_iCurSld = 0;      // Current slide being viewed

g_iAnmStp = 0;      // Number of pixels to move during animation step
g_iAnmTot = 10;     // Total number of animation steps during movement
g_iAnmSpd = 10;     // Number of animation steps
g_iSldInt = 3000;	// Number of seconds between slide transitions

g_iPhtWdt = 0;      // Width of individual photo
g_Sliding = false;	// When true, slide is transitioning

function loadSlides()
{
	$("#ShwLst").html( $("#TmpHld").html() );
	g_iSldMax = $("#ShwLst").children().size();
	g_iPhtWdt = 280;	// $(".SldPht:first").attr("width");
	g_iAnmStp = g_iPhtWdt / g_iAnmSpd;
}

function advanceSlide(iDir)
{
	if (!g_Sliding)
	{
		g_Sliding = true;

		if (iDir == -1)
			g_iCurSld++;
		else
			g_iCurSld--;

		// If we are at the end of the show, and 
		// user wants next photo, reverse to start
		if (g_iCurSld >= g_iSldMax)
		{
			g_iAnmStp = (g_iPhtWdt * (g_iSldMax - 1)) / 10;
			iDir = 1;
			g_iCurSld = 0;
		}
		else if  (g_iCurSld < 0)
		{
			g_iAnmStp = (g_iPhtWdt * (g_iSldMax - 1)) / 10;
			iDir = -1;
			g_iCurSld = g_iSldMax - 1;
		}

		g_iAnmHdl = setInterval( "moveSlide(" + iDir + ")", g_iAnmSpd );
	}
}

function moveSlide(iDir)
{
	var sCurPos = $("#ShwLst").css("left");
    var sStrPos = stripNonNum(sCurPos);
    var iCurPos = Number(sStrPos)
    var iNewPos = iCurPos + (g_iAnmStp * iDir);

	$("#ShwLst").css("left",iNewPos + "px");

    g_iFrmCnt++;

    if (g_iFrmCnt >= g_iAnmTot)
    {
        clearInterval( g_iAnmHdl );
		g_Sliding = false;
        g_iFrmCnt = 0;
        g_iAnmStp = 28;

		// IMM 06.19.08: Push HitBox metrics for current slide
		//var new_pn = "DEMOshots | " + g_aShots[g_iCurSld].FileName;
		//_hbSet('n',new_pn);
		//_hbSend();

		// 06-11-08: Resend QuantCast
		//_qpixelsent = "";
		//quantserve();
    }
}

function stripNonNum( sStr )
{
    sNew = "";
    for (var iPos = 0; iPos < sStr.length; iPos++)
    {
        if ("-0123456789".indexOf(sStr.substr(iPos,1)) > -1)
            sNew += sStr.substr(iPos,1);
    }
    return sNew;
}

function playPauseSlide()
{
    if (g_iPlyHdl != 0)
    {
		$("#PlyPseImg").attr("src",g_sConPth + "plyphtclr.gif");
        clearInterval(g_iPlyHdl);
        g_iPlyHdl = 0;
    }
    else
    {
        advanceSlide(-1);
		$("#PlyPseImg").attr("src", g_sConPth + "psephtclr.gif");
        g_iPlyHdl = setInterval( "advanceSlide(-1)", g_iSldInt );
    }
}

// Setup slideshow
$(document).ready(function(){loadSlides();})

