/* easy peasy Template naming pragma:
 * 
 * function_name__template_name
 * 
 */

var Templates = $H({});		


Templates.lightbox_new__body = new Template(
	'<div id="lightboxPopUp">'
	+'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="320" height="200"><TR>'
	+'<td class="dark1" valign=bottom><DIV class="barheader">&nbsp;<FONT class="bartitle">Make a new lightbox</font></DIV></td></tr>'
	+'<tr><TD ALIGN="left" VALIGN="top" class="light1"><DIV class="light1" style="width:290px;margin:15px;"><form action="javascript:nada();" method="get" name="send"><p>Enter a name for your new lightbox in the box below '
	+'</p><p><INPUT type="text" name="lightbox_new_name" id="lightbox_new_name" size="15" class="emailbox" value="My new LB name" onfocus="if (this.value == \'My new LB name\'){ this.value=\'\';}">'
	+'<A href="javascript: return false;" onclick="lightbox_new_send(); return false;" class=lblink style="font-size: inherit; font-weight:bold;">Create the Lightbox</A><BR><BR>'
	+'Note:  You must enter a unique name for your new lighbox.  It will only be viewable by you unless you use the "E-mail this lightbox" function to share it with someone.<BR><BR>'
	+'If you do not need a lightbox anymore click the link below.<br><br><A HREF="javascript: return false;" onclick="lightbox_email(\'close\'); return false;">[X] close window</A>'
+'</div>' 
);
	
Templates.lightbox_email__body = new Template(
'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="350" height="280" class="dark1" id="emaillb_table"><TR>'
+'<td class="dark1" valign=bottom width="100%"><DIV class="barheader"><FONT class="bartitle">Email your lightbox to a friend</font></DIV></td></tr>'
+'<tr><TD ALIGN="left" VALIGN="top" width="390" class="light1"><DIV class="light1" style="margin: 15px;width:390px"><form action="javascript:nada();" method="get" name="send"><p><B>E-mail your lightbox '
+'"#{currentlbname}"</B> to a friend or colleague.</p><p><B>1.</B> Send To:<CODE>*</CODE></b></font><br><input type="text" name="to_email" id="to_email" size="35" class="emailbox" value="friend@domain.com" onfocus="if (this.value == \'friend@domain.com\') {this.value=\'\';}"><BR>'
+'<BR><B>2.</B> Message:<BR><TEXTAREA NAME="mail_text" ID="mail_text" ROWS="7" COLS="45"></TEXTAREA><BR><BR><B>3.</B> <input type="checkbox" class="checkbox" id="readonly" name="readonly" value=1> Read only<br/>'
+'<B>4.</B> <input type="checkbox" class="checkbox" name="notify" id="notify" value="1"><font class="small">Notify me when this lightbox is viewed</font>'
+'#{emaillbaddhtml}<p><A href="javascript: return false;" onclick="lightbox_email_send(); return false;" class=lblink style="font-size:inherit ;font-weight:bold;">Send the Lightbox</A>'
+'<input type="hidden" name="ot" value="2"><input type="hidden" name="dsm" value="1"></center></form><p>If you have changed your mind, click the close window link below. <br><br><A HREF="javascript: return false;" onclick="lightbox_email(\'close\'); return false;">[X] close window</A><BR>'
+'</DIV></TD></TR></TABLE>'
);
	
Templates.lightbox_rename__body = new Template(
'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="280" id="renamelb_table"><TR>'
+'<td class="dark1" valign=bottom width="100%"><DIV class="barheader">&nbsp;<FONT class="bartitle">Rename  lightbox</font></DIV></td></tr>'
+'<tr><TD ALIGN="left" VALIGN="top" width="290" class="light1"><DIV class="light1" style="margin: 15px;width:290px"><form action="javascript:nada();" method="get" name="send"><p>'
+'</p><p><INPUT type="text" name="lightbox_new_name" id="lightbox_new_name" size="15" class="lightbox_new_name" value="#{currentlbname}" onfocus=" if (this.value == \'#{currentlbname}\'){ this.value=\'\';}">'
+'<A href="javascript: return false;" onclick="lightbox_rename_send(); return false;" class=lblink style="font-size: inherit; font-weight:bold;">Rename</A><br/>'
+'<A HREF="javascript: return false;" onclick="lightbox_email(\'close\'); return false;">[X] close window</A>'
+'</form></DIV></TD></TR></TABLE>'
);

Templates.simplemessage__body = new Template(
'<DIV class=light1 style="text-align:center; width:400px; height:100px; text-align:left; padding:10px; margin-top:200px"><FONT class="header">#{message}</DIV>'
);

Templates.simplemessage__body_lightbox = new Template(
'<DIV class=light1 style="position:absolute; left:0px; bottom:0px; width:100%; height:30px; text-align:left; padding:10px 20px 10px 20px; margin-top:20px"><FONT class="header">#{message}</DIV>'
);

//this is the metadata layout for a popup
Templates.sp_act__metadata = new Template (
'<div class="previewmetadata"><span class="blah"># #{displayimageid} <b>#{rmrftype}</b> <br/> #{filesize} #{dimensions}  #{shortcaption} : #{photographer} #{imagerestrictions}'
+'<br/>'
+' </span></div>'
);

Templates.enlarge2_act__similars = new Template (
'<TD valign="top" align="left" width="120" height="440">'
+'<div style="position:relative; overflow: auto; overflow-y: auto; overflow-x: hidden; height:75%">'
+"<B>Similar Images:</B><BR>"
+'#{simcolinfo}'
+'</div></TD>'
);
	
Templates.enlarge2_act__body = new Template (
'<table cellspacing="0" cellpadding="0" border="0" width="99%" style="height:99%">'
	+'<TR height="99%">'
		+'<TD align="left" valign="top" width="99%" height="99%">'
			+'<table cellspacing="4" cellpadding="0" border="0" width="800" height="470" >'
			+'<TR><TD valign="top" align="center" width="300" height="300" style="min-width: 300px">'
				+'<div style="position:relative;text-align:center;">#{themediainsert}</div>'
			+'<br/></td>'


			+'#{similarscolumn}'
			+'<TD align="left" valign="top" width="320"><BR>'
				+'#{navbacklinks}'
				+'#{navenlargedlinks}'
				+'<br/><div id="iconlb"><a class="iconlink" href="javascript: return false;" onclick="lightbox_addto(\'#{enlargetid}\'); return false;"></a></div><a href="javascript: return false;" onclick="lightbox_addto(\'#{enlargetid}\'); return false;"> ADD TO CURRENT LIGHTBOX </a>'
				+'<br/><br/><div id="iconprice" ><a class="iconlink" href="javascript: return false;" onclick="license(\'#{enlargetid}\'); return false;"></a></div>&nbsp;<a href="javascript: return false;" id="iconpricelink"  onclick="license(\'#{enlargetid}\'); return false;"> CHECK USAGE RATES</a>'
				+'<br/><br/><div id="iconcart"><a class="iconlink" href="javascript: return false;" onclick="cart_addto(\'#{enlargetid}\'); return false;"></a></div><a href="javascript: return false;" onclick="cart_addto(\'#{enlargetid}\'); return false;"> ADD TO SHOPPING CART</a>'
				+'<br/>#{downloadcomplink}'
				+'#{ratetierinfo}'
				+'<BR/><b>Image Number:</b> #{displayenlargetid}&nbsp;[#{rmrftype}]'
				+'#{dimensions}'
				+'<br/><b>Caption:</b> #{myshortcaption}<br/>'
				+'#{releaseinfo}'
				+'#{photographerinfo}'
				+'#{filesizeinfo}'
				+'#{restrictionsinfo}'
				+'<BR/><A class="olink" id="enalarge_keywords_text" onclick="popkeys2(\'enlarge_keywords\', this); return false;">Show keywords</A><BR>'
				+'<div id="enlarge_keywords" style="display:none; overflow-y:auto;">'
				+'#{keywordinfo}'
				+'</div>'
			+'</td></TR></table>'
+'<BR></td></TR></table>'
);

Templates.hovercopyright__text = new Template (
'&copy;#{currentyear} #{baseurl}  All rights reserved <a href=/help_login.shtml#Terms_and_Conditions class=disclaimer>Terms</a> <a href=/help_faq.shtml#Privacy_Policy class=disclaimer>Privacy policy</A> &nbsp;<A HREF=/contact.shtml class=disclaimer>contact</a></FONT></nobr>'
);

Templates.footer__body = new Template (
'<DIV id="copyright"><span class="disclaimer"><A href="/aboutus_mission.shtml" onmouseover="hovercopyright();" class="disclaimer">&copy; #{currentyear} </A></span></DIV>'
);
Templates.tieredimgpricing__rfslug = new Template (
'<h4 style="text-align: left;" class=RFselectfilesize>Select a File Size</h4>'+
'<table style="text-align: left;width: 95%;" cellpadding=0 cellspacing=0 id=rfselectfilesizetable>#{rows}</table>'
);

Templates.tieredimgpricing__rfslug_row = new Template (
'<tr><td align="left" nowrap="nowrap" valign="top" style="padding-bottom: 4px; padding-top: 4px;border-bottom: solid #999 1px;" id=rfselectfilesizetabletdexpr>#{expr}</td>'+
'<td align="right" valign=top style="border-bottom: solid #999 1px;padding-bottom: 4px; padding-top: 4px;" id=rfselectfilesizetabletdcurrency>#{currency} #{price}<BR>'+
'<nobr><A href="javascript: return false;" class=orangelink onclick="cart_addto(\'#{enlargetid}\', { ln:\'#{enlargetid}\', lictype:\'RF\', base:\'#{base}\', Size_opname:\'#{id}\', usage:\'#{usage}\'}); return false;"' +
' id=rfselectfilesizetabletdaddtocart>Add to Cart</a></nobr></td></tr>' 
);

Templates.tieredimgpricing__rfextendedslug = new Template (
'<h4 style="text-align: left;" class=RFselectfilesize><br><b>Extended Licenses</b></h4>'+
'<table style="text-align: left;width: 95%;" cellpadding=0 cellspacing=0 id=rfselectfilesizetable>#{rows}</table>'
);
Templates.tieredimgpricing__rfextendedslug_row = new Template (
'<tr><td align="left" nowrap="nowrap" valign="top" style="padding-bottom: 4px; padding-top: 4px;border-bottom: solid #999 1px;" id=rfselectfilesizetabletdexpr>#{expr}<BR>' +
'(includes largest file size image)&nbsp;'+
'<a href="javascr' + 'ipt:displayWindow(\'/extended_license.shtml\',\'600\',\'640\');">view terms</a></td>'+
'<td align="right" valign=top style="border-bottom: solid #999 1px;padding-bottom: 4px; padding-top: 4px;" id=rfselectfilesizetabletdcurrency>#{currency} #{price}<BR>'+
'<nobr><a href="javascript: return false;" class=orangelink onclick="license(\'#{enlargetid}\'); return false;"></a></div>&nbsp;<a href="javascript: return false;" onclick="cart_addto(\'#{enlargetid}\', { ln:\'#{enlargetid}\', lictype:\'RF\', base:\'#{base}\', Size_opname:\'#{id}\', usage:\'#{usage}\'}); return false;">Add to Cart</a></td></tr>'
);

Templates.tieredimgpricing__rmslug = new Template (
'<h4 style="text-align: left;" class=RFselectfilesize></h4>'+
'<table style="text-align: left;width: 95%;" cellpadding=0 cellspacing=0 id=rfselectfilesizetable>#{rows}</table>'
);


Templates.tieredimgpricing__rmslug_row = new Template (
'<tr><td align="left" nowrap="nowrap" valign="top" style="padding-bottom: 4px; padding-top: 4px;border-bottom: solid #999 1px;" id=rfselectfilesizetabletdexpr>#{expr}</td>'+
'<td align="right" valign=top style="border-bottom: solid #999 1px;padding-bottom: 4px; padding-top: 4px;" id=rfselectfilesizetabletdcurrency>#{currency} #{price}<BR>'+
'<nobr><A href="javascript: return false;" class=orangelink onclick="cart_addto(\'#{enlargetid}\', { ln:\'#{enlargetid}\', lictype:\'RF\', base:\'#{base}\', Size_opname:\'#{id}\', usage:\'#{usage}\'}); return false;"' +
' id=rfselectfilesizetabletdaddtocart>Add to Cart</a></nobr></td></tr>'
);

function ImageUrl(isize,iiid,iindex){
        iurl = 'http://globaldyn.ipnstock.com/'+dynimagesname+ '/' + isize + '/' + iiid + '.JPG';

        // remote url detect
        if(typeof(iindex)=='undefined')
        {
                // seek the index of this particular id if it isn't already known
                for(iii=0;iii<id.length;iii++)
                {
                        if(id[iii] == iiid)
                               iindex =iii;
                }
        }

        /*
         test for remote size available and that we're not already in a safety mode of not available at remote location
         imagesafetymode is local "sense there is a problem with remote hosting failover";
         if url has http it's absolute otherwise use the base path
        */

        //imagesafetymode=0;
        if(typeof(primary_turl) != 'undefined' && typeof(imagesafetymode)=='undefined' && typeof(primary_turl[iindex]) !='undefined' && primary_turl[iindex].indexOf(isize)>=0)
        {
                iurl = (primary_turl[iindex].indexOf('http') >=0 ? '' :  remotemediaprefix1.split('|')[primary_turl[iindex].split('~')[0]]) + '/' + isize + '/' + iiid.substr(0,2) + '/' + iiid.substr(0,iiid.length-5) + '/' + iiid + '.JPG';
        }

        return iurl;
}


function InitSafetyCheck(isize){
        //seek first remote media id for this isize
        if(typeof(testLoadImage)=='undefined')
        {
           this.remoteAssetLoad = function(){
// 		                          alert('We are Sorry. We have detected that something is wrong with you being able to view our images.'
  //                                      + this.src + ' We will now switch you to an alternate image location. We are sorry for the delay.');
                	                imagesafetymode=1; // temporarily changes to safety mode and reverts to default hosting location
                                        currentpage();
                                        };

                if(typeof(primary_turl) == 'undefined')
                {
                                testLoadImage=new Image ();
                                remoteAssetLoad();
                }
                else
                {

                       var iii=0;
                        while( (iii < primary_turl.length) && (primary_turl[iii].indexOf(isize)<1) )
                        {        // seek the first id for this specific size
                                iii++;
                        }


                        if(iii >= primary_turl.length)
                        {
                                testLoadImage=new Image ();
                                remoteAssetLoad();
                        }
                        else
                        {
                               testLoadImage=new Image ();
                                testLoadImage.src= (primary_turl[iii].indexOf('http') >=0 ? '' : remotemediaprefix1.split('|')[primary_turl[[iii]].split('~')[0]] + '/' + isize + '/' + id[iii].substr(0,2) + '/' + id[iii].substr(0,id[iii].length-5) + '/' + id[iii] + '.JPG');

                               testLoadImage.onload = function(){
                                                  if(this.height==0 || this.width==0)
                                                  {
                                                        remoteAssetLoad();
                                                  }
                                                };

                               testLoadImage.onerror= remoteAssetLoad;
                               testLoadImage.onabort= remoteAssetLoad;

                       }
                }
        }
}




function htmlit_custom(showid){

// build html for each image depending on viewing mode
//alert("htmlit_custom, id = " + showid);
var html='';
switchpage = false;
if (id[showid]){
	var myrmrftype = rm[showid];
	myid = id[showid];
	mysimilarto=st[showid];
	if ( (myid.indexOf('Alamy',0) >= 0) || (myid.indexOf('Dreamstime',0) >= 0)){
		var temp = mysimilarto.split("|");
		mysimilarto = temp[1] ;
	}
	if (typeof(scp) != 'undefined' && (viewmode == 'list' || viewmode == 'editing') ) {myshortcaption=unescape(scp[showid]);} else {myshortcaption = "n/a";}
	var temp = true;
	var tempshortcaption='';
	myreleased = rel[showid];

	if (typeof(relcon) != 'undefined' && relcon[showid] && mysimilarto.length < 13) {  //share control style..
		var shortrel = myreleased;
		shortrel = shortrel.substring(0,16) + (myreleased.length > 16 ? '...' : '');
		myreleased = '<div id="shortrel'+showid+'">Release: '+shortrel+'</div> <div>  <form id="releasecontrol'+showid+'" > ' + relcon[showid] + ' <input type="hidden" name="shdex" value="'+showid+'"/></form> <a href="javascript: return false;" onclick="sor('+showid+'); return false;" >Save Release</a></div>';
	} 
	else if(showrelease){
		if(! ( myreleased == "MODEL RELEASED" || myreleased == "MODEL AND PROPERTY RELEASED" || myreleased == "PROPERTY RELEASED") ){
			myreleased = "Release: " + myreleased;
		}
		if (typeof(relcon) != 'undefined' && relcon[showid] && mysimilarto.length < 13)
			myreleased ='<br/>'+myreleased;

	} else { myreleased="";}
	//shorten long captions
	if(myshortcaption.length > 90){
		for(z=0; z < 130; z++){
			var c = myshortcaption.charAt(z);
			if(temp == true){
				if((z > 90) && (c == ".")){
					temp = false;
					tempshortcaption+=c + " ...";
				} else if((z > 110) && (c == " ")){
					temp = false;
					tempshortcaption+=" ...";
				} else {
					tempshortcaption+= c;
				}
			}
		}
		myshortcaption = tempshortcaption;
	}
	var thishassimilars = "yes";
	myphotographer=pho[showid];
	myrglobaldynf = rm[showid];
	myfilesize=fs[showid];
	var myhrdlink = hrdl[showid];
	var myhrdlhtml = "";
	if (myhrdlink && (id[showid].indexOf('Dreamstime',0) < 0)){
		//myhrdlhtml = '<br/><NOBR><a href="'+myhrdlink+'" class="hiresdl_link">Download Hi Res</a></nobr>';
		myhrdlhtml = '<div class="hiresdl_link"><NOBR><a href="'+myhrdlink+'" class="hiresdl_link">Download Hi Res</a></nobr></div>';
	}

	var mysharestatuses = html_share_con_opts(showid);
	var mysiteweight = html_weight_con_opts(showid);
	var mycombinedcon = html_combined_con_opts(showid);

	var thisisacoverimage_feature = '';
	if(rfcd[showid].match(myid)) //myid is in the info for the link, hence this is the cover image
	{
		var pm = unescape(rfcd[showid]).match(/SwishSearch\?n\=1\&fn\=(.*)\&supst\=cd/);
		if(pm != null)
			thisisacoverimage_feature = pm[1];
	}

	//	adminheight=10;
	if(myhrdlink){
		myhrdlink = myhrdlink.replace(/(<br>|%3cbr%3e)/ig, '');
		if (viewmode != 'editing')
			adminheight=12;
	} 
	if(myfilesize < 5){myfilesize='Scan on Demand';} //else {myfilesize+=" Mb";}
	if(myid.length > 9){
		//if ( o[showid] ){displayid=o[showid];} else {displayid=myid;}	
    displayid=myid;
    //if ( myid.indexOf('Alamy',0) >= 0){
    if (lthumb[showid] != "" ){
	//alamy sourced file.
			
			myid = myid.replace("/\s+/","");
			var temp = myid.split("|");
			if(typeof(o[showid]) != 'undefined')
				alamysrc =o[showid] + "/" +temp[1];
			else
				alamysrc = temp[2]+"/"+temp[1];
	
	//		var sthumbi='http://www.alamy.com/thumbs/2/' + alamysrc + '.jpg';
	//		var lthumbi='http://www.alamy.com/thumbs/6/' + alamysrc + '.jpg';
	//		var mthumbi='http://www.alamy.com/thumbs/4/' + alamysrc + '.jpg';
	
			var sthumbi = unescape(sthumb[showid]);	
			var mthumbi = unescape(mthumb[showid]);	
			var lthumbi = unescape(lthumb[showid]);	
			if ( myid.indexOf('Alamy',0) >= 0)
				mthumbi = unescape(sthumb[showid]);

			displayid = temp[1];
			if(typeof(o[showid]) != 'undefined')
				myid += "|"+o[showid];


	} else {
		/*var sthumbi='http://globaldyn.ipnstock.com/dyn_images/135/50/' + myid + '.JPG';
		var lthumbi='http://globaldyn.ipnstock.com/dyn_images/420/60/' + myid + '.JPG';
		var mthumbi='http://globaldyn.ipnstock.com/dyn_images/135/50/' + myid + '.JPG';*/
		var sthumbi = ImageUrl('135/50',myid);
		var mthumbi = ImageUrl('135/50',myid);
		var lthumbi = ImageUrl('420/60',myid);
		
		//var mthumbi='http://globaldyn.ipnstock.com/dyn_images/170/85/' + myid + '.JPG';
		
	}
	//alert("viewmode is"+viewmode);
		if(viewmode == "editing"){
			var theight = 160 + adminheight;

			var sharesync = unescape(shsync[showid]);
			sharesync=sharesync.split('|');
			//so 0 is type, 1 is if it matchess
			var shbg = 'white';
			if (sharesync[0] == 'shared') {
				shbg = '#77BB33';
			} else if (sharesync[0].toString().match(/notshared|rejected/)) {
				shbg = '#DF0000';
			}
			var shbdr = 'white';
			if ( parseInt(sharesync[1]) )
			{
				shbdr = 'orange';
			}
//console.log(myid+' -> '+sharesync[0]+' . '+sharesync[1]+' == '+shsync[showid]);
			if ( mysimilarto.length < 13){

				html += '<span id="cellwrapper'+myid+'" valign=bottom style="float:left;background-color:'+shbdr+'; padding:0 6px; 0 6px">';

				html += '<div id="d'+myid+'" align=center valign=bottom style=" background-color:'+shbg+'; width:288px; height:' + theight + 'px;">';
				html += '<TABLE width=298 cellspacing=2 cellpadding=0 border=0><TR><TD valign=top><div style="position:relative;height:160px;"><a href="javasc' + 'ript:enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\');"><img src="' + sthumbi + '" border=0 class=pimg vspace=2 hspace=3';
				html += " onmouseover=\"prloadimg('"+ myid +"',null,'"+showid+"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";html += '" onmouseout="hp();" id=' + myid + '>';

				html += '</a>';
				html += mycombinedcon + mysharestatuses;




				html += '</div></TD><TD valign="top"><font class=xsmall>ID:' + myid;
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
				}
				html += '<DIV class=icons>';

				if ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) )
				{
					html+='<A href="javascript:lightbox_delete_image_enl(\'' + myid + '\');" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '</DIV>';

				myphotographer = unescape(myphotographer);
				if (myphotographer.length > 18)
					myphotographer = myphotographer.substring(0,18) + '...';

				if(showphotographer == 1){html +='&copy; '+currentYear+' ' + myphotographer;}
				html += '  <nobr>';
				if(showfilesize){html += myfilesize;}

				html += '</nobr><br/>CAPTION: ' + myshortcaption+'<div>'+myreleased+'</div></font>';

				html += mysiteweight + myhrdlhtml;
				html += '<br/><div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox"></a></div>';

				html += '</TD></TR></TABLE></DIV></span></SPAN>';
			} else {

				html += '<span id="cellwrapper'+myid+'" valign=bottom style="float:left;background-color:'+shbdr+'; padding:0 6px; 0 6px;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style=" background-color:'+shbg+'; width:288px; height:' + theight + 'px;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','editing', myhrdlink, myreleased);
				html += '</DIV></span></SPAN>';
			}

		}
		else if(viewmode == "list"){
			var theight = 174 + adminheight;
			if ( mysimilarto.length < 13){	
				
				html += '<span id="cellwrapper'+showid+'" valign=bottom style="float:left;">';
				html += '<div align=center valign=bottom style="width:305px; height:' + theight + 'px;">';
				html += '<TABLE width=298 cellspacing=2 cellpadding=0 border=0><TR><TD valign=top> ';

				if(thisisacoverimage_feature) //myid is in the info for the link, hence this is the cover image
					html += '<a href="/SwishSearch?n=1&fn='+thisisacoverimage_feature+'&supst=cd" >';
				else
					html += '<a href="javascript: return false;" onclick="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;">';

				html += '<img src="' + sthumbi + '" border=0 class=pimg vspace=2 hspace=3';
				html += " onmouseover=\"prloadimg('"+ myid +"',null,'"+showid+"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";html += '" onmouseout="hp();" id=' + myid + '>';
				html += '</a><BR>';
				html += '<center>'+myhrdlhtml+'</center>';
				html += '</TD><TD valign="top"><font class=xsmall>ID:' + displayid;
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
				}
				html += '<DIV class=icons>';

				if (  ! thisisacoverimage_feature && ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) ) )	
				{
					html+='<A href="javascript: return false;" onclick="lightbox_delete_image_enl(\'' + myid + '\'); return false;" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '<div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox"></a></div>';
				html += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart"></a></div>';

                               if (myid.substr(0,10) == "Dreamstime" ) {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" 	class="iconlink" Title="Price Image"></a></div>';
				} else {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
				}               
				// html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
//					if (! thisisacoverimage_feature )
//						html += '<a href="javascript: return false;" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class=iconlink title="Enlarge image and more info"><font class=eye>i</font></a>';

				html += '</DIV>';
				
				if(showphotographer == 1){html +='<BR>&copy; '+currentYear+' ' + myphotographer;}
				html += '  <nobr>';
				if(showfilesize){html += myfilesize;}
				html += '</nobr><br/>CAPTION: ' + myshortcaption + '<div>'+myreleased+'</div></font>';


				html += '</TD></TR></TABLE></DIV></SPAN>';
			} else {	
		

				html += '<span valign=bottom style="float:left;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style="width:305px; height:' + theight + 'px;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','list');
				//html += myhrdlink + '<br/>' + myreleased + mysharestatuses;

				html += '</DIV></SPAN>';
			}
			
		
		} else if (viewmode == "tiny"){
			//adminheight += 8;
			var theight = 110 + adminheight;
			if ( mysimilarto.length < 13){	
				
				html += '<span valign=bottom style="float:left;">';
				html += '<div align=center valign=bottom style="width:95px; height:' + theight + 'px; overflow: hidden;">';

				if(thisisacoverimage_feature) //myid is in the info for the link, hence this is the cover image
					html += '<a href="/SwishSearch?n=1&fn='+thisisacoverimage_feature+'&supst=cd" ';
				else
					html += '<a href="javascript: return false;" onclick="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;"';

				if(document.page.previews.selectedIndex == 1){html +=' TITLE="ID:' + displayid;
					if(showphotographer == 1){html += '\r&copy; ' + myphotographer;}
					if(showfilesize){html += '\rSIZE: '+ myfilesize ;}
					html +=  ' \r' + 'CAPTION: ' + myshortcaption + '"';
				}
				html += '><img src=' + sthumbi + ' border=0 class=pimg vspace=1 hspace=1 height=55';
				html += " onmouseover=\"prloadimg('"+ myid +"',null,'"+showid+"'); sp(this, '" + myid + "', '" + showid + "','"+tset+"');";
				html += '" onmouseout="hp();" id=' + myid + '>';
				
				//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "')
				html += '</a><br>';
				html += '<div class=imidxxsmall>' + displayid;
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
				}
				html +='</div>'
				html += '<div class=icons>';

				if (! thisisacoverimage_feature && ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) ) )
				{
					html+='<A href="javascript: return false;" onclick="lightbox_delete_image_enl(\'' + myid + '\'); return false;" class="iconlinktiny" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '<div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlinktiny" title="Add to your current lightbox"></a></div>';
				html += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlinktiny" title="Add this image to your shopping cart"></a></div>';
                                
				if (myid.substr(0,10) == "Dreamstime" ) {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" 	class="iconlink" Title="Price Image"></a></div>';
				} else {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlinktiny" Title="Price Image"></a></div>';
				}
				
				//html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlinktiny" Title="Price Image"></a></div>';
//					if (! thisisacoverimage_feature)
//						html += '<a href="javascript: return false;" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlinktiny" title="Enlarge image and more info"><font class=eye>i</font></a>';

				html += '</DIV>';
				html += '<center>'+myhrdlhtml+'</center>';
				html += '</DIV></SPAN>';

			} else {				

				html += '<span valign=bottom style="float:left;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style="width:95px; height:' + theight + 'px; overflow:hidden;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','tiny');		
				//html += myhrdlhtml;
				html += '</DIV></SPAN>';
			}
		
		} else if (viewmode == "med"){
			//adminheight += 4; // tweaking adminheight...
			var theight = 120 + adminheight;
			if ( mysimilarto.length < 13){	
			
				html += '<span valign=bottom style="float:left;">';
				html += '<div align=center valign=bottom style="width:140px; height:' + theight + 'px; overflow: hidden;">';

				if(thisisacoverimage_feature) //myid is in the info for the link, hence this is the cover image
					html += '<a href="/SwishSearch?n=1&fn='+thisisacoverimage_feature+'&supst=cd" ';
				else
					html += '<a href="javascript: return false;" onclick="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;"';


				if(document.page.previews.selectedIndex == 1){html += ' TITLE="ID:' + displayid;
					if(showphotographer == 1){html += '  \r&copy; ' + myphotographer;}
					if(showfilesize){html += '\rSIZE: ' + myfilesize ;}
					html += ' \r' + 'CAPTION: ' + myshortcaption + '"';
				}
				html += '><img src=' + sthumbi + ' border=0 vspace=1 class=pimg hspace=1 height=80';
				html += " onmouseover=\"prloadimg('"+ myid +"',null,'"+showid+"'); sp(this, '" + myid + "', '" + showid + "','"+tset+"');";
				html += '" onmouseout="hp();" id=' + myid + '>';
					//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "')
				html += '</a><BR>';
				 html += '<DIV class="icons imidxxsmall">' + displayid;
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
				}
				html +='</DIV>'
				html += '<DIV class=icons>';

				if (! thisisacoverimage_feature && ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) ) )
				{
					html+='<A href="javascript: return false;" onclick="lightbox_delete_image_enl(\'' + myid + '\'); return false;" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '<div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox"></a></div>';
				html += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart"></a></div>';
                                
				if (myid.substr(0,10) == "Dreamstime" ) {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" 	class="iconlink" Title="Price Image"></a></div>';
				} else {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
				}
//					if (! thisisacoverimage_feature)
//						html += '<a href="javascript: return false;" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font></a>';

				html += '</DIV>';
				html +=myhrdlhtml;
				
				

				html += '</DIV></SPAN>';

			} else {				

				html += '<span valign=bottom style="float:left;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style="width:140px; height:' + theight + 'px;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','med');		
				//if(myhrdlink)
					//html += myhrdlhtml;
				html += '</DIV></SPAN>';
			}
		} else if (viewmode == "ss"){			
			html = '  ';
		} else if (viewmode == "huge"){		
			var theight = 245 + adminheight;
			if ( mysimilarto.length < 13){	
				html += '<span valign=bottom style="float:left;">';
				html += '<div align=center valign=bottom style="border:solid 0px #ccc;width:330px; height:' + theight + 'px; overflow: hidden;">';

				if(thisisacoverimage_feature) //myid is in the info for the link, hence this is the cover image
					html += '<a href="/SwishSearch?n=1&fn='+thisisacoverimage_feature+'&supst=cd" ';
				else
					html += '<a href="javascript: return false;" onclick="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" TITLE="ID:' + displayid;

				if(showphotographer == 1){html += '\r&copy; ' + myphotographer;}
				if(showfilesize){html +=   '\rSIZE: ' + myfilesize ;}
				html += ' \r' + 'CAPTION: ' + myshortcaption + '"><img src="' + lthumbi + '" border="0" vspace="1" hspace="3" alt="loading..." height="192"></a><BR>';
				html += '<div class="icons" style="margin:0px 20px 0px 20px;width:290px;text-align:center" align=center>';
				html += displayid;
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font> ';
				}
					html += '</div>';
				html += '<DIV class=icons align=center>';

				if ( ! thisisacoverimage_feature && ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) ) )
				{
					html+='<A href="javascript: return false;" onclick="lightbox_delete_image_enl(\'' + myid + '\'); return false;" class="lblink" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '<div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox"></a></div>';
				html += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart"></a></div>';

				//html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
                                if (myid.substr(0,10) == "Dreamstime" ) {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" 	class="iconlink" Title="Price Image"></a></div>';
				} else {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
				}

//if (! thisisacoverimage_feature)
		//			html += '<a href="javascript: return false;" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font> ENLARGE</a> ';

				html += '</div>'+ myhrdlhtml;

				html += '</div></SPAN>';
				
			} else {
				html += '<span valign=bottom style="float:left;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style="width:330px; height:' + theight + 'px; overflow: hidden;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','huge');
				//html += myhrdlhtml;

				html += '</DIV></SPAN>';
			}				
		} else if (viewmode == "large"){
			var theight = 199 + adminheight;
			if ( mysimilarto.length < 13){		
				html += '<span valign=bottom style="float:left;">';
				html += '<div align=center valign=bottom style="width:187px; height:' + theight + 'px; overflow:hidden;">';
				if(thisisacoverimage_feature) //myid is in the info for the link, hence this is the cover image
					html += '<a href="/SwishSearch?n=1&fn='+thisisacoverimage_feature+'&supst=cd" ';
				else
					html += '<a href="javascript: return false;" onclick="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;"'

				if(document.page.previews.selectedIndex == 1){html += ' TITLE="ID:' + displayid;
					if(showphotographer == 1){html +=  '\r&copy; ' + myphotographer;}
					if(showfilesize){html += '\rSIZE: ' + myfilesize ;}
					html += ' \r' + 'CAPTION: ' + myshortcaption + '"';
				}
				html += '><img src="' + sthumbi + '" class=pimg border="0" vspace="0" hspace="3"';
				html += " onmouseover=\"prloadimg('"+ myid +"',null,'"+showid+"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";
				html += '" onmouseout="hp();" id=' + myid + '>';
				
				html += '</a><br>';
				html += '<div><font class=imid>' + displayid + '</font>';
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
				}
				html +='</div>';
				html += '<div class=icons>';

				
				if (! thisisacoverimage_feature && ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) ) )						{
					html+='<A href="javascript: return false;" onclick="lightbox_delete_image_enl(\'' + myid + '\'); return false;" class="iconlink" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '<div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox"></a></div>';
				html += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart"></a></div>';
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
//					if (! thisisacoverimage_feature )
//						html += '<a href="javascript: return false;" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font></a>&nbsp;';

				html += '</div>';

				html += '<center>'+myhrdlhtml+'</center>';

				html += '</DIV></SPAN>';
	
		
			} else {			
				html += '<span valign=bottom style="float:left;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style="width:187px; height:' + theight + 'px; overflow: hidden;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','large');
				//html += myhrdlhtml;

				html += '</DIV></SPAN>';
			}
		} else {
			var theight = 174 + adminheight;
			if ( mysimilarto.length < 13){		
				html += '<span valign=bottom style="float:left;">';
				html += '<div align=center style="width:152px; height:' + theight + 'px; overflow:hidden;">';
				if(thisisacoverimage_feature) //myid is in the info for the link, hence this is the cover image
					html += '<a href="/SwishSearch?n=1&fn='+thisisacoverimage_feature+'&supst=cd" ';
				else
					html += '<a href="javascript: return false;" onclick="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;"'


				if(document.page.previews.selectedIndex == 1){html += ' TITLE="ID:' + displayid;
					if(showphotographer == 1){html +=  '\r&copy; ' + myphotographer;}
					if(showfilesize){html += '\rSIZE: ' + myfilesize ;}
					html += ' \r' + 'CAPTION: ' + myshortcaption + '"';
				}
				html += '><img src="' + mthumbi + '" class=pimg border="0" vspace="0" hspace="3"';
				html += " onmouseover=\"prloadimg('"+ myid +"',null,'"+showid+"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";
				html += '" onmouseout="hp();" id=' + myid + '>';
				
				html += '</a>';
				 html += '<div style="margin-top: 0px;"><font class=imid>' + displayid + '</font>';
				if(typeof(suppressrmrftype) == 'undefined'){
					html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
				}
				html +='</div>';
				html += '<DIV class=icons>';

				
				if (! thisisacoverimage_feature && ((typeof(pre_q_args) != 'undefined' && pre_q_args.match(/fn=/) ) || (typeof(q_args) != 'undefined' && ( q_args.match(/vmo=/) || q_args.match(/rid=/) || q_args.match(/lb_view=1/) || q_args.match(/fn=/))) ) )						{
					html+='<A href="javascript: return false;" onclick="lightbox_delete_image_enl(\'' + myid + '\'); return false;" class="iconlink" TITLE="Remove this image from the lightbox">X</A>';
				}

				html += '<div id="iconlb"><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox"></a></div>';
				html += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart"></a></div>';
				if (myid.substr(0,10) == "Dreamstime" ) {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="hp(); enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" 	class="iconlink" Title="Price Image"></a></div>';
				} else {
				html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
				}
				//html += '<div id="iconprice"><a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image"></a></div>';
//					if (! thisisacoverimage_feature)
//						html += '<a href="javascript: return false;" ONCLICK="enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\'); return false;" class="iconlink" title="Enlarge image and more info"><font class=eye>i</font></a>&nbsp;';
				html += '</div>';
				html += '<center>'+myhrdlhtml+'</center>';


				html += '</DIV></SPAN>';
	
		
			} else {			
				html += '<span valign=bottom style="float:left;">';
				html += '<div id="d' + myid + '" align=center valign=bottom style="width:152px; height:' + theight + 'px; overflow: hidden;">';
				html += writesimilar(myid,showid,myphotographer,myshortcaption,'start','normal');
				//html += myhrdlhtml;

				html += '</DIV></SPAN>';
			}

		}
	}
} 
return html;
};


function buildpages(startnumber,endnumber,snum){
suspendtrap=1;

//builds pulldown menu for page numbers depending on pixperpage and total pagenumbers
var thehtml= '';
//var thehtml= '<table width="100%"><tr><td valign="top">';

thehtml+= '<NOBR>';

//pagenumbers
var showstartnumber = parseInt(startnumber) + parseInt(snum) + 1;
var showendnumber = parseInt(endnumber) + parseInt(snum);


	//thehtml +='<div style="float:right;margin-top:0px">testsfd</div>';
	//thehtml +='<div style="float:right;margin-top:0px">testsfd</div>';
if ( showstartnumber <= results_total )
{
	if(grange != "outofrange"){
		thehtml+='<div id="buttonnext"><a href="javascript: return false;" onclick="document.currentLayer1Mode=\'searchresults\';nextpage(); return false;"></a></div>';
	}else{
	thehtml+='<div id="sbuttonnext"></div>';
	}
	thehtml +='<div style="float:right;margin-top:0px">&nbsp;&nbsp;';

	thehtml+='<SELECT name="pageurl" align="middle"  onChange="document.currentLayer1Mode=\'searchresults\'; self.location=this.options[this.selectedIndex].value; return false;" class="smallmenu">';

	totalpages=(  Math.ceil((snum)/( parseInt( $F('pixperpage') ))) +  Math.ceil( (results_total - snum) / ( parseInt( $F('pixperpage') )  ))) ;
	if(Number(currentpagenum) > 52){psn = (Number(currentpagenum) - 50);} else { psn = 1;}

	if((Number(totalpages) - Number(currentpagenum)) > 50){ pen = (Number(currentpagenum) + 50);} else {pen = totalpages;}
	if(psn >1 && currentpagenum != 0){
		thehtml+='<option value="' + nextlink + 'snum=' + ((psn - 2) * (parseInt(gpixperpagev))) + '">&lt; ' + (Number(psn) - 1) + '</option>';
	}

	for(i=psn;i <= pen;i++){
		if(i == (Number(currentpagenum) + 1)){
			thehtml+='<option value="' + nextlink + 'snum=' + ((i-1) * (parseInt(gpixperpagev))) + '" selected>' + i + '</option>';
		} else {
			thehtml+='<option value="' + nextlink + 'snum=' + ((i-1) * (parseInt(gpixperpagev))) + '">' + i + '</option>';
		}
	}

	if(pen != totalpages){
		thehtml+='<option value="' + nextlink + 'snum=' + ((Number(pen)) * (parseInt(gpixperpagev))) + '">&gt; ' + (Number(pen) + 1) + '</option>';
	}


	thehtml+='</select>';
	thehtml +=  '&nbsp;of&nbsp;<span id="imgtotal">' + totalpages + '</span>';
	thehtml += '&nbsp;&nbsp;</div>';	
	
//	thehtml += '&nbsp;&nbsp;[' + showstartnumber + '-';
	/*
	if (showendnumber > parseInt(results_total)){
	} else {
		thehtml += &nbsp;of&nbsp;<span id="imgtotal">' + results_total + '</span>';
	}
	thehtml += '</NOBR>';
	*/

	//thehtml += '</td><td align="right">';

	//linkback to feature:
	if (document.thisIsFeatureView)
	{
		//thehtml += '<a href="/R?'+feat_requestview+'" style="color:#c00; font-size:10px"><nobr>View images from</nobr> <br/><nobr><b>All IPN Members</b></nobr></a>';
	}

	if (typeof(shsync) == 'object' && shsync[0] && shsync[0] != '')
	{
		var lochtml = '<a onclick="return save_all_releases();" href="javascript: return false;">Save All Releases</a> &nbsp;&nbsp; [ Set All: <a href="javascript: return false;" onclick="return share_set_page(\'shared\'); ">Accepted</a> | <a href="javascript: return false;" onclick="return share_set_page(\'rejected\'); ">Rejected</a> | <a href="javascript: return false;" onclick="return share_set_page(\'pending\'); ">Pending</a>  &nbsp;|&nbsp;  <a onclick="return release_set_page(\'NOT RELEASED\');" href="javascript: return false;" title="NOT RELEASED">NR</a> | <a onclick="return release_set_page(\'NOT APPLICABLE\');" href="javascript: return false;" title="NOT APPLICABLE">NA</a> | <a onclick="return release_set_page(\'NOT RECOGNIZABLE\');" href="javascript: return false;" title="NOT RECOGNIZABLE">NR</a> | <a onclick="return release_set_page(\'MODEL AND PROPERTY RELEASED\');" href="javascript: return false;" title="MODEL AND PROPERTY RELEASED">MaPR</a> ]';
		$('Layerpreviews').innerHTML = lochtml;
	}
}
//conditional previous page
if(Number(currentpagenum) > 0){
	thehtml+='<div id="buttonprev"><a href="javascript: return false;" onclick="document.currentLayer1Mode=\'searchresults\';prevpage(); return false;"></a></div>';
} else if (showstartnumber <= results_total){
	thehtml+='<div id="sbuttonprev"></div>';
}

//	thehtml += '</td></tr></table>';
$('Layerpages').style.overflow = 'visible';
$('Layerpages').style.visibility='visible';
MM_setTextOfLayer('Layerpages','',thehtml);
//	setbackpagetrap(showstartnumber,snum,viewmode);
};

/*
function buildimages(startnumber,mode,resized){
if(typeof(cartview) != 'undefined' && cartview)
	return;

if(typeof(id) == 'undefined')
	return;

var showstartnumber = parseInt(startnumber) + parseInt(snum) + 1;
var section = $H({ showstart:showstartnumber, snum:startnumber, viewmode:viewmode, buildmode:mode, resized:resized }).toJSON();
try { YAHOO.util.History.navigate("nav", section); } catch (e) { dispatchAll(section); }
};

*/

function prloadimg(prid,crop,sid){

 if ((prid.indexOf('Alamy',0) >= 0) || (prid.indexOf('Dreamstime',0) >= 0)){
	//alamy sourced file.

			prid = prid.replace("/\s+/","");
			temp = prid.split("|"); 
			alamysrc =temp[2] + "/" + temp[1];
			prid = temp[1];
			var lthumbi='http://www.alamy.com/thumbs/6/' + alamysrc + '.jpg';
			var lthumbi=unescape(lthumb[sid]);

	} else {
//		var lthumbi ='http://globaldyn.ipnstock.com/dyn_images/420/60/' + prid + '.JPG';
		var lthumbi = ImageUrl('420/60',prid);
	}



if (! $("pimid"))
	document.body.appendChild( Builder.node('div',{id:'pimid',style:'position:absolute; top:-500px'}) );

var theImgAttrs = $H({
	id:'previewimg_' + prid, src:'http://www.ipnstock.com/graphics/loading.png', border:0, alt:'Loading...', lowsrc:'/graphics/spacer.gif'
});
if(winH < 450){
	smallscreen=1;
	if(typeof(crop)!= 'undefined'){//smallscreen using orientation to decide limiter
		if(crop=='panoramic'){
			theImgAttrs['width'] = 420;
		} else if(crop=='vertical'){
			theImgAttrs['height'] = ((winH - 100) < 180) ? 180 : (winH - 100);
		} else {
			theImgAttrs['height'] = ((winH - 142) < 160) ? 160 : (winH - 142);
		}
	} else {
		theImgAttrs['height'] = 135;
	}
} else {
	smallscreen=0;
}
$("pimid").innerHTML = '';
$('pimid').style.visibility="hidden";
var theNode =
Builder.node('div', {id:'previewpaneshadow2'},[
	Builder.node('div',{id:'previewpaneshadow1'},[
		Builder.node('div',{id:'previewpane'},[
			Builder.node('div', {style:'padding: 2px 2px 2px 2px;', align:'center'},
				[ Builder.node('img', theImgAttrs) ]
			),
			Builder.node('div',{id:'previewpane_metdat_'+prid},'')
		]),
		Builder.node('img', {src:""+lthumbi, style:'display:none', onload:"if($('previewimg_"+prid+"')) $('previewimg_"+prid+"').src = this.src"})
	])
]);
$("pimid").appendChild(theNode);
};


function getThumbnailSrc(tid){

//var sthumbi='http://globaldyn.ipnstock.com/dyn_images/135/50/' + tid + '.JPG';
var sthumbi = ImageUrl('135/50',tid);

if ((tid.indexOf('Alamy',0) >= 0) || (tid.indexOf('Dreamstime',0) >= 0)){
	//alamy sourced file.
		for(var i=0;i<st.length;i++){
			
			if(st[i].replace(/^\s+|\s+$/,"") == tid)
				return unescape(sthumb[i]);
			
		}
/*
			tid = tid.replace("/\s+/","");
			var alamysrc =tid.replace("Alamy|","") ;
			var temp = tid.split("|");
			alamysrc =temp[2] + "/" + temp[1];
			sthumbi='http://www.alamy.com/thumbs/2/' + alamysrc + '.jpg';
*/

 }
return sthumbi ;
}


function setuppagesize_cellsizes_custom()
{
var cellh = 174;
    imagerows=Math.floor(winH/(cellh + adminheight));
    imagespaceheight=imagerows * (cellh + adminheight);
    area=imagerows * Math.floor(winW/152);

    if(! viewmode && imagerows == 1)
    {
	viewmode='med';
	gsetCookie('gviewmode','med', '', '/', gGetCookieDom());
    }

    if(viewmode){
	if(viewmode == 'table'){
		var cellh=174;
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('135/50');};
		imagerows=Math.floor(winH/(cellh + adminheight));
		if(imagerows == 0)
		 imagerows=1;
		imagespaceheight=imagerows * (cellh + adminheight);
		area=imagerows * Math.floor(winW/152);
		vertremainder=Math.floor((winH - (imagerows*(cellh + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/152) * 152))      /    Math.floor(winW/152)             );
	} else  if(viewmode == 'editing'){
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('135/50');};
		imagerows=Math.floor(winH/(160 + adminheight));
		if(imagerows == 0)
			imagerows=1;
		imagespaceheight=imagerows * (160 + adminheight);
		area=imagerows * Math.floor(winW/300.00);
		vertremainder=Math.floor((winH - (imagerows*(160 + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/300) * 300))      /    Math.floor(winW/300)             );
	} else  if(viewmode == 'list'){
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('135/50');};
		imagerows=Math.floor(winH/(152.00 + adminheight));
		if(imagerows == 0)
			imagerows=1;
		imagespaceheight=imagerows * (152 + adminheight);
		area=imagerows * Math.floor(winW/300.00);
		vertremainder=Math.floor((winH - (imagerows*(152 + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/300) * 300))      /    Math.floor(winW/300)             );
	} else  if (viewmode == 'tiny'){
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('135/50');};
		imagerows=Math.floor(winH/(110.00 + adminheight));
		if(imagerows == 0)
			imagerows=1;
		imagespaceheight=imagerows * (110 + adminheight);
		area=imagerows * Math.floor(winW/95.00);
		vertremainder=Math.floor((winH - (imagerows*(110 + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/95) * 95))      /    Math.floor(winW/95)             );
	} else if (viewmode == 'med'){
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('135/50');};
		imagerows=Math.floor(winH/(120.00 + adminheight));
		if(imagerows == 0)
			imagerows=1;
		imagespaceheight=imagerows * (120 + adminheight);
		area=imagerows * Math.floor(winW/140.00);
		vertremainder=Math.floor((winH - (imagerows*(136 + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/140) * 140))      /    Math.floor(winW/140)             );
	} else if (viewmode == 'huge'){
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('420/60');};
		imagerows=Math.floor(winH/(245.00 + adminheight));
		if(imagerows == 0)
			imagerows=1;
		imagespaceheight=imagerows * (245 + adminheight);
		area=imagerows * Math.floor(winW/330.00);
		vertremainder=Math.floor((winH - (imagerows*(240 + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/330) * 330))      /    Math.floor(winW/340)             );
	} else if (viewmode == 'large'){
		if(typeof(InitSafetyCheck)=='function'){InitSafetyCheck('420/60');};
		imagerows=Math.floor(winH/(199 + adminheight));
		if(imagerows == 0)
		   imagerows=1;
		imagespaceheight=imagerows * (199 + adminheight);
		area=imagerows * Math.floor(winW/187.00);
		vertremainder=Math.floor((winH - (imagerows*(199 + adminheight)))/imagerows);
		horizremainder=Math.floor(    (winW - (Math.floor(winW/187) * 187))      /    Math.floor(winW/187)             );

	}
    }
}


function enlarge2_act__generateTierRows(myratetiers_data,myrmrftype,enid,encount,user_tier,extended_license) {
var myratetiers = '';
if ( myrmrftype == 'RF')
{
	var tieredimgpricing__rfslug_row = '';
	var tieredimgpricing__rfextendedslug_row = '';
	$A(myratetiers_data.tierinfo).each(function(rowi){
				Object.extend(rowi,  {
					enlargetid: myratetiers_data.image_id,
					usage: rowi.subof,
					img_id: enid,
					encount: ( encount ? encount : "''" ),
					price : (rowi.price_additive != "0" ? rowi.price_additive: rowi.price)
				});
				if(!((rowi.expr).match(/Extended/)))
					tieredimgpricing__rfslug_row += Templates.tieredimgpricing__rfslug_row.evaluate(rowi);
				else
					tieredimgpricing__rfextendedslug_row += Templates.tieredimgpricing__rfextendedslug_row.evaluate(rowi);
		});
	myratetiers = Templates.tieredimgpricing__rfslug.evaluate({ 'rows' : tieredimgpricing__rfslug_row });
	if(extended_license)
		myratetiers += Templates.tieredimgpricing__rfextendedslug.evaluate({ 'rows' : tieredimgpricing__rfextendedslug_row });
		
}
else if ( myrmrftype == 'RR' )
{
	var tieredimgpricing__rrslug_row = '';
	$A(myratetiers_data.tierinfo).each(function(rowi){
				Object.extend(rowi, {
					enlargetid: myratetiers_data.image_id,
					usage: rowi.subof,
					img_id: enid,
					encount: ( encount ? encount : "''" )
				});
				//if image is priced out, then include remove button..
				if (rowi.opt_selected == 1)
					rowi.removebutton = Templates.tieredimgpricing__rrslug_row_removebutton.evaluate(rowi);

				tieredimgpricing__rrslug_row += Templates.tieredimgpricing__rrslug_row.evaluate(rowi);
		});
	myratetiers = Templates.tieredimgpricing__rrslug.evaluate({ 'rows' : tieredimgpricing__rrslug_row });
}
return myratetiers;
}




function enlarge2_act(enid,encount,featuredimage,preMem) {
	

featuredimage = ( featuredimage == 'undefined' ? '' : featuredimage );
debug('featuredimage',featuredimage);
hp();//ensure closure the preview window
var useInPage = 0;
if ( id[encount] == document.JSONobj.getImgDat('id') || featuredimage.length==10 || id[encount] == (document.JSONobj.getImgDat('orig_id')))
	useInPage = 1;
debug('useInPage',useInPage);


if (useInPage || ( document.ajaxLoaded && (enid.match( document.JSONobj.getImgDat('id') )) ) )//made it
{
	//wipe viewmode cookie:
	if(typeof(viewmode) != 'undefined' && viewmode == 'ss')
		gsetCookie("gcurrentview",'', '', '/', gGetCookieDom());


//              if( featuredimage || preMem == 'cartview' || ( useInPage && id[encount] )
//              {
		if($('cdheader'))
			$('cdheader').style.display = 'none';


		//init
		if ( (! document.thisIsFeatureView && useInPage && st[encount] && st[encount].length > 13) || overflowtype == 'hidden' )
			suspendtrap=1;
		//gSetBackpage();
		if(firstpictureonpage)
			gsetCookie("gwhichstartpage",firstpictureonpage, '', '/', gGetCookieDom());

		//set metatdata variables
		var myshortcaption;
		var testshortcaption = document.JSONobj.getImgDat('short_caption');
		testshortcaption = (    testshortcaption        ?  testshortcaption : "n/a");
		var testlongcaption = document.JSONobj.getImgDat('long_caption');
		testlongcaption = (     testlongcaption ?  testlongcaption : "n/a");
		if ( typeof(uselongcaption) != 'undefined' && testlongcaption != "n/a" )
		{
			if ( uselongcaption == 'useboth' )
			{
				if ( testshortcaption == "n/a" ) //then just use long
				{
					myshortcaption = testshortcaption;
				}
				else //build switcher
{
					myshortcaption = '<span id="enlarge_short_caption">'+testshortcaption+
						' <a href="javascript: return false;" onclick="$(\'enlarge_short_caption\').style.display=\'none\'; $(\'enlarge_long_caption\').style.display=\'inline\'; return false;">more&nbsp;&gt;&gt;</a></span><span style="display:none" id="enlarge_long_caption">'+testlongcaption+'  <a href="javascript: return false;" onclick="$(\'enlarge_long_caption\').style.display=\'none\'; $(\'enlarge_short_caption\').style.display=\'inline\'; return false;">&lt;&lt;&nbsp;less</a></span>'
				}
			}
			else
			{
				myshortcaption = testlongcaption;
			}

		}
		else
		{
			myshortcaption = testshortcaption;
		}


		var myrmrftype = document.JSONobj.getImgDat('rmrftype');
		//var myratetiers = document.JSONobj.getImgDat('rfcdimgpricing'); //this is currently preformatted list from templates, could
							//be extended in ajaxhandlers to return a data obj if we need
							//more granular data
		var user_tier = document.JSONobj.getImgDat('user_tier');
		var myratetiers_data = document.JSONobj.getImgDat('tieredimgpricing'); //myratetiers is a data object now.. so build..
		 var extended_license = (typeof (document.JSONobj.getImgDat('extended_license')) != 'undefined') ? document.JSONobj.getImgDat('extended_license') : 0;
		if(typeof(o[encount]) != 'undefined'){
			if((o[encount].indexOf('Dreamstime',0)>=0))
				extended_license=1;
		}
		if(enid.indexOf('Dreamstime',0)>=0)
			extended_license=1;
	
		var myratetiers = enlarge2_act__generateTierRows(myratetiers_data,myrmrftype,enid,encount,user_tier,extended_license)


		var myphotographer      = document.JSONobj.getImgDat('photographer') +
				((document.JSONobj.getImgDat('agent_name') && document.JSONobj.getImgDat('agent_name') != '') ? '&nbsp;/&nbsp;'+document.JSONobj.getImgDat('agent_name') : '' );
		var myfilesize = (      document.JSONobj.getImgDat('file_size') < 5 ?
				'Scan on Demand'
					:
				document.JSONobj.getImgDat('file_size') + ' Mb');
		var myreleased = document.JSONobj.getImgDat('released');
		var myrestrictions = document.JSONobj.getImgDat('image_restrictions');
		var mycompallow = document.JSONobj.getImgDat('comp_allow');
		var mydimensions = ( typeof(showdimensions) != 'undefined' ? document.JSONobj.getImgDat('dimensions') : '');
		if (mydimensions) //comes as <XVAL>x<YVAL>
		{
			var dimr = mydimensions.match(/^(\d+)x(\d+)$/);
			if (typeof(dimr) == 'object')
				mydimensions = '<br/><b>Original Dimensions:</b>&nbsp;'+dimr[1]+'px&nbsp;x&nbsp;'+dimr[2]+'px';
		}

		var nextimage = parseInt(encount) + 1;
		var nextimageid = id[nextimage];
		var previmage = parseInt(encount) - 1;
		var previmageid = id[previmage];

		if(nextimageid  != undefined){
			if ((nextimageid.indexOf('Alamy',0) >= 0) || (nextimageid.indexOf('Dreamstime',0)>=0)){
				if(typeof(o[nextimage]) != 'undefined')
					nextimageid +="|"+o[nextimage];

			}
		}
		if(previmageid != undefined){
			if(  (previmageid.indexOf('Alamy',0) >= 0) || (previmageid.indexOf('Dreamstime',0) >= 0)){
				if(typeof(o[previmage]) != 'undefined')
					previmageid +="|"+o[previmage];
			}
		}

		//this ifblock becomes template var: themediainsert
		var themediainsert = '';
		var nextimagesrc = '';
		//var nextimagesrc = "http://globaldyn.ipnstock.com/'+dynimagesname+'/420/60/' + nextimageid + '.JPG";
		if(nextimageid != undefined)
			nextimagesrc = ImageUrl('420/60',nextimageid);

		if((! document.thisIsFeatureView) && useInPage && v[encount] && (v[encount] == 'H')){
			var temph= + enid.substring(0,2) + '/' + enid.substring(0,5) + '/' + enid;
			themediainsert += '<EMBED SRC="http://tools.cgibackgrounds.com/qtvideo/' + temph + '.MOV" WIDTH=420 HEIGHT=280></EMBED>';

		} else {
			var tarid = '0000000000';
			if(featuredimage){tarid = featuredimage;} else {tarid= enid;}
			debug('tarid',tarid);
		//	var themediainsert_src =' http://globaldyn.ipnstock.com/'+dynimagesname+'/'+ ( (typeof(localwatermark) != 'undefined' && ! pngsupport) ? 'wm' : '420' )+'/60/'+tarid+'.JPG';
			var themediainsert_src = ImageUrl(( (typeof(localwatermark) != 'undefined' && ! pngsupport) ? 'wm' : '420')+'/60',tarid);

	//alamy sourced file.

/*
			if ((enid.indexOf('Alamy',0) >= 0)){
			var temp =enid.split("|");
			var alamysrc;
			if(typeof(o[encount]) != 'undefined')
				alamysrc = o[encount]+"/"+temp[1];
			else
				alamysrc = temp[2]+"/"+temp[1];
			themediainsert_src ='http://www.alamy.com/thumbs/6/' + alamysrc + '.jpg';

			 }
*/

			if(lthumb[encount] != "" && useInPage){
				themediainsert_src = unescape(lthumb[encount]);
			}

			if(typeof(lthumb[nextimage])!='undefined' && lthumb[nextimage] != "" && useInPage){
				nextimagesrc = unescape(lthumb[nextimage]);
		       }

			if(typeof(document.JSONobj.getImgDat('lthumb')) != 'undefined'){
				if(document.JSONobj.getImgDat('lthumb') != '')
					 themediainsert_src = unescape(document.JSONobj.getImgDat('lthumb'));
			}

		themediainsert += '<A HREF="javascript: return false;" onclick="currentpage(); return false;">'
				+'<img src="'+ themediainsert_src
				+'" border=1 style="display:inline; clear:none;" id="'+tarid+'">'
				+( (typeof(localwatermark) != 'undefined' && pngsupport) ?
					'<img style="z-index: 300; position:absolute; left:0px; bottom:0px;" src="'+localwatermark+'" border="0" onload="fitMeTo(\''+tarid+'\', this)"/>'
					:
					'');
			themediainsert += '</A>';
		}
	     //similarscolumn
		var similarscolumn = '';
		if(! document.thisIsFeatureView && useInPage && st[encount] && st[encount].length > 13 && (( st[encount].indexOf('Alamy',0) < 0) && ( st[encount].indexOf('Dreamstime',0) < 0))){
			var simlist =st[encount];
			var simarray=simlist.split(" ");
			var temparray = simarray[1].split(",");
			if(temparray.length > 1){temparray=simarray[0] + ' ' + temparray.join(' ');simarray=temparray.split(' ');}
			var simcount =simarray.length;
			if(simcount>40){simheight=(70 - simcount/2)} else {simheight=70 - simcount;}

			var simcolinfo = '';
			for(var i=0;i< simcount;i++){
				simcolinfo += '<span valign=bottom style="float:left;">'
							+'<a href="javasc' + 'ript:enlarge2(\'' + enid + '\'' + ',' + '\'' + encount + '\',\'' + simarray[i] + '\');" TITLE="ID:' + simarray[i];
				if(showphotographer == 1)
					simcolinfo += '  \r&copy; ' + myphotographer;

				simcolinfo += ' click image to view similar"><img src="' + ImageUrl('135/50',simarray[i]) + '" border=0 vspace=2 hspace=2 height=' + simheight + ' align=left></a></span>';
			}
			similarscolumn = Templates.enlarge2_act__similars.evaluate({simcolinfo: simcolinfo});
		}


	     //this ifblock becomes var navbacklink
		//will become navenlargedlinks
		var navenlargedlinks = '';
		var navbacklink = '';
		    if (preMem == 'cartview')
		    {
			navbacklink = '<A HREF="javascript: return false;" onclick="document.currentLayer1Mode=\'cartview\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom());currentpage(); return false;"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO CART</A><BR><BR>';
		    }
		    else if (document.thisIsFeatureView)
		    {
			navbacklink = '<A HREF="javascript: return false;" onclick="document.currentLayer1Mode=\'searchresults\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom()); self.location = self.location; return false;"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO REQUEST RESULTS</A><BR><BR>';
		    }
		    else
		    {
			navbacklink = '<A HREF="javascript: return false;" onclick="document.currentLayer1Mode=\'searchresults\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom());$(\'Layerpages\').style.visibility=\'visible\';currentpage();$(\'row2\').style.display=\'block\'; return false; "><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO SEARCH RESULTS</A><BR><BR>';
		    }

		if ( useInPage )
		{
		    if(preMem != 'cartview')
		    {
			if((snum + encount) > 0){ navenlargedlinks+= '                                  <A HREF="javascript: return false;" onclick="enlarge2(\'' + previmageid + '\',\'' + previmage + '\'); return false;" TITLE="GO TO THE PREVIOUS IMAGE"><FONT style="font-size:9pt; font-family: Arial;">&#8592;</FONT> PREV IMAGE </A>&nbsp;&nbsp;';}
			if((Number(snum) + Number(encount) + 1) < Number(results_total)){ navenlargedlinks+= '                                  <A HREF="javascript: return false;" onclick="enlarge2(\'' + nextimageid + '\',\'' + nextimage + '\'); return false;" TITLE="GO TO THE NEXT IMAGE">NEXT IMAGE <FONT style="font-size:9pt; font-family: Arial;">&#8594;</FONT></A><BR>';}
		    }
		}

	     var enlargetid = '';
		if(featuredimage){ enlargetid = featuredimage;} else {  enlargetid = enid;}

		//will become downloadcomplink
		var downloadcomplink = '';
		if(preMem != 'cartview')
		{
			if(gsession && gusername && mycompallow == 'Y') {
				downloadcomplink = '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="Javascr' + 'ipt:displayWindow(\'/comp_view.shtml?' + gusername + '/' + cs[encount] + '/' +
				enlargetid
				+ '.JPG\',\'600\',\'640\');"> DOWNLOAD COMP</a><BR><BR>';
			} else {
			if(gsession) {
				downloadcomplink = '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="Javascr' + 'ipt:displayWindow(\'/comp_view.shtml?guest/' + cs[encount] + '/' +
				enlargetid
				+ '.JPG\',\'600\',\'640\');"> DOWNLOAD COMP</a><BR><BR>';
				}
			}
		}


		// META DATA FOR ENLARGED TARGET IMG:

		//will become: ratetierinfo
		var ratetierinfo = ( myratetiers ? '<BR/><div class="enlargeratetiers">' + myratetiers + '</div>' : '' );

		//becomes releaseinfo
		var releaseinfo = ( showrelease ? '<b>Release:</b> ' + myreleased + '<br>' : '' );

		//becomes photographerinfo
		var linked_photog = myphotographer;
		if(myphotographer.indexOf('/') > 0)
			linked_photog = linked_photog.substring(0, linked_photog.indexOf('/'));
		var photographerinfo = ( (myphotographer && showphotographer) ? '<b>Photographer:</b> <A href="/SwishSearch?Keywords=' + linked_photog + '&spec_idx=ne&method=photographer">' + myphotographer + '</a><br>' : '');

		//becomes filesizeinfo
		var filesizeinfo = ( (! featuredimage && showfilesize) ? '<b>File Size:</b> ' + myfilesize : '');

		//becomes restrictionsinfo
		var restrictionsinfo = (myrestrictions ? '<BR/><span style="color:#990000">'+myrestrictions+'</span>' : '');

		//becomes keywordinfo
		//becomes keywordinfo
		var keywordinfo = '';
		document.JSONobj.getKeywords().each(function (kwd){
			var relink = q_args;
			//e.g. Keywords=shot%20put+haspeople+NOT+imagehasrestrictions
			if(relink.match(/Keywords=[^\+\&]+\+/))
			{
				relink = relink.replace(/Keywords=[^\+]+\+/, 'Keywords='+kwd+'+');
			}
			else if (relink.match(/Keywords=[^\+\&]+\&/))
			{
				relink = relink.replace(/Keywords=[^\+\&]+\&/, 'Keywords='+kwd+'&');
			}
			else if (relink.match(/Keywords=[^\+\&]+$/))
			{
				relink = relink.replace(/Keywords=[^\+\&]+$/, 'Keywords='+kwd);
			}
			else //might be lightbox or request, but so no actual keywords, so append it directly
			{
				relink = relink.replace(/((rid|\&rid)|(vmo|\&vmo)|(lb_view|\&lb_view)|(cartview|\&cartview))=[^\&]+/, '');
				relink = 'Keywords='+kwd+'&'+relink;
				relink = relink.replace(/\&+/, '&');
			}
			relink = relink.replace('&spec_idx=ne', '');
			keywordinfo += '<a href="/SwishSearch?' + relink +'&spec_idx=ne">' + kwd + '</a>, ';
		});

		var displayenlargetid;
		if ( o[encount] ){displayenlargetid=o[encount];} else {displayenlargetid=enlargetid;}

		  if((enid.indexOf('Alamy',0) >= 0) || (enid.indexOf('Dreamstime',0) >= 0)){
			var temporary =enid.split("|");
			displayenlargetid = temporary[1];
			filesizeinfo = "";
		 }else{
			if(typeof(o[encount]) != 'undefined'){
			if((o[encount].indexOf('Alamy',0) >= 0) || (o[encount].indexOf('Dreamstime',0)>=0)){
				o[encount] = o[encount].replace("%7C","|");
				o[encount] = o[encount].replace("%7C","|");
				var temporary = o[encount].split("|");
				displayenlargetid = temporary[1];
				filesizeinfo = "";
		      }
		   }
		}
		var dateshot = document.JSONobj.getImgDat('date_shot');
		var rfcdlinkslug = document.JSONobj.getImgDat('rfcdlink');

		var tdata = $H({enlargetid: enlargetid,
				rfcdlinkslug: rfcdlinkslug,
				dateshot: dateshot,
				keywordinfo: keywordinfo,
				displayenlargetid: displayenlargetid,
				restrictionsinfo: restrictionsinfo,
				filesizeinfo: filesizeinfo,
				photographerinfo: photographerinfo,
				releaseinfo: releaseinfo,
				ratetierinfo: ratetierinfo,
				downloadcomplink: downloadcomplink,
				navenlargedlinks: navenlargedlinks,
				navbacklinks: navbacklink,
				similarscolumn: similarscolumn,
				themediainsert: themediainsert,
				rmrftype: myrmrftype,
				myshortcaption: myshortcaption,
				dimensions: mydimensions
			});
		//write html for enlarge page
		$('Layer1').style.overflow = 'auto';
		MM_setTextOfLayer('Layer1','', Templates.enlarge2_act__body.evaluate(tdata));
		//$('Layerpages').style.display='none';
		$('Layerpages').style.visibility='hidden';
		//auto-show keywords switch
		if(typeof(autoshowkeywords) != 'undefined'){
			setTimeout("popkeys2('enlarge_keywords','','enalarge_keywords_text');",500);
		}
		//MM_preloadImages('http://gdynx.ipnstock.com/'+dynimagesname+'/420/60/' + nextimageid + '.JPG');
	
		if(nextimageid != undefined )	
			MM_preloadImages(nextimagesrc);
		
	}
	else {
		//alert("This is the last image of the search results.");
		gsetCookie('gviewmode','ss', '', '/', gGetCookieDom());

		self.location= nextlink + 'snum=' + (Number(firstpictureonpage) + Number(snum)); //figure out which should be first picture on next page
	}//end if id[enid]
if (enid.substr(0,10) == "Dreamstime") {
	//alert("here "+ enid);
	document.getElementById('iconprice').style.visibility = 'hidden';
	document.getElementById('iconpricelink').style.visibility = 'hidden';
	
} else {
	document.getElementById('iconprice').style.visibility = 'visible';
	document.getElementById('iconpricelink').style.visibility = 'visibile';
}


};

function cart_display (flip) { // call to load shopcart display into Layer1
if ( document.cart_display_lock )
	return;

//	truevertHeight +=55;


var section = $H({ showstart:'cartview', snum:firstpictureonpage, viewmode:'cartview', flp:flip }).toJSON();
//make the call through the YAHOO registry.
if (flip)
{
	dispatchAll(section);
}
else
{
	try { YAHOO.util.History.navigate("nav", section); } catch (e) { dispatchAll(section); }
}

$('row2').style.display="none";

};

function preloadnextimg(){
preloadcurrent++;
// preload till the next page's images are loaded and stop preloading if next page is clicked
if(preloadcurrent < preend && endnumber < preend){
	objImage = new Image();
	Event.observe(objImage, 'load', function() { setTimeout("preloadnextimg();",10) });

	objImage.src = getPreloadSrc({ pos : preloadcurrent });

/*
	if( (typeof(mthumb[preloadcurrent])!='undefined') && mthumb[preloadcurrent]!=""){
	//	objImage.src=unescape(sthumb[preloadcurrent]);
		objImage.src=unescape(mthumb[preloadcurrent]);
	}
	else{ 
	  // objImage.src='http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' + id[preloadcurrent] + '.JPG';
	  objImage.src=ImageUrl(image_dimensions(),id[preloadcurrent]);
	}
*/
}

};

function getPreloadSrc(args) {

	var preSrc = ImageUrl(image_dimensions(),id[args.pos]);
	
	var imagemode = ( (typeof(args)!='undefined' && args.viewmode!=null && args.viewmode) ? args.viewmode : viewmode );

	switch(imagemode){
		case 'table': preSrc = ( (typeof(mthumb[args.pos])!='undefined' && mthumb[args.pos]!="") ? ( mthumb[args.pos].indexOf('alamy')>0 ? unescape(sthumb[args.pos]) : unescape(mthumb[args.pos]) ) : preSrc );  
				break;
		case 'list' : preSrc = ( (typeof(mthumb[args.pos])!='undefined' && mthumb[args.pos]!="") ? ( mthumb[args.pos].indexOf('alamy')>0 ? unescape(sthumb[args.pos]) : unescape(mthumb[args.pos]) ) : preSrc );
				break;
		case 'editing' : preSrc = ( (typeof(mthumb[args.pos])!='undefined' && mthumb[args.pos]!="") ? ( mthumb[args.pos].indexOf('alamy')>0 ? unescape(sthumb[args.pos]) : unescape(mthumb[args.pos]) ) : preSrc );
				 break;
		case 'tiny':	preSrc = ( (typeof(sthumb[args.pos])!='undefined' && sthumb[args.pos]!="") ?  unescape(sthumb[args.pos])  : preSrc );
				break;
		case 'med':	preSrc = ( (typeof(mthumb[args.pos])!='undefined' && mthumb[args.pos]!="") ? ( mthumb[args.pos].indexOf('alamy')>0 ? unescape(sthumb[args.pos]) : unescape(mthumb[args.pos]) )  : preSrc );
				break;
		case 'huge':	preSrc = ( (typeof(lthumb[args.pos])!='undefined' && lthumb[args.pos]!="") ? unescape(lthumb[args.pos]) : preSrc );
				break;
		case 'large':	preSrc = ( (typeof(lthumb[args.pos])!='undefined' && lthumb[args.pos]!="") ? unescape(lthumb[args.pos]) : preSrc );
				break;
	}

	//alert(preSrc);
	return preSrc;
};


function writesimilar_custom(myid,showid,myphotographer,myshortcaption,action,mode,myhrdlink,myreleased) {
	myhrdlink = ( myhrdlink || '' );
	myreleased = ( myreleased || '' );
        var simlist =st[showid];
        var simarray=simlist.split(" ");
 	var temparray = simarray[1].split(",");
 	if(temparray.length > 1){temparray=simarray[0] + ' ' + temparray.join(' ');simarray=temparray.split(' ');}
 	var simcount =simarray.length;
 	if(mode =='normal' || mode=='huge'){
         	if(parseInt(simcount) < 5 ){simindicator=simcount;} else {simindicator=4;}
 	} else {
         	if(parseInt(simcount) < 4 ){simindicator=simcount;} else {simindicator=3;}
 	}

         var thehtml='';
         var wmyid = myid;
     var setid = myid;
     var iconheight=15;var iconwidth=15;
 
         if (action == 'next'){
 
                 var n=sw[showid];
                 n++;
                 sw[showid] = n;
                 if(sw[showid] >= simcount) { sw[showid]=0;n=0;}
                 wmyid = simarray[n];
 
         } else if (action == 'prev'){
                 var n=sw[showid];
                 n--;
                 sw[showid] = n;
                 if(sw[showid] < 0) { sw[showid]=simcount - 1;n=simcount - 1;}
                 wmyid = simarray[n];
         }
 	//empty array fix for a single image returned which is a similar
 	if ( isNaN((sw[showid] + 1)) )
 		sw[showid] = 0;
 		var theight = 172 + adminheight;
         if (mode == 'list' || mode == 'editing'){
                 thehtml += '<TABLE width=298 cellspacing=2 cellpadding=0 border0 height=' + theight + '><TR><TD valign=top width=149 align=center>';
         }
         // similar graphics zzz
         thehtml += '<table cellpadding=0 cellspacing=0 border=0><TR><TD colspan=2 align=right valign=bottom bgcolor=#c9c9c9 width=18 height=18>';
         thehtml += '<a href="javasc' + 'ript:enlarge2(\'' + myid + '\'' + ',' + '\'' + showid + '\', \''+wmyid+'\');" TITLE="ID:' + wmyid;
         if(showphotographer == 1){'  \r&copy; ' + myphotographer;}
         if(showfilesize){thehtml += '  \rSIZE: '+ myfilesize;}
         thehtml += '  \r' + 'CAPTION: ' + myshortcaption;
         if (mode == 'huge'){
                 thehtml += '"><img src="' + ImageUrl('420/60',wmyid) + '" border="0" alt="loading..." height="180"></a></TD>';
         } else if( mode == 'med'){
                 iconheight=10;iconwidth=14;
                 thehtml += '"><img src="' + ImageUrl('135/50',wmyid) + '" border="0" vspace="0" hspace="0" alt="loading..." height=72></a></TD>';
         } else if( mode == 'tiny'){
                 iconheight=8;iconwidth=12;
                 thehtml += '"><img src="' + ImageUrl('135/50',wmyid) + '" border="0" vspace="0" hspace="0" alt="loading..." height=45></a></TD>';
 
         } else {
 				iconheight=12;iconwidth=16;
                 thehtml += '"><img src="' + ImageUrl('135/50',wmyid) + '" border="0" vspace="0" hspace="0" alt="loading..." height=100></a></TD>';
         }
         //simindicator="";
 
         thehtml += '<TD background=/graphics/similars_rc' + simindicator + '.gif valign=top width=9><IMG SRC=/graphics/similars_ru' + simindicator + '.gif width=12 height=9></TD></TR><TR height=8>';
         if(mode == 'normal' || mode=='huge' || mode=='large'){
 		thehtml += '<TD background=/graphics/similars_ll' + simindicator + '.gif height=8 width=12></TD><TD background=/graphics/similars_lc' + simindicator + '.gif height=8><div style="width: 18px;height:8px;padding:0;margin:0;"></DIV></TD>';
 	} else {
 		thehtml+='<TD colspan=2 background=/graphics/similars_lc' + simindicator + '.gif height=8></TD>';
 	}
 	thehtml += '<TD width=12 height=8 background=/graphics/similars_lr' + simindicator + '.gif></TD></TR></TABLE>';

	/* Display Similars */
	thehtml += '<div class=icons>';	
         thehtml += '<A HREF="javascript: return false;" onclick="writesimilar(\'' + setid + '\',\'' + showid + '\',\'';
         thehtml += myphotographer + '\',\'';
         thehtml += myshortcaption + '\',\'prev\',\'' + mode + '\', \'' + myhrdlink + '\',\'' + myreleased + '\'); return false;" TITLE="show similars">';
	thehtml += '<IMG SRC="/graphics/similars_prev.gif" border="0" hspace="1" height="' + iconheight + '" width="' + iconwidth + '" align="middle"></A>';
         if (mode == 'list' || mode == 'huge' || mode == 'normal' || mode=='large' || mode == 'editing' || mode=='tiny'){
                 thehtml += '<font class=xsmall>' + (sw[showid] + 1) + ' of ' + simcount + '</font>';
         }
         thehtml += '<A HREF="javascript: return false;" onclick="writesimilar(\'' + setid + '\',\'' + showid + '\',\'';
         thehtml += myphotographer + '\',\'';
         thehtml += myshortcaption + '\',\'next\',\'' + mode + '\', \'' + myhrdlink + '\',\'' + myreleased + '\'); return false;" TITLE="show similars">';
         thehtml += '<IMG src="/graphics/similars_next.gif" border="0" hspace="1" height="' + iconheight + '" width="' + iconwidth + '" align="middle"></A></nobr><BR>';
	thehtml += '</div>';

	/* End of display similars */
        
	 if(mode =='med' || mode == 'tiny'){
                 thehtml += '<div class=imidxxsmall>' + wmyid + '</div>';
 	 }
	 if(mode == 'table' || mode == 'normal' || mode =='huge'){
                 thehtml += '<div class=imid>' + wmyid + '</div>';
 	 }
         if (mode == 'list' || mode == 'editing'){
                 thehtml += '<font class=xsmall>ID:' + wmyid;
                 if(showphotographer == 1){thehtml +='  <BR>&copy; '+currentYear+' ' + myphotographer;}
                 if(showfilesize){thehtml += '<nobr>' + myfilesize + '</nobr>';}
                 thehtml += myreleased + '<BR>CAPTION: ' + myshortcaption + '</font><BR>';
 
                 if (mode == 'editing') {
                 	thehtml += '<br/><a href="javascript: return false;" onclick="launchwin(\'/SwishSearch?show_all=1&similar_to='+wmyid+'\', \'edit sims\', 600, 800, 100, 100); return false;" title="Edit Similar Images">Edit&nbsp;Similar&nbsp;Images</a>';
                 }
 
         }


	/*
         if(mode == 'normal' || mode =='med' || mode == 'tiny' || mode=='large'){
                 thehtml += '<Table cellpadding=0 cellspacing=0 border=0><TR><TD valign=top align=center>';
         }
	*/

         if(mode != 'editing')
         {
			thehtml += '<DIV class=icons>';
        		thehtml += '<DIV id="iconlb"><a href="javascript: return false;" onclick="lightbox_addto(\'' + wmyid + '\'); return false;" class=iconlink title="Add to your current lightbox"></a></div>';
			thehtml += '<div id="iconcart"><a href="javascript: return false;" ONCLICK="cart_addto(\'' + wmyid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart"></a></div>';
         	thehtml += '<div id="iconprice"><a href="javascript: return false;" onclick="return price_image(\'' + wmyid + '\',\''+rm[wmyid]+'\');" class=iconlink Title="Price Image"></a></div>';
         	//thehtml += '<a href="javasc' + 'ript:enlarge2(\'' + wmyid + '\'' + ',' + '\'' + showid + '\');" class=iconlink title="Enlarge image and more info"><font class=eye>i</font></a>';
         	if(mode == 'huge'){
                 	//thehtml += '<font class=xsmall>' + wmyid + '</font>&nbsp;&nbsp;' + (myhrdlink ? '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>' : '')+'&nbsp;&nbsp;';
 		} else if (mode == 'list') {
 			thehtml += '&nbsp;&nbsp;'+ (myhrdlink ? '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>' : '')+'</DIV>';
         	} else {
         		//thehtml += '</DIV>';
 		}
 	}
 
         /* if(mode == 'normal' || mode =='med' || mode == 'tiny' || mode =='large'){
            thehtml += '<BR>';
         } */


	/* 
         if(mode =='med' || mode == 'tiny'){
                 thehtml += '<font class=xsmall>' + wmyid + '</font>';
                 thehtml += '</TD><TD valign=top align=center width=40><nobr>';
         }
         if (mode == 'list' || mode == 'normal' || mode=='large' || mode == 'editing'){
                 thehtml += '</TD><TD valign="top">';
         }
	*/

         
 		thehtml += '</DIV>';
	if( myhrdlink )
		thehtml = '<div class="hiresdl_link"><nobr><a href="'+myhrdlink+'" class="hiresdl_link">Download Hi Res</a></nobr></div>'; 
	//thehtml += '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>';
 
       //  thehtml += '</td></TR></TABLE>';
        
 
         if (action == 'start'){
                 return thehtml;
         }
         if (action == 'prev'){
                 MM_setTextOfLayer( 'd' + setid,'',thehtml);
         }
         if (action == 'next'){
                 MM_setTextOfLayer( 'd' + setid,'',thehtml);
         }
 };
 

