function set_top_image(id, scroll) {
	var img_div = 'top_image_container';
	var nav_div = 'top_nav_container';
	var img = array_img[id];
	var alt = array_alt[id];
	var iw = array_width[id];
	var ih = array_height[id];
	var description = array_description[id];
	var nextPage = currentPage+1;
	var previousPage = currentPage - 1;
	var currentPic = id;
	
	/* 
	* allPictureCount
	* pageCount
	* currentPage
	* navHit
	* baseURI
	*
	* firstPicOnPage = 1 always starts the id count over on a new page
	* maxid = lastPicOnPage = maxid
	*/
	
	if(pageCount == 1){
		nextPage = currentPage;
		previousPage = currentPage;
	} else if(currentPage == pageCount){
		nextPage=1;
	} else if(currentPage == 1){
		previousPage = pageCount;
	}
			
	if(id == maxid){
		nextid = 1;
	} else {	
		nextid = id - 1+2;
	}
	
	if(id == '1'){
		previousid = maxid;
	} else {
		previousid = id - 1;
	}
	
	if(currentPage > 1){
		currentPic = (((currentPage - 1) * 20)+parseFloat(id));
	}
	
	var img_n = document.getElementById(nav_div);
	var html_nav = '';

	html_nav += '<h1 class="right">';
	if(id == maxid && pageCount > 1){
		html_nav += '		<a id="'+nextPage+'" title="View Page" href="'+baseURI+'?nggpage='+ nextPage+'">NEXT &raquo;</a>';
	} else if(id != maxid){
		html_nav += '		<a id="'+nextid+'" onclick="return set_top_image(this.id)" title="View Next" href="'+array_img[nextid]+'">NEXT &raquo;</a>';
	}
	html_nav += '</h1>';
	html_nav += '		<div class="right nav_number">'+currentPic+' of '+allPictureCount+'</div>';
	html_nav += '<h1 class="right">';
	if(id == 1 && pageCount > 1){
		html_nav += '		<a id="'+previousPage+'" title="View Previous Page" href="'+baseURI+'?navhit=prev&nggpage='+ previousPage+'">&laquo; PREVIOUS</a>';
	} else if(id > 1){ 
		html_nav += '		<a id="'+previousid+'" onclick="return set_top_image(this.id)" title="View Previous" href="'+array_img[previousid]+'">&laquo; PREVIOUS</a>';
	}
	html_nav += '</h1>';
	
	img_n.innerHTML = html_nav;		
	  	
	var maxw = 660;
	var maxh = 500;			
	var img_d = document.getElementById(img_div);
	if(nextid == 1){
		var html_img = '';
	} else {		
		if(id == maxid && pageCount > 1){
			var html_img = '		<a id="'+nextPage+'" title="View Page" href="'+baseURI+'?nggpage='+ nextPage+'">';
		} else if(id != maxid){
			var html_img = '		<a id="'+nextid+'" onclick="return set_top_image(this.id)" title="View Next" href="'+array_img[nextid]+'">';
		}
	}
	
	html_img += '<img src="'+img+'" alt="'+alt+'"';
	
	var parsedIW = parseFloat(iw);
	var parsedIH = parseFloat(ih);
			
	if (parsedIH > parsedIW && parsedIH > parseFloat(maxh)) {
    f=1-((parsedIH - parseFloat(maxh)) / parsedIH);
    uw=parsedIW * f;
    uh=parsedIH * f;    		
	} else if (parsedIW > parseFloat(maxw)) {
  	f=1-((parsedIW - parseFloat(maxw)) / parsedIW);
  	uw=parsedIW * f;
  	uh=parsedIH * f;
	} else {
		uw = parsedIW;
		uh = parsedIH;    	
	}
		
  html_img += ' width="'+uw+'"';
  html_img += ' height="'+uh+'"';
	html_img += 'border="0" class="gown_main" /></a>';
	html_img += '<div class="description">';
	html_img += '<em>'+description+'</em>';
	html_img += '</div>';
	
	img_d.innerHTML = html_img;	
	
	if(scroll == 'yes'){
		window.scrollTo(0,350);	
	}
	return false;
}

function set_top_image_listing(id, scroll) {
	var img_div = 'top_image_container_listing';
	var nav_div = 'top_nav_container_listing';
	var img = array_img[id];
	var alt = array_alt[id];
	var iw = array_width[id];
	var ih = array_height[id];
	
	if(id == maxid){
		nextid = 1;
	}	else {	
		nextid = id - 1+2;
	}
	
	if(id == '1'){
		previousid = maxid;
	} else {
		previousid = id - 1;
	}
	
	var img_n = document.getElementById(nav_div);
	var html_nav = '';

	html_nav += '<div class="gown_previous">';
		html_nav += '		<a id="'+previousid+'" onclick="return set_top_image_listing(this.id)" title="View Previous" href="'+array_img[previousid]+'"></a>';
	html_nav += '</div>';	
	html_nav += '<div class="gown_next">';
		html_nav += '		<a id="'+nextid+'" onclick="return set_top_image_listing(this.id)" title="View Next" href="'+array_img[nextid]+'"></a>';
	html_nav += '</div>';
		    
	img_n.innerHTML = html_nav;		
	  	
	var maxw = 330;
	var maxh = 506;			
	var img_d = document.getElementById(img_div);
	var	html_img = '		<a id="'+nextid+'" onclick="return set_top_image_listing(this.id)" title="View Next" href="'+array_img[nextid]+'">';
	html_img += '<img class="gown_main" src="'+img+'" alt="'+alt+'"';
	
	var parsedIW = parseFloat(iw);
	var parsedIH = parseFloat(ih);
			
	if (parsedIH > parsedIW && parsedIH > parseFloat(maxh)) {
    f=1-((parsedIH - parseFloat(maxh)) / parsedIH);
    uw=parsedIW * f;
    uh=parsedIH * f;    		
	} else if (parsedIW > parseFloat(maxw)) {
  	f=1-((parsedIW - parseFloat(maxw)) / parsedIW);
  	uw=parsedIW * f;
  	uh=parsedIH * f;
	} else {
		uw = parsedIW;
		uh = parsedIH;    	
	}
		
  html_img += ' width="'+uw+'"';
  html_img += ' height="'+uh+'"';
	html_img += 'border="0" /></a>';
	
	img_d.innerHTML = html_img;	
	
	if(scroll == 'yes'){
		window.scrollTo(0,350);	
	}
	return false;
}

function set_top_image_vendor(id, scroll) {
	var img_div = 'side_image_container_vendor';
	var img = array_img[id];
	var alt = array_alt[id];
	var iw = array_width[id];
	var ih = array_height[id];
	
	if(id == maxid){
		nextid = 1;
	}	else {	
		nextid = id - 1+2;
	}
	
	if(id == '1'){
		previousid = maxid;
	} else {
		previousid = id - 1;
	}
	
	var maxw = 500;
	var maxh = 400;			
	var img_d = document.getElementById(img_div);
	var	html_img = '		<a id="'+nextid+'" onclick="return set_top_image_vendor(this.id)" title="View Next" href="'+array_img[nextid]+'">';
	html_img += '<img class="gown_main" src="'+img+'" alt="'+alt+'"';
	
	var parsedIW = parseFloat(iw);
	var parsedIH = parseFloat(ih);
			
	if (parsedIH > parsedIW && parsedIH > parseFloat(maxh)) {
    f=1-((parsedIH - parseFloat(maxh)) / parsedIH);
    uw=parsedIW * f;
    uh=parsedIH * f;    		
	} else if (parsedIW > parseFloat(maxw)) {
  	f=1-((parsedIW - parseFloat(maxw)) / parsedIW);
  	uw=parsedIW * f;
  	uh=parsedIH * f;
	} else {
		uw = parsedIW;
		uh = parsedIH;    	
	}
		
  html_img += ' width="'+uw+'"';
  html_img += ' height="'+uh+'"';
	html_img += 'border="0" /></a>';
	
	img_d.innerHTML = html_img;	
	
	if(scroll == 'yes'){
		window.scrollTo(0,350);	
	}
	return false;
}

function MM_swapImgRestore() { //v3.0  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}function MM_preloadImages() { //v3.0  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}function MM_findObj(n, d) { //v4.01  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);  if(!x && d.getElementById) x=d.getElementById(n); return x;}function MM_swapImage() { //v3.0  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
  else
    countfield.value = maxlimit - field.value.length;
}

function jchange(o) {
	var fold_image = new Array();
	
	if(document.getElementById(o).style.display=='none') {
		document.getElementById(o).style.display='block';
	} else {
		document.getElementById(o).style.display='none';
	}
}