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

var Templates = $H({});		


Templates.lightbox_new__body = new Template(
	'<div id="lightboxPopUp"><div class="shadow">'
	+'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="290" height="200"><TR>'
	+'<td class="dark1" valign=bottom width="100%"><DIV class="barheader">&nbsp;<FONT class="bartitle">Make a new lightbox</font></DIV></td></tr>'
	+'<tr><TD ALIGN="left" VALIGN="top" width="290" class="dark1"><DIV class="light1" style="padding: 15px;font-size:85%"><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="25" class="emailbox" value="My new LB name" onfocus="if (this.value == \'My new LB name\'){ this.value=\'\';}">'
	+'<A href="" 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="" onclick="lightbox_email(\'close\'); return false;">[X] close window</A>'
	+'</div></div>' 
);
		
Templates.lightbox_email__body = new Template(
	'<div id="emaillb_table"><div class="shadow"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="340" height="280"><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="dark1"><DIV class="light1" style="padding: 15px;font-size:85%"><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" id="readonly" name="readonly" value=1> Read only<BR><FONT CLASS="xsmall">check this box to prevent recipient from changing your lightbox.</FONT></p>'
	+'<B>4.</B> <input type="checkbox" name="notify" id="notify" value="1"><font class="small">Notify me when this lightbox is viewed</font><br>'
	+'#{emaillbaddhtml}<br><p><A href="" 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><br><br><p>If you have changed your mind, click the link below.<BR/><BR/> <A HREF="" onclick="lightbox_email(\'close\'); return false;">[X] close window</A>.<BR>'
	+'</DIV></TD></TR></TABLE>'
	+'</div></div>'
);
		
Templates.lightbox_rename__body = new Template(
	'<div id="renamelb_table"><div class="shadow"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="270"><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="dark1"><DIV class="light1" style="padding: 10px;font-size:85%"><form action="javascript:nada();" method="get" name="send"><p>'
	+'</p><p><INPUT type="text" name="lightbox_new_name" id="lightbox_new_name" size="40" class="lightbox_new_name" value="#{currentlbname}" onfocus=" if (this.value == \'#{currentlbname}\'){ this.value=\'\';}">'
	+'<A href="" onclick="lightbox_rename_send(); return false;" class=lblink style="font-size:inherit ; font-weight:bold;">Rename</A><br/><br/>'
	+'<A HREF="" onclick="lightbox_email(\'close\'); return false;">[X] close window</A>'
	+'</form></DIV></TD></TR></TABLE>'
	+'</div></div>'
);

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 (
        '<span class="blah"># #{displayimageid} #{rmrftype} #{filesize} #{dimensions} :: #{shortcaption} #{photographer} #{imagerestrictions}'
        +'<br/>'
        +'<span class="warning"> To turn live previews off, use Search Preferences at the top of the page </span>'
);

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%;overflow:auto" id="image_details">'
                +'<TR height="99%">' 
                        +'<TD align="left" valign="top" width="99%" height="99%" style="overflow:auto;padding-left:6px;">'
                                +'<table cellspacing="4" cellpadding="0" border="0" width="100%" height="99%">'
				+'<TR><TD valign="top" align="right" width="430" height="440" style="min-width: 440px;padding-left:14px;">'
					+'<div style="position:relative;margin-right: 20px;text-align:left"><div id="overlaywatermark"></div>#{themediainsert}</div>'
					+'<div style="text-align:left"><BR/><b>Image no:</b> #{displayenlargetid}'
					+'#{dimensions}'
					+'<br/><b>Caption:</b> #{myshortcaption}<br/>'
					+'#{photographerinfo}'
					+'<b>Type of image:</b> #{rmrftype}<br/>'
					+'#{releaseinfo}'
					+'<br/><b>Restrictions:</b>#{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></div>'
				+'<br/></td>'
				
                                +'#{similarscolumn}'
                                +'              <TD align="left" valign="top"><div style="padding-left: 15px;">'
					+'#{navbacklinks}'
					+'<b>#{rmrftype} Image</b></br><br/>'
					+'<br/>#{calcusage}'
					//+'<br/><a href="" onclick="license(\'#{enlargetid}\'); return false;">Calculate Usage rates</a>'
					+'<br/><br/><br/><br/><a href="" onclick="lightbox_addto(\'#{enlargetid}\'); return false;">Add to current lightbox </a>'
					+'<br/><a href="" onclick="cart_addto(\'#{enlargetid}\'); return false;">Add to Cart</a>'
					+'<br/><br/><br/></br>#{downloadcomplink}'
					+'#{hires_link}'
					+'#{manage_link}'
					+'<br/><br/><br/><br/>#{navenlargedlinks}'
					+'</div>'
				+'</td><TD rowspan=2 align="left" valign="top">'
                                        +'#{ratetierinfo}'
                                +'</TD></TR>'
		+'<tr><td>#{rfcdlinkslug}</td></tr>'
		+'<tr><td colspan=4 align="right">&copy;#{currentyear}  All rights reserved <b>ANT Photo Library Pty Ltd - Ph: 03 5978 8877 - images@antphoto.com.au</nobr></td></tr>'
                                +'</table>'
        +'<BR></td></TR></table>'
);

Templates.calc_usage_text = new Template (
		'<br/><a href="" onclick="license(\'#{enlargetid}\'); return false;">Calculate Usage rates</a>'
);

Templates.hovercopyright__text = new Template (
	'&copy;#{currentyear} #{baseurl}  All rights reserved <b>ANT Photo Library Pty Ltd - Ph: 03 5978 8877 - images@antphoto.com.au</nobr>'
);

Templates.footer__body = new Template (
	'<DIV id="copyright">&copy;#{currentyear} #{baseurl} All rights reserved <b>ANT Photo Library Pty Ltd - Ph: 03 5978 8877 - images@antphoto.com.au</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}\'});"' +
        ' id=rfselectfilesizetabletdaddtocart>Add to Cart</a></nobr></td></tr>' 
);


Templates.tieredimgpricing__rrslug = new Template (
        '<div align="left"><IMG src=/graphics/h_RightsReady.gif border=0 alt="Royalty Free Licensing"></div>'+
        '<h4 style="text-align: left;">Select one or more uses below</h4>'+
        '<A href="/EULA/Blend_RM_RR_EULA.pdf" TITLE="View License Agreement as a pdf" class="orangelink" target="eula">View Rights Ready License Agreement (pdf file)</A><BR clear=all>'+
        '<table cellspacing=0 cellpadding=0 width="100%" >#{rows}</table>'
);
Templates.tieredimgpricing__rrslug_row = new Template (
        '<tr><td colspan=2><h2>#{name}<h2></td></tr>'+
        '<tr><td align=left style="border-bottom: 1px solid rgb(187, 187, 187);padding-bottom: 3px; padding-top: 4px;"><span><nobr><b>#{optname}</b></nobr></span><BR>'+
        '<div id="d#{id}"><a href="javascript:ShowOrHideComboText(\'d#{id}\', \'none\',\'e#{id}\'); ShowOrHideComboText(\'d#{id}2\', \'block\');" class="orangelink">Show Details</a></div>'+
        '  <div id="d#{id}2" style="display:none;"><a href="javascript:ShowOrHideComboText(\'d#{id}\', \'block\'); ShowOrHideComboText(\'d#{id}2\', \'none\');" class="orangelink">Hide Details</a>'+
        '<br />#{expr}<BR>'+
        '<div id="d#{id}e" style="display:none;"><a href="javascript:ShowOrHideComboText(\'d#{id}e\', \'none\'); ShowOrHideComboText(\'d#{id}e2\', \'block\');" class="orangelink">Show Examples</a></div>'+
        '  <div id="d#{id}e2" style="display:none;"><a href="javascript:ShowOrHideComboText(\'d#{id}e\', \'block\'); ShowOrHideComboText(\'d#{id}e2\', \'none\');" class="orangelink">Hide Examples</a>'+
        '  <div id="e#{id}">#{expr_extended}</div></div>'+
        '</div></td><td align=right valign=top style="border-bottom: 1px solid rgb(187, 187, 187);padding-bottom: 4px; padding-top: 4px;">'+
            '<div style="min-width: 50px; padding-right: 5px;">#{currency} #{price}</div> '+
            '<div style="min-width: 50px;">'+
                '#{removebutton}'+
                '<nobr><A href="#" onclick="cart_addto(\'#{enlargetid}\',{ \'ln\':\'#{enlargetid}\', \'lictype\':\'RR\', \'base\':\'#{price}\', \'Size_opname\':\'#{id}\', \'usage\':\'#{usage}\', \'callback\':\'enlarge2(#{img_id},#{encount},null,1);\' }); return false;" class="orangelink">Add to Cart</a></nobr>'+
            '</div>'+
        '</td></tr>'
);

Templates.tieredimgpricing__rrslug_row_removebutton = new Template (
        '<nobr><a href="#" class="orangelink" onclick="cart_delete_license(#{img_id},{ \'lictype\':\'RR\', \'usage\':#{usage}, \'opts\':#{id}, \'callback\':\'enlarge2(#{img_id},#{encount},null,1);\' }); return false;">Remove Option</a><nobr> &nbsp;&nbsp;'
);


Templates.login = new Template(
 '<div id="loginRegister" ><div class="shadow">'
        +'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="left" width="450" height="275"><TR>'
        +'<td class="dark1" valign=bottom width="100%"><DIV class="barheader"><div style="float:right"><A HREF="javascript:return false;" onclick="javascript:hide_login(); return false;" style="text-decoration:none;font-size:85%">&nbsp;[x] close window&nbsp;</A></div><div style="float:left">&nbsp;<FONT class="bartitle">Login</font></div></DIV></td></tr>'
        +'<tr><td ALIGN="left" VALIGN="top" width="100%" class="dark1"><DIV class="light1" style="padding: 15px;font-size:85%"><p>By signing back in you will be able to buy images through your Cart, use your Lightboxes, download comp images and access and amend your profile details.</p><p>If you have not had a chance to set up <A href=/bin/Register>Your Account by Registering</a>, please take a moment to do so. You will be able to use all the features of this site once you have.</p><p>Need some help - please ring us on 03 5978 8877</p>'
	+'<p><div id="loginMessage"></div></p>'
        +'<p><form name="loginForm" id="loginForm" action="javascript:evaluate_login();"><table cellspacing=5 cellpadding=5 width=100%>'
	+'<tr><td>Email</td><td>:</td><td><INPUT type="text" name="username" id="username" size="25" class="emailbox" ></td><td></tr>'
        +'<tr><td>Password</td><td>:</td><td><INPUT type="password" name="password" id="password" size="25" class="emailbox" ><input type="hidden" name="sphotog" id="sphotog" value="antphoto"></td><td>'
	+'<div id=sbuttonenter class="spritebuttons" style="width:150px"><a href="javascript:return false;" onclick="javascript:return evaluate_login();"></a></div>'+'</td></tr>'
	+'</table></form></p>'
	+'<br><a href="/bin/Register" class="small">Not a registered user?</a>&nbsp;&nbsp;'
	+'<a href="/bin/Lostpass" class="small">Forgot your password?</a>&nbsp;&nbsp;'
	+'<a href="/bin/Changepass" class="small">Change your password?</a><BR>'
	+'</td></tr></table>'
        +'</div></div>'

);


function cKey(e){
        var keycode="";
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;


	alert(keycode);
        if (keycode == 13)
               evaluate_login(); 
     
}

//document.getElementById("username").onkeydown  = cKey;

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="" onclick="document.currentLayer1Mode=\'searchresults\';nextpage(); return false;">&nbsp;</A></div>';
		}else{
            //    thehtml+='<div id="sbuttonnext"></div>';
		}
		thehtml +='<div style="float:right;margin-top:0px">&nbsp;&nbsp;Page&nbsp;';

		thehtml+='<SELECT name="pageurl" align="absmiddle"  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.replace(/&#34;/g,"\"") + '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.replace(/&#34;/g,"\"") + 'snum=' + ((i-1) * (parseInt(gpixperpagev))) + '\' selected>' + i + '</option>';
			} else {
				thehtml+='<option value=\'' + nextlink.replace(/&#34;/g,"\"") + 'snum=' + ((i-1) * (parseInt(gpixperpagev))) + '\'>' + i + '</option>';
			}
		}
	
		if(pen != totalpages){
			thehtml+='<option value=\'' + nextlink.replace(/&#34;/g,"\"") + '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>';	
	
		if (totestman == 'Lightbox:'){
			var displaytype_div = "&nbsp;<b>Lightbox : "+dsplkys+"</b>";
			 displaytype_div += '&nbsp;&nbsp;[' + showstartnumber + '&nbsp;-&nbsp;';
                if (showendnumber > parseInt(results_total)){
                        displaytype_div += results_total+']&nbsp;of&nbsp;<span id="imgtotal">' + results_total + '</span>';
                } else {
                        displaytype_div += showendnumber+']&nbsp;of&nbsp;<span id="imgtotal">' + results_total + '</span>';
                }
			$('displaytype_div').innerHTML =displaytype_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="">Save All Releases</a> &nbsp;&nbsp; [ Set All: <a href="" onclick="return share_set_page(\'shared\'); ">Accepted</a> | <a href="" onclick="return share_set_page(\'rejected\'); ">Rejected</a> | <a href="" onclick="return share_set_page(\'pending\'); ">Pending</a>  &nbsp;|&nbsp;  <a onclick="return release_set_page(\'NOT RELEASED\');" href="" title="NOT RELEASED">NR</a> | <a onclick="return release_set_page(\'NOT APPLICABLE\');" href="" title="NOT APPLICABLE">NA</a> | <a onclick="return release_set_page(\'NOT RECOGNIZABLE\');" href="" title="NOT RECOGNIZABLE">NR</a> | <a onclick="return release_set_page(\'MODEL AND PROPERTY RELEASED\');" href="" title="MODEL AND PROPERTY RELEASED">MaPR</a> ]';
			$('Layerpreviews').innerHTML = lochtml;
		}
	}
        //conditional previous page
        if(Number(currentpagenum) > 0){
                thehtml+='<div id="buttonprev"><A href="" onclick="document.currentLayer1Mode=\'searchresults\';prevpage(); return false;"></A>&nbsp;</div>';
        } else if (showstartnumber <= results_total){
  //              thehtml+='<div id="sbuttonprev"></div>';
	}

//	thehtml += '</td></tr></table>';

	$('Layerpages').style.overflow = 'visible';
        MM_setTextOfLayer('Layerpages','',thehtml);
//	setbackpagetrap(showstartnumber,snum,viewmode);
};

function dispatchBuildimages(args) {

      var MacIE5 = global.macIE5;
	var startnumber = args['snum'];
	var mode = args['buildmode'];
	var resized = args['resized'];
	viewmode = args['viewmode'];
	$('Layer1').style.height = winH +'px';
	$('Layer1').style.overflow = 'hidden';


//LS20081106 moving this to lightbox_delete_image_enl function 
//to fix issue where search results number did not match Layerspage section
//	if ( $("nav_total_images") )
//		$("nav_total_images").innerHTML = id.length;

        if($('cdheader')){
		(typeof(dsplkys) != 'undefined' ? ( ( dsplkys.substring(0,6)=='BLDVCD' || dsplkys.match(/ZRFCD$/) ) ? $('cdheader').style.display = 'block' : $('cdheader').style.display = 'none')             : $('cdheader').style.display = 'block' );
	}

	document.currentLayer1Mode='searchresults';
	createCoverLayer();
	if(!MacIE5){var tshown = Element.getOpacity('coverlayer');}
	
	if(tshown > 0.2){
		hidedisplaypanel();
	}
        suspendcheck=1;
        //calculate how many images can be held on the page depending on mode being used
        if(startnumber > 1 || resized==1){setuppagesize();}

        //  build the page
	showstartnumber_trap = parseInt(startnumber);  //save for later
        var thehtml=optimize(); // + '<FORM name=activedisplay action=#>';
        grange="legal";
        MM_setTextOfLayer('Layer1','','<CENTER> <BR><BR><BR><BR><BR><BR><BR><BR>loading ...</CENTER>');
        var cnt=startnumber;
        //figureout current range of images to show
        firstpictureonpage=startnumber;
        endnumber = parseInt(gpixperpagev) + parseInt(startnumber);

        if (viewmode != "ss"){
                //loop through images in the array and build html
				if(pagetype=='lb' && (typeof(pre_q_args) != 'undefined' && ! ( pre_q_args.match(/lb_view=1/) || pre_q_args.match(/fn=/) || pre_q_args.match(/vmo=/) ) ) )
					thehtml += '&nbsp;&nbsp;<A href="javascript: return false;" onclick="viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom()); self.location=\'/SwishSearch'+pre_q_args+'\'; return false;"><FONT style="font-size:9pt; font-family:Arial;">&#8593;</font> BACK TO SEARCH RESULTS</A><BR/><BR/>';

		while(cnt < endnumber) {
			if( id[cnt] ){
				if ( typeof(htmlit_custom) == 'function' )  {
					thehtml += htmlit_custom(cnt);
				} else {
					 thehtml += htmlit(cnt);
				}
			} else if((snum + cnt)>=results_total){
                                if (grange != "outofrange"){
                                        thehtml+='<span valign=bottom style="float:left;"><div align=center valign=bottom style="width:130; height:50px; overflow: hidden;">';

                                        if(pagetype=='lb'){
						thehtml+='<div id="endbox" class="endoflightboximages"><nobr>[ end of lightbox images ]</div></nobr></DIV></SPAN> ';
                                        } else {
						thehtml+='<div id="endbox" class="endofsearchresults"><nobr>[ end of search results ]</div></nobr></DIV></SPAN> ';
					}
                                }

                                grange="outofrange";

                        } else {
                                grange="illegalpage";   //check to see if page numbers are out of the legal range of images
                        }
                        cnt++;
               } 

		if (snum + cnt == results_total)
			grange = 'outofrange';  //basically we have exactly enough images, 
						//so we want to skip adding the nextlink and the [ end of results ] cell

               //conditions below are for going ahead or behind available imagenumber ranges
                if (grange == "illegalpage"){
                        if (mode == "next"){
				var next_snum = ( Number(snum) + Number(startnumber) );
        			var section = $H({ showstart:1, snum:0, viewmode:viewmode, resized:resized }).toJSON();

                                self.location= nextlink.replace(/&#34;/g,"\"") + 'snum=' + next_snum + '#nav='+section; //figure out which should be first picture on next page
                                 MM_setTextOfLayer('Layer1','','<CENTER> <BR><BR><BR><BR><BR><BR><BR><BR>loading next set of images...</CENTER>');
                        } else {

                                // two ways to go with this code
                                // method a is one screen at a time
                                //prevtogoto = snum + startnumber;

                                // method b is two screens at a time
                                prevtogoto=Number(snum) + Number(startnumber) - parseInt($F('pixperpage')); // go back two pages from start page
                                //gsetCookie("gwhichstartpage",parseInt($F('pixperpage')), '', '/', gGetCookieDom());
                                // ensure no negative numbers
                                if(prevtogoto < 0 ){ prevtogoto=0;}
        			var section = $H({ showstart:1, snum:0, viewmode:viewmode, resized:resized }).toJSON();
                                self.location=nextlink.replace(/&#34;/g,"\"") + 'snum=' + prevtogoto + '#nav='+section;

                        }

                } else {

                        //normal page ranges - add lower right next page link
			//thehtml+='</FORM>';
                        MM_setTextOfLayer('Layer1','',thehtml);

			if (shsync[0])
				setTimeout('init_share_radios()', 1);
			// f9f9ef
                        var bottomthehtml= "<table id=\"footerpaging\" style=\"position:absolute; z-index:999;min-width:200px\" width=100% height=24 cellpadding=0 cellspacing=0 border=0><TR><TD align=right >";
			bottomthehtml+= "<div style=\"float:right;width:3px\">&nbsp;</div>";
                        if (grange != "outofrange"){
                                bottomthehtml+= "<div id=\"buttonnext\"><a href='javascript: return false;' onclick='nextpage(); return false;' name=bottomnext></a></div>";
                                bottomthehtml+= "<div id=\"footerpaging_nextlink\"><a href='javascript: return false;' onclick='nextpage(); return false;' name=bottomnext>NEXT</a></div>";
                                //reset the page numbersw

                        }else{
                                bottomthehtml+= "<div id=\"buttonnext\"><a href='javascript: return false;' onclick='javascript:alert(\"End of search results\");return false;' name=bottomnext></a></div>";
                                bottomthehtml+= "<div id=\"footerpaging_nextlink\"><font color='grey'>NEXT</font></div>";


			}
 
                        if ((typeof(snum) != 'undefined' && Number(snum) > 1) || ( typeof(startnumber) != 'undefined' && Number(startnumber) > 1)){
                                bottomthehtml+= "<div id=\"buttonprev\"><a href=javasc" + "ript:prevpage();></a></div>";
                        } else {
                                bottomthehtml+= "&nbsp;";
                        }

                     //   bottomthehtml+= "</TD><TD align=\"middle\"  width=20%><center><nobr>" + footer() + "</nobr></center></TD><TD width=40% align=right>";

                        bottomthehtml+= "</TD></TR>";
			bottomthehtml+= "<TR><TD align=right><div style=\"float:right;width:26px\">&nbsp;</div>"+footer()+"</TD></TR>";
			bottomthehtml+= "</table>";
			$('pagingrow').innerHTML =  bottomthehtml;


                        // preload next page worth of images
                        lastimage=cnt;
                      	if($('pixperpage')){
				prestart = endnumber - 1;
				preend=(lastimage + parseInt($F('pixperpage')));
                       		if(startnumber==0){
					var delay=6000 + parseInt($F('pixperpage') * 30);
                       		         self.setTimeout("preloadnextpage()",delay);
                       		} else {
					var delay=1000;//delay just a bit to make several next page load requests have time to catch up
                       		         self.setTimeout("preloadnextpage()",delay);
                        	}
			}
                }
        } else {
                //ss mode
                enlarge2(id[0],0); // new page and slideshow mode
        }


        currentpagenum = Math.ceil(         (      Number(snum) + Number(startnumber)         ) /      parseInt($F('pixperpage'))            );
        buildpages(startnumber,endnumber,snum);
	iconstatus();
 };

 function iconstatus(){
        if(viewmode){
                //clear them
                if($('iconlist')){$('iconlist').className='sizeiconblocks';}
                if($('iconbig')){$('iconbig').className='sizeiconblocks';}
                if($('icontiny')){$('icontiny').className='sizeiconblocks';}
                if($('iconmed')){$('iconmed').className='sizeiconblocks';}
                if($('iconhuge')){$('iconhuge').className='sizeiconblocks';}
                if($('iconlrg')){$('iconlrg').className='sizeiconblocks';}
                 //set it
                if(viewmode == 'table'){
                        if($('iconbig')){$('iconbig').className='iconbigactive';}
                 } else  if(viewmode == 'list'){
                        if($('iconlist')){$('iconlist').className='iconlistactive';}
                 } else  if (viewmode == 'tiny'){
                        if($('icontiny')){$('icontiny').className='icontinyactive';}
                 } else if (viewmode == 'med'){
                        if($('iconmed')){$('iconmed').className='iconmedactive';}
                 } else if (viewmode == 'huge'){
                        if($('iconhuge')){$('iconhuge').className='iconhugeactive';}
                 } else if (viewmode == 'large'){
                        if($('iconlrg')){$('iconlrg').className='iconlrgactive';}
                 }

         }
 };

function htmlit_custom(showid){

	// build html for each image depending on viewing mode
	dynimagesname = "dyn_images";	
	var html='';
	switchpage = false;
	if (id[showid]){
		
		var myrmrftype = rm[showid];
		myid = id[showid];
		if (typeof(suspendsimilars) == 'undefined'){
			mysimilarto=st[showid];
		} else { 
			mysimilarto='';
		}
			
		if (typeof(scp) != 'undefined' && (viewmode == 'list' || viewmode == 'editing' || viewmode == 'huge' || viewmode == 'large') ) {myshortcaption=unescape(scp[showid]);} else {myshortcaption = "n/a";}
		var temp = true;
		var tempshortcaption='';
		var myreleased = '';

		if (! relcon[showid])
			myreleased = rel[showid];

		if (typeof(relcon) != 'undefined' && relcon[showid] && mysimilarto.length < 13) {  //share control style..
			var shortrel = myreleased; ///( $('gRelease'+showid) && $('gRelease'+showid).value ) ? $('gRelease'+showid).value : 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 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=0;
		if(myhrdlink){
                        if (viewmode != 'editing')
                                adminheight=11;
		} 
		if(myfilesize < 5){myfilesize='Scan on Demand';} //else {myfilesize+=" Mb";}
		if(myid.length > 9){
			if ( o[showid] ){displayid=o[showid];} else {displayid=myid;}	
                        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';
                                }
                                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="http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' +myid + '.JPG" border=0 class=pimg vspace=2 hspace=3';
                                        html += " onmouseover=\"prloadimg('"+ myid +"'); 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;

                                        if(myhrdlink)
                                                html += '<br/><NOBR><a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a></NOBR>';
                                        html += '<br/><a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';

                                        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 = 172 + 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 border0><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="http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' + myid + '.JPG" border=0 class=pimg vspace=2 hspace=3';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";html += '" onmouseout="hp();" id=' + myid + '>';
					html += '</a><BR>';
					if(myhrdlink)
						html += '<center><a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a></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 += '<a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$$$</a>';
					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>info</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', myhrdlink, myreleased);
                                        //html += myhrdlink + '<br/>' + myreleased + mysharestatuses;

					html += '</DIV></SPAN>';
				}
				
			
			} else if (viewmode == "tiny"){
				//adminheight += 8;
				var theight = 100 + 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=http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' + myid + '.JPG border=0 class=pimg vspace=1 hspace=1 height=55';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "', '" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
					
					//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "')
					html += '</a><BR>';
					html += '<font class="xxsmall"><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 += '<a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlinktiny" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlinktiny" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlinktiny" Title="Price Image">$</a>';
					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>';

					/*  if(typeof(gusert) != 'undefined' && gusert =='IPN'){
						html += '<A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?good=1&id=' + myid + '&q=' + dsplkys + '\'); return false;"><IMG src=/graphics/rating_enhance.gif width=18 height=12 border=0 style="margin-bottom: -3px;"></a><A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?bad=1&id=' + myid + '&q=' + dsplkys + '\'); return false;"><IMG src=/graphics/rating_discourage.gif width=18 border=0 height=12 style="margin-bottom: -3px;"></a>';
					}  */

					html += '</DIV></font>';
					html += '<DIV class=imidxxsmall>' + displayid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html +='</DIV>';

					if (myhrdlink)
						html += '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>';
					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',myhrdlink,myreleased);		
					html += '</DIV></SPAN>';
				}
			
			
			} else if (viewmode == "med"){
				//adminheight += 4; // tweaking adminheight...
				var theight = 130 + 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=http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' + myid + '.JPG border=0 vspace=1 class=pimg hspace=1 height=80';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "', '" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
						//sp('','" + myid + "','" + myrglobaldynf + "','" + myphotographer + "','" + myid + "','" + showid + "')
					html += '</a><BR>';
					html += '<font class="xsmall"><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 += '<a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$$$</a>';
					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>info</font></a>';

					if(typeof(gusert) != 'undefined' && gusert =='IPN'){
						html += '<A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?good=1&id=' + myid + '&q=' + dsplkys + '\',getpost); return false;"><IMG src=/graphics/rating_enhance.gif width=18 height=12 border=0 style="margin-bottom: -3px;"></a><A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?bad=1&id=' + myid + '&q=' + dsplkys + '\', getpost); return false;"><IMG src=/graphics/rating_discourage.gif width=18 border=0 height=12 style="margin-bottom: -3px;"></a>';
					}
					html += '</DIV></font>';
					html += '<DIV class=imidxxsmall>' + displayid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html +='</DIV>';
					if (myhrdlink)
						html += '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>';
					
					

					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',myhrdlink,myreleased);		
					html += '</DIV></SPAN>';
				}
			} else if (viewmode == "ss"){			
				html = '  ';
			} else if (viewmode == "huge"){		
				var theight = 250 + adminheight;
				if ( mysimilarto.length < 13){	
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="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="http://globaldyn.ipnstock.com/'+dynimagesname+'/420/60/' + myid + '.JPG" border="0" vspace="1" hspace="3" alt="loading..." height="152"></a><BR>';
					html += '<font class="xsmall"><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 += '<a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LIGHTBOX+</a>';
					if(gsession){html += '<a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}

					html += '<a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$$$</a>';
					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>ENLARGE</font></a> ';

					if(typeof(gusert) != 'undefined' && gusert =='IPN'){
						html += '<A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?good=1&id=' + myid + '&q=' + dsplkys + '\', getpost); return false;"><IMG src=/graphics/rating_enhance.gif width=18 height=12 border=0 style="margin-bottom: -3px;"></a><A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?bad=1&id=' + myid + '&q=' + dsplkys + '\',getpost); return false;"><IMG src=/graphics/rating_discourage.gif width=18 border=0 height=12 style="margin-bottom: -3px;"></a>';
					}
					html += displayid;
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font> ';
					}
					html += '<br/>' + myshortcaption ;
	                                html += '</DIV></font>';

					if (myhrdlink)
						html += '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>';

					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', myhrdlink, myreleased);

					html += '</DIV></SPAN>';
				}				
			} else if (viewmode == "large"){
				var theight = 229 + adminheight;
				if ( mysimilarto.length < 13){		
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom style="width:197px; 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="http://globaldyn.ipnstock.com/'+dynimagesname+'/150/85/' + myid + '.JPG" class=pimg border="0" vspace="0" hspace="3"';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
					
					html += '</a><BR>';
					html += '<font class="xsmall"><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 += '<a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}
					html += '<a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$$$</a>';
					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;';

					if(typeof(gusert) != 'undefined' && gusert =='IPN'){
						html += '<A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?good=1&id=' + myid + '&q=' + dsplkys + '\',getpost); return false;"><IMG src=/graphics/rating_enhance.gif width=18 height=12 border=0 style="margin-bottom: -3px;"></a><A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?bad=1&id=' + myid + '&q=' + dsplkys + '\',getpost); return false;"><IMG src=/graphics/rating_discourage.gif width=18 border=0 height=12 style="margin-bottom: -3px;"></a>';
					}

					html += '<font class=imid>' + displayid + '</font>';
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html += '<br/>' + myshortcaption ;
				//	html += '<br/>' + myshortcaption ;
					html +='</DIV></font>';

					if (myhrdlink)
	                                        html += '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>';

					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', myhrdlink, myreleased);

					html += '</DIV></SPAN>';
				}
			} else {
				var theight = 176 + adminheight;
				if ( mysimilarto.length < 13){		
					html += '<span valign=bottom style="float:left;">';
					html += '<div align=center valign=bottom 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="http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' + myid + '.JPG" class=pimg border="0" vspace="0" hspace="3"';
					html += " onmouseover=\"prloadimg('"+ myid +"'); sp(this, '" + myid + "','" + showid + "','"+tset+"');";
					html += '" onmouseout="hp();" id=' + myid + '>';
					
					html += '</a><BR>';
					html += '<font class="xsmall"><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 += '<a href="javascript: return false;" ONCLICK="lightbox_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add to your current lightbox">LB+</a>';
					if(gsession){html += '<a href="javascript: return false;" ONCLICK="cart_addto(\'' + myid + '\'); return false;" class="iconlink" title="Add this image to your shopping cart">CART+</a>';}
					html += '<a href="javascript: return false;" ONCLICK="return price_image(\'' + myid + '\',\''+myrmrftype+'\');" class="iconlink" Title="Price Image">$$$</a>';
					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>info</font></a>&nbsp;';

					if(typeof(gusert) != 'undefined' && gusert =='IPN'){
						html += '<A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?good=1&id=' + myid + '&q=' + dsplkys + '\',getpost); return false;"><IMG src=/graphics/rating_enhance.gif width=18 height=12 border=0 style="margin-bottom: -3px;"></a><A href="javascript: return false;" onclick="ajax_TEXT(\'/bin/KeywordAdjust?bad=1&id=' + myid + '&q=' + dsplkys + '\',getpost); return false;"><IMG src=/graphics/rating_discourage.gif width=18 border=0 height=12 style="margin-bottom: -3px;"></a>';
					}
					 
					html += '</div><div><font class=imid>' + displayid + '</font>';
					if(typeof(suppressrmrftype) == 'undefined'){
						html += '  <font class=rmrfindicator>'+rm[showid]+'</font>';
					}
					html +='</DIV></font>';

					if (myhrdlink)
	                                        html += '<a href="'+myhrdlink+'" class="hiresdl_link"><font color="#cc0000">Download Hires</font></a>';


					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', myhrdlink, myreleased);

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

			}
		}
	} 
	return html;
 };

//CALLBACK ACTion for enlarge2
 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)
                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 myratetiers_data = document.JSONobj.getImgDat('tieredimgpricing'); //myratetiers is a data object now.. so build..
                        var myratetiers = enlarge2_act__generateTierRows(myratetiers_data,myrmrftype,enid,encount);


			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];
			
			//this ifblock becomes template var: themediainsert
			var themediainsert = '';
			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);
				themediainsert += '<A HREF="" onclick="currentpage(); return false;">'
					+'<img src="http://globaldyn.ipnstock.com/'+dynimagesname+'/'+
					( (typeof(localwatermark) != 'undefined' && ! pngsupport) ? 'wm' : '420' )
					+'/60/'+tarid+'.JPG" 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){
				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=http://globaldyn.ipnstock.com/'+dynimagesname+'/135/50/' + simarray[i] + '.JPG 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="" 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="" 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="" onclick="document.currentLayer1Mode=\'searchresults\'; viewmode=\'' + viewmode + '\';gsetCookie(\'gviewmode\',\'' + viewmode + '\', \'\', \'/\', gGetCookieDom()); currentpage(); 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+= '<div id="buttonprev" style="float:left;margin-right:10px"><A HREF="" onclick="enlarge2(\'' + previmageid + '\',\'' + previmage + '\'); return false;" TITLE="GO TO THE PREVIOUS IMAGE"></A></div>';}
				if((Number(snum) + Number(encount) + 1) < Number(results_total)){ 
					navenlargedlinks+= '<div style="float:left;margin-right:5px"><A HREF="" onclick="enlarge2(\'' + nextimageid + '\',\'' + nextimage + '\'); return false;" TITLE="GO TO THE NEXT IMAGE" style="text-decoration:none;color:#000">Next image</A></div>';
					navenlargedlinks+= '<div id="buttonnext" style="float:left"><A HREF="" onclick="enlarge2(\'' + nextimageid + '\',\'' + nextimage + '\'); return false;" TITLE="GO TO THE NEXT IMAGE"></A></div><BR>';

				}
			    }
			}

			var enlargetid = '';
			if(featuredimage){ enlargetid = featuredimage;} else { 	enlargetid = enid;}
			
			//will become downloadcomplink
			var downloadcomplink = '';
			if(preMem != 'cartview')
			{
				if(gsession && gusername && mycompallow == 'Y') { 
					downloadcomplink = '<a href="Javascr' + 'ipt:displayWindow(\'/comp_view.shtml?' + gusername + '/' + cs[encount] + '/' +
					id[encount]
					+ '.JPG\',\'600\',\'640\');">Download preview image</a><BR><BR>';
				} else {
				if(gsession) {
					downloadcomplink = '<a href="Javascr' + 'ipt:displayWindow(\'/comp_view.shtml?guest/' + cs[encount] + '/' +
					id[encount]			
					+ '.JPG\',\'600\',\'640\');">Download preview image</a><BR><BR>';
					}else{
						downloadcomplink = '<a href="javascript: return false;" onclick="javascript: show_login();">Download preview image</a>';
					}
				}
			}
	
			// META DATA FOR ENLARGED TARGET IMG:
	
			//will become: ratetierinfo
			var ratetierinfo = ( myratetiers ? '<BR/><div class="enlargeratetiers">' + myratetiers + '</div>' : '' );
			
			//becomes releaseinfo
			var releaseinfo = ( showrelease ? '<b>Released:</b> ' + myreleased : ' Not Applicable' );
			
			//becomes photographerinfo
			var linked_photog = myphotographer;
			if(myphotographer.indexOf('/') > 0)
				linked_photog = linked_photog.substring(0, linked_photog.indexOf('/'));
//			var photographerinfo = ( (myphotographer && showphotographer) ? '<b>Credit:</b> <A href="/SwishSearch?Keywords=' + linked_photog + '&spec_idx=ne&method=photographer">' + myphotographer + '</a>' + (typeof(defaultcredit) !='undefined' ? defaultcredit : '') + '<br>' : '');
	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 ? '<span style="color:#990000">'+myrestrictions+'</span>' : 'No Restrictions');
			
			//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 subject = document.JSONobj.getImgDat('subject');

			if((typeof(subject) != 'undefined') && (subject != '')){
				var subarr = subject.split(",");
				for(i=0;i<subarr.length;i++){
					var sarr = subarr[i].split(".");
					for(j=0;j<sarr.length;j++)
					keywordinfo += ',<a href="/SwishSearch?Keywords=' + sarr[j] +'&spec_idx=ne">' + sarr[j] + '</a>';
				}
				
			}


			var location_country = document.JSONobj.getImgDat('location_country');
			if((typeof(location_country) != 'undefined') && (location_country != ''))
                                keywordinfo += ', <a href="/SwishSearch?Keywords=' +location_country +'&spec_idx=ne">' + location_country + '</a> ';

			var location_state = document.JSONobj.getImgDat('location_state');
			if((typeof(location_state) != 'undefined') && (location_state != ''))
                                keywordinfo += ', <a href="/SwishSearch?Keywords=' +location_state +'&spec_idx=ne">' + location_state+ '</a> ';
			
			var location_city = document.JSONobj.getImgDat('location_city');
			if((typeof(location_city) != 'undefined') && (location_city != ''))
                                keywordinfo += ', <a href="/SwishSearch?Keywords=' +location_city +'&spec_idx=ne">' + location_city+ '</a>';


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

			var dateshot = document.JSONobj.getImgDat('date_shot');
			var rfcdlinkslug = document.JSONobj.getImgDat('rfcdlink');
		
			myrmrftype = (myrmrftype == "RF") ? "Royalty Free" : "Rights Managed";
			var hires_link	 = "";
			var manage_link = "";
			if(gadmin && gadmin_links && gusername && gsession) {
				hires_link = '<br/><NOBR><a href="'+hrdl[encount]+'" ><font color="#cc0000">Download Hires</font></a></NOBR>';
				manage_link = '<br/><NOBR><a target="_blank" href="/bin/QuickEdit?oid='+displayenlargetid+'" ><font color="#cc0000">Manage Image</font></a></NOBR>';
			}
			var calcusage = "";
			if(myrmrftype == "Rights Managed")
				calcusage = Templates.calc_usage_text.evaluate({enlargetid: enlargetid}) ;

			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,
					currentyear: currentYear,
                                	baseurl: baseurl,
					hires_link : hires_link,
					manage_link : manage_link,
					calcusage: calcusage
				});
			//write html for enlarge page
			$('Layer1').style.overflow = 'auto';
			MM_setTextOfLayer('Layer1','', Templates.enlarge2_act__body.evaluate(tdata));
			//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');
		} 
		else {
			//alert("This is the last image of the search results.");
			gsetCookie('gviewmode','ss', '', '/', gGetCookieDom());

			self.location= nextlink.replace(/&#34;/g,"\"") + 'snum=' + (Number(firstpictureonpage) + Number(snum)); //figure out which should be first picture on next page	
		}//end if id[enid]	
/*	}
	else if ( tryCtr < 10 ) 
	{
		tryCtr++;
		setTimeout("enlarge2_act('"+enid+"','"+encount+"','"+featuredimage+"', '"+tryCtr+"', 0, '"+preMem+"')", (500 + (10 * (tryCtr - 1))));
	}
	else // nothing loaded, pop the page w/ missing data..
	{
		enlarge2_act(enid,encount,featuredimage,tryCtr,1,preMem);
	}
*/	
 };

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

        var row2=document.getElementById("row2");
	var bdresultsLayer = document.getElementById("bdresultsyellow");

        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";
	if((typeof(bdresultsLayer) != 'undefined') && (bdresultsLayer != null)){
		bdresultsLayer.style.backgroundColor="#fff";
	}

 };


function lightbox_addto(id) { // adding an image to the current lightbox

        if (gsession)
        {
                var clb_exists = ( typeof(document.currentlbstash) == 'object' ? 1 : 0 );
                var temp= ( clb_exists ? document.currentlbstash.join(" ") : '');
                if(temp.indexOf(id)>0){
                        alert('That image is already in your Lightbox');
                } else {
                        if (! currentlbname)
                                currentlbname = 'newlb';

                        if (!document.currentlbstash.push)
                                document.currentlbstash = new Array();

                        document.currentlbstash.push({id: id, rfcd: ''});

                        var mobid = ((typeof(mobject_id) != 'undefined' && mobject_id != '') ? 'mob='+mobject_id : '');
                        var lbs = make_lightbox_string(gusername,currentlbname,id);
                        ajax_JSON('/AjaxHandlers/LightboxAddTo/' + lbs + '.json', getpost, mobid);

                        if(clb_exists)
                                lightbox_build(document.currentlbstash);
                }
        }
        else //not
        {
              show_login(); 
        }

};

function cart_addto(id,args){
        if (gsession)//logged in user
        {
            if( document.JSONobj.getCartDat && typeof(args) == 'undefined' )
            {
                for (var cti=0;cti<document.JSONobj.getCartDat('total');cti++)
                {
                        if ( id == document.JSONobj.getCartDat('image_id',cti) )
                        {
//need to do reprice thing here?
                                alert('That image is already in your Cart');
                                return;
                        }
                }
            }

            if ( typeof(args) == 'undefined' )
            {
                args = $H({ callback: 'cart_mod_act(0)' });
            }
            else if ( args.callback && args.callback.toString().length > 1)  //allready passed a callback so append..
            {
                args.callback += ' cart_mod_act(0);';
            }
            else
            {
                args.callback  = 'cart_mod_act(0)';
            }

            document.TEXTresp = null;
            simplemessage('Adding image to Shopping Cart <blink>.</blink>','','LB');
            if ( typeof(args) == 'object' && args.Size_opname ) //meaning RF pricing data was sent along..
            {
                Object.extend(args, {
                    calc_rate: 1
                });
            }

                ajax_TEXT('/AjaxHandlers/CartAdd/' + id + '.txt', 'POST', args);
                cart_mod_act(-1);
        }
        else //not
        {
		show_login();
        }
};

function license(id) {
	if(gsession)
	        launchwin('/bin/Rates?calc_only=1&usage=1&ln='+id);
	else
		show_login();
};

function price_image(pid,ttype){

	if(gsession){
	        if (! pid || ! pid.match(/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/))  //did this longhand (instead of w/ curly brackets) b/c
        	        return false;                                                      //it screws up the compressors otherwise

	        //get image info to retrieve pricing tier
        	var url = '/AjaxHandlers/ImageInfo/'+ pid + '.json';
	        ajax_JSON( url, 'POST', null );

        	price_image_act(pid, 0, 0);
	}else{
		show_login();
	}

        return false;
};


var loginObj = new loginRegister();
var show_login = loginObj.showLogin;
var evaluate_login = loginObj.evaluateLogin;
var hide_login = loginObj.hideLogin; 


function loginRegister(){

this.showLogin = showLogin;
this.hideLogin = hideLogin;
this.evaluateLogin =  evaluateLogin;

function showLogin(){

	$('loginLayer').style.display = "block";
	$('loginLayerCover').style.display = "block";
	var mesg = "Login";	
	$('loginLayer').innerHTML  = Templates.login.evaluate({message: mesg});
	$('username').focus();
	
}

function evaluateLogin(form){
	//if(!validEmail($('username').value)){
	if(isBlank($('username').value)){
		loginMessage('Invalid email address. Please enter a valid email.');
		$('username').focus();
		return false;
	}
	if(isBlank($('password').value)){
		loginMessage('Please enter your password');
		$('password').focus();
		return false;
	}else{
	//	loginMessage("Authenticating ...");
		return submitLogin();
	}
	return true;
}

function validEmail(val)
{
	if(val.match(/[A-Za-z][A-Za-z0-9._]+\@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+/))
		return true;

	return false;
}

function isBlank(val){
	if(val.match(/^\s*$/))
		return true;
	
	return false;
}

function hideLogin(){
	$('loginLayer').style.display="none";
	$('loginLayerCover').style.display="none";
}

function submitLogin(){
	var meth = "POST";
	var url = "/AjaxHandlers/LoginAjax/.json";
	
	var params ={ "username"  : $('username').value,
			"password" : $('password').value,
			"sphotog" : $('sphotog').value,
			"login" :  1};

	var myAjax = new Ajax.Request(
                url,
                {
                        method: meth ,
                        parameters: params,
			onSuccess : function(responseObj){
				var responseHsh = responseObj.responseText.evalJSON();
				if(responseHsh.success){
					loginMessage('Login Successful - please wait a moment.');
					window.location.reload();
				}else	
					loginMessage(responseHsh.message); 
			 },
                        onFailure: function () {alert('communications error'); }
                }
        );

	return false;
}

function loginMessage(txt){
	$('loginMessage').style.display='block';
	 $('loginMessage').innerHTML = txt; 

}


};
