<!--

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// Portfolio functions
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

// --------------------------------------------------------------------------------
// Uses
//  rm_browser_check.js  !!!
//  ds_popup_photo.js
//	portfolio_item.js
//	portfolio_db.js
//  portfolio_lang.js
//  SimpleTwitter.js
// --------------------------------------------------------------------------------


// 
// Library function
//
function escapeHTML( str )
{
   var div = document.createElement( 'div' );
   var text = document.createTextNode( str );
   div.appendChild( text );
   return div.innerHTML;
};




function showPortfolioThumbs()
{
	for ( idx = Portfolio.length - 1; idx >= 0; idx-- )
	{
		var itm = Portfolio[ idx ];		

		var html = 
			'<a href="#">' +
				'<img ' +
					'src="' + itm.uriThumb + '" ' +
					'border="1" ' +
					'alt="' + portfolioPhotoAlt( itm ) + '" ' +
					'title="' + portfolioPhotoAlt( itm ) + '" ' +
					'onClick="javascript: return showPortfolioItem( ' + idx + ' );" ' +
				'/>' +
			'</a>'
		;
		document.writeln( html );	
	}
}

function showPortfolioItem( /* int */ portfolioItemIndex )
{
	// retrieve the specified portfolio item from the "database".
	var itm = Portfolio[ portfolioItemIndex ];
	
	// show the, medium sized, photo.
	var imgPhoto = document.getElementById( 'photo'	);
	imgPhoto.src = itm.uriImage;
	imgPhoto.alt = portfolioPhotoAlt( itm );
	imgPhoto.title = portfolioPhotoAlt( itm );

	// set the photo information
	document.getElementById( 'model'		).innerHTML	= itm.model;	
	document.getElementById( 'photographer'	).innerHTML	= itm.photographer;	
	document.getElementById( 'date'			).innerHTML	= portfolioDate( itm.date );	 
	// DO NOT USE "description", it's already in the <head/>
	document.getElementById( 'desc'			).innerHTML = portfolioDescription( itm.description );	 
	document.getElementById( 'remarks'		).innerHTML = portfolioRemarks( itm.idxRemark );	 
	
	// set anchors href to the large photo
	var anchorLargePhoto = document.getElementById( 'largePhoto' );
	anchorLargePhoto.href = "javascript: popupPortfolioLargePhoto( " + portfolioItemIndex + " )";
	
	// retrieve the uri of the current page
	var page = location.href;
	var posQryStr = location.href.indexOf( '?' );
	if ( posQryStr != -1 ) 
	{
		// strip everything after (and including) the '?'.
		page = location.href.substring( 0, posQryStr );
	}
	
	// construct a direct link
	var directLink = page + "?pid=" + portfolioItemIndex;

	var tweetThis = document.getElementById( 'tweetThis' );
	tweetThis.href = "javascript: TweetThis( '" + itm.model + " on RopeMarks', '" + directLink + "' );";

	var directLinkAnchor = document.getElementById( 'directLink' );
	directLinkAnchor.href = directLink;
	directLinkAnchor.innerHTML = directLink; // set the text of the anchor
	
	// Embed code
	var uriRopeMarks = window.location.protocol + "//" + window.location.host + "/";
	var uriImg = uriRopeMarks + itm.uriImage
	var szImg = 240;
	var embedHtml = 
		"<!-- RopeMarks embedded portfolio code --> " +
		"<div style=\"width: " + szImg + "px; padding: 1px; margin: 2px;\">" +
			"<div style=\"text-align: center;\"> " +
				"<a href=\"" + directLink + "\" target=\"_blank\"> " +
					"<img src=\""+ uriImg + "\" width=\"" + szImg + "\" border=\"0\" /> " +
				"</a> " +
			"</div> " +
			"<div style=\"font-size: 75%;\"> " +
				"<a href=\"" + directLink + "\" target=\"_blank\">See this photo on RopeMarks</a> " +
				"<div style=\"float: right;\"> &copy; <a href=\"" + uriRopeMarks + "\" target=\"_blank\">RopeMarks</a> </div> " +
			"</div> " +
		"</div> " +
		"<!-- RopeMarks embedded portfolio code --> "
	;
	var embedCode = document.getElementById( 'embedCode' );
	embedCode.innerHTML = escapeHTML( embedHtml );
	

	// cancel the default action of executing the value of the href attribute
	return false; 
}

// test for php portfolio
function showPortfolioItem2(	/* string */ uriMediumImage,  
								/* string */ model,
								/* string */ photographer,
								/* string */ date,
								/* string */ desc,
								/* string */ remarks )
{
	// show the, medium sized, photo.
	var imgPhoto = document.getElementById( 'photo'	);
	imgPhoto.src = uriMediumImage;
	imgPhoto.alt = "";
	imgPhoto.title = "";

	// set the photo information
	document.getElementById( 'model'		).innerHTML	= model;	
	document.getElementById( 'photographer'	).innerHTML	= photographer;	
	document.getElementById( 'date'			).innerHTML	= date;	 
	// DO NOT USE "description", it's already in the <head/>
	document.getElementById( 'desc'			).innerHTML = desc;	 
	document.getElementById( 'remarks'		).innerHTML = remarks;	 
	
	// set anchors href to the large photo
	var anchorLargePhoto = document.getElementById( 'largePhoto' );
	anchorLargePhoto.href = "javascript: popupPortfolioLargePhoto( " + portfolioItemIndex + " )";

	// cancel the default action of executing the value of the href attribute
	return false; 
}

function popupPortfolioLargePhoto( /* int */ portfolioItemIndex )
{
	// Retrieve the data to be displayed in the popup
	var uriPhoto = Portfolio[ portfolioItemIndex ].uriLargeImage;
	var docTitle = Portfolio[ portfolioItemIndex ].photographer;

	// popup.js
	Popup.photo( docTitle, uriPhoto );
}

// -->
