// picture objects toXml method


var pictureStartTag = "<picture ";
var pictureEndTag = "</picture>";
var filenameStartTag = "<filename>";
var filenameEndTag = "</filename>";
var scanYearStartTag = "<scanYear>";
var scanYearEndTag = "</scanYear>";
var scanMonthStartTag = "<scanMonth>";
var scanMonthEndTag = "</scanMonth>";
var gardnerStartTag = "<gardner>";
var gardnerMonthEndTag = "</gardner>";
var titleStartTag = "<title>";
var titleEndTag = "</title>";
var categoryStartTag = "<category>";
var categoryEndTag = "</category>";
var frameWidthEqual = " framewidth=\"";
var frameHeightEqual =  " frameheight=\"";
var widthEqual = "width=\"";
var heightEqual = "height=\"";
var singleQuote = "\"";
var oneSpace = " ";
var endBracket = ">";



var endFiller = "<scanYear>2007</scanYear><scanMonth>1</scanMonth><gardner>Jim</gardner></picture>";

function _toXml()
{
    var str = pictureStartTag;
    str += heightEqual;
    str += this.height;
    str += singleQuote;
    str += oneSpace;
    str += widthEqual;
    str += this.width;
    str += singleQuote;
    str += oneSpace;
    str += frameHeightEqual;
    str += this.frameheight;
    str += singleQuote;
    str += oneSpace;
    str += frameWidthEqual;
    str += this.framewidth;
    str += singleQuote;
    str += endBracket;
    str += titleStartTag;
    str += this.title;
    str += titleEndTag;
    str += filenameStartTag;
    str += this.filename;
    str += filenameEndTag;
    str += categoryStartTag;
    str += this.category;
    str += categoryEndTag;
    str += endFiller;    
    return str;

}


function _show()
{
    //alert("show()");
    
    if(slideshowIsRunning)
    {
        this.showForSlideShow();
    }
    else
    {
        this.showForThumbnail();
    }
}

function _showForSlideShow()
{
	// .80 reduction
	//alert("showForSlideShow()");
	var stage = document.getElementById("stage");
	var caption = document.getElementById("caption");
	var clrhght = getHeightOfStageDivClear(this.height * SLIDESHOW_REDUCTION);
	stage.width = (this.framewidth * SLIDESHOW_REDUCTION);
	stage.height = (this.frameheight * SLIDESHOW_REDUCTION);
	stage.src = this.constructPathSlideshow();
	caption.innerHTML = this.title;
	stage.alt = this.alt;
	
    document.images[STAGE_DIV_CLEAR].height = getHeightOfStageDivClear(this.isHorizontal());	

	//this.report();
}

function _showForThumbnail()
{
	
	
	var stage = document.getElementById("stage2");
	var caption = document.getElementById("caption");
	stage.width = (this.width * THUMBSHOW_REDUCTION);
	stage.height = (this.height * THUMBSHOW_REDUCTION);
	stage.src = this.constructPath();
   // alert("showForThumbnail() set src to\n" + stage.src);
	caption.innerHTML = this.title;
	stage.alt = this.alt;

	
    document.images[STAGE_DIV_2_CLEAR].height =  getHeightOfStageDivClearForThumbView(this.isHorizontal());
	//this.report();
}



function _report()
{
    var str = this.title;
    var sep = ": ";

    str += sep;
    str += "category";
    str += sep;
    str += this.category;
    str += "\n";
    str += "path";
    str += sep;
    str += this.constructPath();
    str += "\n";
    str += "picture object width and height";
    str += sep;
   str += this.width;
   str += " ";
   str += sep;
   str += this.height;
   str += "\n";   
   var stage = document.getElementById("stage");
   str += "image width and height";
   str += sep;
   str += stage.width;
   str += " ";
   str += sep;
   str += stage.height;
   str += "\n";   
   var stageDiv = document.getElementById("stageDiv");
  // alert(stageDiv);
   str += "stageDiv width and height";
   str += sep;
   str += stageDiv.width;
   str += " ";
   str += sep;
   str += stageDiv.height;
    
    alert(str);
}

function _constructPath()
{
    var str = "images/all/";
    str += this.filename;
    str += ".jpg";
    return str;
}

function _constructPathSlideshow()
{
    var str = "images/frames/";
    str += this.filename;
    str += ".jpg";
    //alert(str);
    return str;
}



function _isHorizontal()
{
    return this.width > this.height;    
}





function testPicture()
{   
    var pic = new picture("500", "500", "Elegance 1", "01", "Elegance");
    pic.report();
}

// props constructor
function picture(framewidth, frameheight, width, height, title, filename, category, placeInArray)
{
	// props
	this.framewidth = framewidth;
	this.frameheight = frameheight;
	this.width = width;
	this.height = height;
	this.title = title;
	this.filename = filename;
	this.category = category;
	this.placeInArray = placeInArray;
	this.alt = ALT_BEGINNING;
	
	//functions
	this.report = _report;
	this.constructPath = _constructPath;
	this.constructPathSlideshow = _constructPathSlideshow;
	this.show = _show;
	this.isHorizontal = _isHorizontal;
	this.showForSlideShow = _showForSlideShow;
	this.showForThumbnail = _showForThumbnail;
	this.toXml = _toXml;
	// put in browsers memory ??
	new Image().src = this.constructPath();


}

