	var actualWidth  = 0;
	var actualHeight = 0;
	var currentWidth  = 0;
	var currentHeight = 0;
	var thumbsWidth	= 0;
	var pictureID = '';
	var celebrityDirectory = '';
	var subfolder = '';
	var profiledomain = '';
	var typ='';

function highlight(field) {
	field.focus();
 	field.select();
	field.focus();
}

function set_thumb_input_values() {
  document.getElementById("th1").value = '<a href="http://'+celebrityDirectory+'.'+profiledomain+'/'+subfolder+'/'+pictureID+'/"><img src="http://'+celebrityDirectory+'.'+profiledomain+'/th_t'+typ+'x0y0i'+pictureID+'.jpg"/></a>';
  document.getElementById("th2").value = '[url=http://'+celebrityDirectory+'.'+profiledomain+'/'+subfolder+'/'+pictureID+'/][img]http://'+celebrityDirectory+'.'+profiledomain+'/th_t'+typ+'x0y0i'+pictureID+'.jpg[/img][/url]';
  document.getElementById("th3").value = '[link=http://'+celebrityDirectory+'.'+profiledomain+'/'+subfolder+'/'+pictureID+'/][img]http://'+celebrityDirectory+'.'+profiledomain+'/th_t'+typ+'x0y0i'+pictureID+'.jpg[/img][/link]';
  
	if (!window.clipboardData)	{
	  document.getElementById("Button0").style.display='none';
	  document.getElementById("Button1").style.display='none';
	  document.getElementById("Button2").style.display='none';
	  document.getElementById("Button3").style.display='none';
	  document.getElementById("Button4").style.display='none';
	  document.getElementById("Button5").style.display='none';
	}

}

function set_values(width,height) {
  document.getElementById("hl1").value = '<a href="http://'+celebrityDirectory+'.'+profiledomain+'/'+subfolder+'/'+pictureID+'/"><img src="http://'+celebrityDirectory+'.'+profiledomain+'/hl_t'+typ+'x'+width+'y'+height+'i'+pictureID+'.jpg"/></a>';
  document.getElementById("hl2").value = '[url=http://'+celebrityDirectory+'.'+profiledomain+'/'+subfolder+'/'+pictureID+'/][img]http://'+celebrityDirectory+'.'+profiledomain+'/hl_t'+typ+'x'+width+'y'+height+'i'+pictureID+'.jpg[/img][/url]';
  document.getElementById("hl3").value = '[link=http://'+celebrityDirectory+'.'+profiledomain+'/'+subfolder+'/'+pictureID+'/][img]http://'+celebrityDirectory+'.'+profiledomain+'/hl_t'+typ+'x'+width+'y'+height+'i'+pictureID+'.jpg[/img][/link]';
  document.getElementById("PictureWidth").value = width;
  document.getElementById("PictureHeight").value = height;
}

function calc_width(actualWidth,actualHeight) {
  height = document.getElementById("PictureHeight").value;
  if (height=="") {height=0}
  if (height>actualHeight) { height=actualHeight }
  width = Math.floor(height / actualHeight * actualWidth);
  set_values(width,height);
}

function calc_height(actualWidth,actualHeight) {
  width = document.getElementById("PictureWidth").value;
  if (width=="") {width=0}
  if (width>actualWidth) { width=actualWidth }
  height = Math.floor(width / actualWidth * actualHeight);
  set_values(width,height);
}

function CopyCode(box) {      
	var code = box.value;
	if (window.clipboardData)	{
		window.clipboardData.setData("Text", code);
    alert("Copied to clipboard.");
	}
}

onresize=liveResize;

	function setDim(acelebrityDirectory,asubfolder,aprofiledomain,atyp,aWidth,aHeight,pID,tWidth) {
		actualWidth  = aWidth;
		actualHeight = aHeight;
		pictureID	= pID;
		thumbsWidth = tWidth;
		celebrityDirectory = acelebrityDirectory;
		subfolder=asubfolder;
		profiledomain = aprofiledomain
		typ = atyp;
  }

	function CurrentThumb() {
	  var cell  = document.getElementById('p'+pictureID);             
	  cell.className = "imageThumbnailtst";
	}
	
	function NextPicture() {
		var table  = document.getElementById('thumbTable');		
		var tds = table.getElementsByTagName('td');
		var nextpicture = '';
	  	
 		var prevpicture = tds[0].getElementsByTagName('a')[0].href;

		j = 0;
		for (i=0;i<tds.length;i++) {
			if (tds[i].id != '') j++;
  		
  			if (tds[i].id == 't'+pictureID) {
  				if (j > 2) {
     			  tag = tds[i-1].getElementsByTagName('a');
		      	prevpicture = tag[0].href;
 				} else if (tds[0].id != 'prevpage' ) {
 			  		tag = tds[i].getElementsByTagName('a');
	      		prevpicture = tag[0].href;
	  			}
  			}
  		                      
	  		if (tds[i].id == 't'+pictureID) { 
				if (i == tds.length-1)
	  			nextpicture = tds[i].getElementsByTagName('a')[0].href;
				else
			  	nextpicture = tds[i+1].getElementsByTagName('a')[0].href;
			}
		}  

		document.getElementById('prevpicturetop').href = prevpicture;
		document.getElementById('nextpicturetop').href = nextpicture;
		document.getElementById('prevpicturebottom').href = prevpicture;
		document.getElementById('nextpicturebottom').href = nextpicture;
	}

  function scale(orgWidth,orgHeight,width,height) {
		what = document.getElementById('thepic');
		if (currentWidth == 0 || currentWidth == width) {
  	  what.width=orgWidth;
		  what.height=orgHeight;
  	  currentWidth=orgWidth;
		  currentHeight=orgHeight;
		} else {
  	  what.width=width;
		  what.height=height;
  	  currentWidth=width;
		  currentHeight=height;
		}
  }

	function scaleImg() {
		if (fitsInWindow())
			return;
	
		what = document.getElementById('thepic');
		
		if (what.width<=tableWidth()) {
			what.width=actualWidth;
			what.height=actualHeight;
			displayWarning("none");
		} else {
			what.style.cursor = "pointer";
			what.width=tableWidth();
			what.height=(tableWidth() / actualWidth) * actualHeight;
			displayWarning("block");
		}
	}
	
	function liveResize() {
		if (fitsInWindow())
			return;
		
		what = document.getElementById('thepic');
		
		if (what.width!=actualWidth) {
			what.width=tableWidth();
			what.height=(tableWidth() / actualWidth) * actualHeight;
			displayWarning("block");
		}
	}

	function setImgWidth() {
		if (fitsInWindow()) {
			return;
		}
		what = document.getElementById('thepic');
		what.width=tableWidth();
		what.height=(tableWidth() / actualWidth) * actualHeight;
		what.style.cursor = "pointer";
		
	  var div  = document.getElementById('thewidth');             
	  div.style.width = tableWidth()+'px';
	}
	
	function tableWidth() {
    var wW = windowWidth()-686;
    if (wW < 720) wW = 720;
    if (wW < thumbsWidth) wW = thumbsWidth;
		return  wW;
	}
	
	function windowWidth() {
	  var x;
	  
    if (self.innerWidth) {
	    x = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) {
	    x = document.documentElement.clientWidth;
    } else if (document.body) {
	    x = document.body.clientWidth;
    }

		return x;
	}

	function fitsInWindow() {
		if (actualWidth<tableWidth()) {
			displayWarning("none");
			return true;
		}
		
		return false;
	}
      
	function displayWarning(how) {
		document.getElementById('scaled').style.display=how;
	}
