////////////////////////////////VTOUR OBJECT : BEG////////////////////////////////

/////CONSTRUCTOR : BEG/////

//function VTour(sID,sImgRef,sDisplayText,sPlayerID,iStartPosPcnt,iIs360)
function VTour(sID,sImgRef,sDisplayText,iStartPosPcnt,iDisplayID)
{
    if(iStartPosPcnt== null)    iStartPos   = 0;

    //Properties
    this.ID             = sID;                                      //Name of tour (currently an integer media ID in DB, but will be treated as string here);
    this.ImgSrcPrefix   = g_sTourImageBaseURL;                      //Base href for images
    this.ImgSrcSuffix   = sImgRef;                                  //Reference to actual 360 tour image
    this.ImgSrc         = null;                                     //Full path to tour image
    this.Caption        = sDisplayText;                             //Link text to display
    this.StartPosPcnt   = iStartPosPcnt;                            //Start position expressed as percentage of total image width
    this.StartPos       = null;                                     //Start position in pixels, initialized in InitImage() after image has been loaded.
    this.Is360          = ConvertDisplayIDToBool(iDisplayID);       //Is image panoramic?
    this.Speed          = 2;                                        //Play speed
    this.Direction      = 1;                                        //Play direction (-1 = backward, 1=forward, 0=paused);
    this.IsInit         = false;                                    //Has the Image been initialized already?
    this.IsValid        = true;
    this.ValidateMsg    = "";                                       //Information about validation failure
    this.Height         = null;                                     //Image height in pixels. Determined after image has been loaded on client in TourInit();
    this.Width          = null;                                     //Image width  in pixels. Determined after image has been loaded on client in TourInit();

    //Methods
    this.Init           = TourInit;                                 //Initialize tour object.
    this.Validate       = TourValidate;                             //Validate initialization.
    this.Report         = ReportTourState;                          //Report tour state information (for test only)

    //Initialization
    this.Init();
}

/////CONSTRUCTOR : END/////

/////METHODS : BEG/////

//REPORT state of current tour object
function ReportTourState(sMsg)
{
if(!g_bTst) return;
sMsg += "";
if(sMsg.length > 0) sMsg = "\n\n[NOTE]\n" + sMsg
var sCaller = "\n\n[CALLING FUNCTION]\n" + ((ReportTourState.caller != null) ? ReportTourState.caller.toString().slice(0,ReportTourState.caller.toString().indexOf(")")+1) : "No Calling Function");

var sState  = "VTour Object("    + this.ID + ") State:"
            +sMsg
            +sCaller
            +"\n\n[PROPERTIES : GENERAL]"
            +"\nID ["           + typeof(this.ID)           + "]\t\t= " + this.ID
            +"\nImgSrcPrefix [" + typeof(this.ImgSrcPrefix) + "]\t= "   + this.ImgSrcPrefix
            +"\nImgSrcSuffix [" + typeof(this.ImgSrcSuffix) + "]\t= "   + this.ImgSrcSuffix
            +"\nImgSrc ["       + typeof(this.ImgSrc)       + "]\t\t= " + this.ImgSrc
            +"\nCaption ["      + typeof(this.Caption)      + "]\t\t= " + this.Caption
            +"\nStartPosPcnt [" + typeof(this.StartPosPcnt) + "]\t= "   + this.StartPosPcnt
            +"\nStartPos ["     + typeof(this.StartPos)     + "]\t\t= " + this.StartPos
            +"\nIs360 ["        + typeof(this.Is360)        + "]\t\t= " + this.Is360
            +"\nSpeed ["        + typeof(this.Speed)        + "]\t\t= " + this.Speed
            +"\nDirection ["    + typeof(this.Direction)    + "]\t\t= " + this.Direction
            +"\nIsInit ["       + typeof(this.IsInit)       + "]\t\t= " + this.IsInit
            +"\nIsValid ["      + typeof(this.IsValid)      + "]\t\t= " + this.IsValid
            +"\nHeight ["       + typeof(this.Height)       + "]\t\t= " + this.Height
            +"\nWidth ["        + typeof(this.Width)        + "]\t\t= " + this.Width

    Tst(sState,1,c_iTstMsgsObjReports);
}

//PRE-LOAD image for performance
function TourInit()
{
    if(this.IsInit) return;

    //CONVERT image ref to v-tour
    this.ImgSrcSuffix   = ConvertVtourImageRef(this.ImgSrcSuffix);

    // Add source suffix to relative URLs
    if (this.ImgSrcSuffix.indexOf("http:") == -1)
    {
        this.ImgSrc     = this.ImgSrcPrefix + this.ImgSrcSuffix;
    }
    else
    {
        this.ImgSrc     = this.ImgSrcSuffix;
    }


    //PRE-CACHE image
    var oImg        = GetTourImage(this.ID,this.ImgSrc);

    if(!document.all) this.Speed -= 1; //SLOW speed down by 1 for NS
    this.Height     = oImg.height;
    this.Width      = oImg.width;
    this.StartPos   = GetStartPosPx(this);
    this.IsValid    = this.Validate();
    this.IsInit     = this.IsValid;
}

//VALIDATE tour
function TourValidate()
{
    var sErrMsg = '';
    if (this.ImgSrc == null || this.ImgSrc.length < 1)  this.ValidateMsg += '- this.ImgSrc bad reference.';
    if (this.StartPos < -this.Width)                    this.ValidateMsg += '- Tour image start position(' + this.StartPos + ') must be >= ' + this.Width;
    if (this.Width < c_iMinVTourWidth)                  this.ValidateMsg += '- Image width(' + this.Width + ') less than minimum required(' + c_iMinVTourWidth + ').';

    if(this.ValidateMsg.length > 0)
    {
        sErrMsg = "Problem(s) Initializing Tour(" + this.ID + "):"
                + "\n-------------------------------"
                + "\n"
                + this.ValidateMsg;

        Tst(sErrMsg,null,c_iTstMsgsObjReports);
        return false;
    }
    else
    {
        return true;
    }
}

/////METHODS : END/////

////////////////////////////////VTOUR OBJECT : END////////////////////////////////