// Photo Display Helper functions

function pGetObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function popPhotos(product_id){

	URL = '/photopop.php?p='+product_id;
	
	var pactivephoto_id = pGetObject('pactivephoto');
	
	if(pactivephoto_id){
		//URL = URL + '#'+pactivephoto_id.value;
	}
	
	fncCenteredChildWindow(URL,'600','840','yes','yes');
}

function pSwithImage(photo_id){

	var pactivephoto_id = pGetObject('pactivephoto'); 
	var primary_photo = pGetObject('pprimary');
	var active_caption = pGetObject('pcap');
	
	if(pactivephoto_id){
		var pthumb_old = pGetObject('pthumb_'+pactivephoto_id.value);
	}
	
	var pmed = pGetObject('pmed_'+photo_id);
	var pcap = pGetObject('pcap_'+photo_id);
	var psource = pGetObject('psource_'+photo_id);
	var pthumb_img = pGetObject('pthumb_'+photo_id);
	
	if(primary_photo){
		//alert(photo_id);
		if(pmed){
			primary_photo.src = pmed.value;
		}
	}
	
	if(pthumb_img){
		pthumb_img.className='thumbActive';
	}
	
	if(pthumb_old){
		pthumb_old.className='thumbPhoto';
	}
	
	if(active_caption){
		if(pcap){
			active_caption.innerHTML = pcap.value;
		}
	}
	
	if(pactivephoto_id){
		pactivephoto_id.value = photo_id;
	}
}

function fncCenteredChildWindow(URL,vHeight,vWidth,vScroll,vStatus) {
	if (screen.width) {
		var winl=(screen.width-vWidth)/2;
		var wint=(screen.height-vHeight)/2;
	} else { 
		winl=0;wint=0;
	}
	if(winl<0)winl=0;
	if(wint<0)wint=0;
	window.open(URL,'myWin','height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus+',top='+wint+',left='+winl+',resizable=yes')
}