// picture objects toXml method


var pictureStartTag = "<picture ";
var pictureEndTag = "</picture>";
var filenameStartTag = "<filename>";
var filenameEndTag = "</filename>";

var titleStartTag = "<title>";
var titleEndTag = "</title>";
var categoryStartTag = "<category>";
var categoryEndTag = "</category>";

var widthEqual = "width=\"";
var heightEqual = "height=\"";
var singleQuote = "\"";
var oneSpace = " ";
var endBracket = ">";



function _toXml()
{
    var str = pictureStartTag;
    str += heightEqual;
    str += this.height;
    str += singleQuote;
    str += oneSpace;
    str += widthEqual;
    str += this.width;
    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 += pictureEndTag
 
    return str;

}


function _show()
{
  	//alert("Picture.show " + this.filename);
  	var stage = document.getElementById("stage2");
  	var caption;
  	var reduction = THUMBSHOW_REDUCTION;
  	
  	if(this.isHorizontal())
    {
        hide("caption", true);
        
        if(isSmallScreen())
        {
            reduction = SMALL_THUMBSHOW_HORIZONTAL_REDUCTION;
        }

    }
    else  // duh it's vertical
    {
    
        hide("caption", false);
    }


  	  	
  	if(isAscension)
  	{
 // 	   alert("isAscension");
        
//  	   alert("isAscension b = " + b);
        if(!this.isHorizontal())
      	{


//            alert("NOT Horizontal");    	
           	caption = document.getElementById("caption");
//           		alert(caption);
           	caption.innerHTML = "&nbsp;";     
            caption = document.getElementById("verticleCaption"); 
//            	alert(caption);
      	}
  	   else
      	{
 
 //          	alert("isHorizontal");
           	caption = document.getElementById("verticleCaption"); 
            caption.innerHTML = "&nbsp;";         	
           	caption = document.getElementById("caption"); 	  	
      	}
      	
  	}
  	else
  	{
     	caption = document.getElementById("caption"); 	
  	}
  	
//  	alert(caption);

	stage.width = (this.width * reduction);
	stage.height = (this.height * reduction);
	stage.src = this.filename + ".jpg";
   // alert("showForThumbnail() set src to\n" + stage.src);

     if(this.title == "No Caption")
     {
         caption.innerHTML = "&nbsp;";
     }
     else
     {
      	 caption.innerHTML = this.title;
     }


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


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.filename;
    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("stage2");
   str += "image width and height";
   str += sep;
   str += stage.width;
   str += " ";
   str += sep;
   str += stage.height;
   str += "\n";   
   var stageDiv = document.getElementById("stageDiv2");
  // alert(stageDiv);
   str += "stageDiv width and height";
   str += sep;
   str += stageDiv.width;
   str += " ";
   str += sep;
   str += stageDiv.height;
    
    alert(str);
}



function _isHorizontal()
{
    
    var ret = this.width > this.height; 
//    alert("isHorizontal this.width "  + this.width + " this.height " + this.height + " ret = " + ret);
    return this.width > this.height;    
}





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

// props constructor
function picture(width, height, title, filename, category, placeInArray)
{
	// props

	this.width = width;
	this.height = height;
	this.title = title;
	this.filename = filename;
	this.category = category;
	this.placeInArray = placeInArray;

	
	//functions
	this.report = _report;
	this.show = _show;
	this.isHorizontal = _isHorizontal;
	this.toXml = _toXml;
	// put in browsers memory ??
	new Image().src = this.filename + JPEG;


}

