// JavaScript Document

// AJAX INIT STUFF -- START
var xmlhttp=null;


try
{
	xmlhttp = new XMLHttpRequest();
}
catch (error)
{
	try
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (error)
	{
		xmlhttp = null;
	}
}
//  END

var scrollCell, scrollCell2, contentHeight, contentHeight2, timer, timer2, lefttime, topStop, topStop2, theTimer;
var currentDiv = '#page1';

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 initialize(){
	scrollCell = document.getElementById('scrollCell');
	contentHeight = scrollCell.offsetHeight; //alert(contentHeight);
	scrollCell.style.top = '0px';
	topStop = 0;
	
	scrollCell2 = document.getElementById('scrollCell2');
	contentHeight2 = scrollCell2.offsetHeight; //alert(contentHeight);
	scrollCell2.style.top = '0px';
	topStop2 = 0;
}

function initialize2(){
	scrollCell2 = document.getElementById('scrollCell2');
	contentHeight2 = scrollCell2.offsetHeight; //alert(contentHeight);
	scrollCell2.style.top = '0px';
	topStop2 = 0;
}

function scrollDown(stopScroller){	
	if(stopScroller){
		clearInterval(timer);
	}else{
		//alert(scrollCell.style.top);
		timer=setInterval("moveScroll(true)",50);
	}
}

function scrollUp(stopScroller){	
	if(stopScroller){
		clearInterval(timer);
	}else{
		//alert('start');
		timer=setInterval("moveScroll(false)",50);
	}
}

function moveScroll(down){
	scrollCell = document.getElementById('scrollCell');
	//smallBlock = document.getElementById('smallBlock');
	//if(isNaN(parseInt(smallBlock.style.paddingTop))) smallBlock.style.paddingTop = '0px';
	if(down){
		if(parseInt(scrollCell.style.top) > ((contentHeight-300)*-1)){ //alert(contentHeight/20);
			scrollCell.style.top = parseInt(scrollCell.style.top) - 20 + 'px';
			//if(parseInt(smallBlock.style.paddingTop) < 122) smallBlock.style.paddingTop = parseInt(smallBlock.style.paddingTop) + 144/((contentHeight  - 300)/20) + 'px';
		}
	}else{
		if(parseInt(scrollCell.style.top) < 0){
			scrollCell.style.top = parseInt(scrollCell.style.top) + 20 + 'px';
			//if(parseInt(smallBlock.style.paddingTop) < 122) smallBlock.style.paddingTop = parseInt(smallBlock.style.paddingTop) - 105/((contentHeight  - 300)/20) + 'px';
		}
	}
}

function scrollDown2(stopScroller){	
	if(stopScroller){
		clearInterval(timer2);
	}else{
		//alert(scrollCell.style.top);
		timer2=setInterval("moveScroll2(true)",50);
	}
}

function scrollUp2(stopScroller){	
	if(stopScroller){
		clearInterval(timer2);
	}else{
		//alert('start');
		timer2=setInterval("moveScroll2(false)",50);
	}
}

function moveScroll2(down){
	scrollCell2 = document.getElementById('scrollCell2');
	if(down){
		if(parseInt(scrollCell2.style.top) > ((contentHeight2+160)*-1)){
			scrollCell2.style.top = parseInt(scrollCell2.style.top) - 12 + 'px';
		}
		//alert(parseInt(scrollCell.style.top) + '--' + (contentHeight*-1));
	}else{
		if(parseInt(scrollCell2.style.top) < 0){
			scrollCell2.style.top = parseInt(scrollCell2.style.top) + 12 + 'px';
		}
		//document.getElementById('echo').innerHTML = parseInt(scrollCell.style.top) + '--' + (contentHeight*-1);
	}
}

function top(){
	scrollCell.style.top = '0px';
}

function hideMenu(whichMenu){
	//alert(whichMenu);
	var divtohide=document.getElementById(whichMenu);
	divtohide.style.display = 'none';
}

function hideAllMenus(doNotHideMenu){
	document.getElementById('dropMenu1').style.display = 'none';
	document.getElementById('dropMenu2').style.display = 'none';
	document.getElementById('dropMenu3').style.display = 'none';
	document.getElementById('dropMenu4').style.display = 'none';
	document.getElementById('dropMenu5').style.display = 'none';
	document.getElementById('dropMenu6').style.display = 'none';
	document.getElementById('dropMenu7').style.display = 'none';
}

function changeBack(whichMenu){
	//alert(whichMenu);
	theTimer = setTimeout("hideMenu('"+whichMenu+"')", 400);
} 

function showMenu(whichMenu, whichAnchor, positionx, positiony){
	hideAllMenus(whichMenu);
	clearTimeout(theTimer);
	positionMenu(whichMenu, whichAnchor, positionx, positiony);
	document.getElementById(whichMenu).style.display = 'block';		
}

function positionMenu(whichMenu, whichAnchor, positionx, positiony){
	var c = getAnchorPosition(whichAnchor);
	//alert("X = "+c.x+" , Y = "+c.y);
	if (document.getElementById) {
		var o = document.getElementById(whichMenu);
		//alert(o.style.left);
		if (o.style) {
			o.style.left = (c.x + positionx) + 'px';
			o.style.top = (c.y + positiony) + 'px';
		}
	}
}

function getPhoto(photoID){ //alert('fire');	
	xmlhttp.open("GET", "/ajaxHandler.php?object=getPhoto&photoID=" + photoID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			photoElementsString = xmlhttp.responseText; //alert(photoElementsString);
			photoElementsArray = photoElementsString.split('|');
			document.getElementById('photoCaption').innerHTML = photoElementsArray[1];
			document.getElementById('largePhoto').innerHTML = photoElementsArray[0];
			document.getElementById('currentPhoto').value = photoID;
		}
	}
	xmlhttp.send(null);
}

function getPhotoThumbs(pageNumber){ //alert('fire');	
	xmlhttp.open("GET", "/ajaxHandler.php?object=getPhotoThumbs&pageNumber=" + pageNumber);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			photoCatalogString = xmlhttp.responseText;  //alert(photoCatalogString);
			photoCatalogArray = photoCatalogString.split('~');
			document.getElementById('nextPrevPhotos').value = photoCatalogArray[1];
			document.getElementById('photoCatalog').innerHTML = photoCatalogArray[0];
		}
	}
	xmlhttp.send(null);
}

function nextPhoto(){
	photoIDsArray = document.getElementById('nextPrevPhotos').value.split('|');
	currentPhoto = document.getElementById('currentPhoto').value;
	
	for(i=0; i<photoIDsArray.length; i++){
		if(currentPhoto == photoIDsArray[i]){
			photoIdPosition = i;
		}
	}
	if(photoIdPosition == (photoIDsArray.length - 1)){
		getPhoto(photoIDsArray[0]);
	}else{
		getPhoto(photoIDsArray[(photoIdPosition + 1)]);
	}
}

function previousPhoto(){
	photoIDsArray = document.getElementById('nextPrevPhotos').value.split('|');
	currentPhoto = document.getElementById('currentPhoto').value;
	
	for(i=0; i<photoIDsArray.length; i++){
		if(currentPhoto == photoIDsArray[i]){
			photoIdPosition = i;
		}
	}
	if(photoIdPosition == 0){
		getPhoto(photoIDsArray[(photoIDsArray.length - 1)]);
	}else{
		getPhoto(photoIDsArray[(photoIdPosition - 1)]);
	}
}

function getVideo(videoID){ //alert('fire');	
	xmlhttp.open("GET", "/ajaxHandler.php?object=getVideo&videoID=" + videoID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('videoCell').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
		}
	}
	xmlhttp.send(null);
}
 
function getVideoThumbs(pageNumber){ //alert('fire');	
	xmlhttp.open("GET", "/ajaxHandler.php?object=getVideoThumbs&pageNumber=" + pageNumber);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('videoListing').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function showCommission(commissionID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=getCommission&commissionID=" + commissionID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('commissionFrame').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			initialize2();
		}
	}
	xmlhttp.send(null);
}

function showOriginal(originalID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=getOriginal&originalID=" + originalID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('commissionFrame').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			initialize2();
		}
	}
	xmlhttp.send(null);
}

function showDrawing(drawingID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=getDrawing&drawingID=" + drawingID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('commissionFrame').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			initialize2();
		}
	}
	xmlhttp.send(null);
}

function showPrivateCollection(originalID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=getPrivateCollection&originalID=" + originalID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('commissionFrame').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
		}
	}
	xmlhttp.send(null);
}

function showBook(bookID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=getBook&bookID=" + bookID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('commissionFrame').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
		}
	}
	xmlhttp.send(null);
}

function showPrint(printID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=getPrint&printID=" + printID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('commissionFrame').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			initialize2();
		}
	}
	xmlhttp.send(null);
}

function showPopupPrint(printID){
	document.getElementById('popupBkg').style.display = 'block';
	document.getElementById('popupImage').style.display = 'block';
	//document.getElementById('popupImage').innerHTML = '<div align="center"><img src="/images/common/ajax-loader2.gif" alt="Loading..." style="padding-top:325px; padding-bottom:10px"><br><span style="font-family:\'Times New Roman\', Times, serif; font-style:italic; font-size:18px; font-weight:bold; color:#FFFFFF">Loading...</span></div>';
	
	xmlhttp.open("GET", "/ajaxHandler.php?object=showPopupPrint&printID=" + printID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);		
		}
	}
	xmlhttp.send(null);
}

function showPopupOriginal(originalID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=showPopupOriginal&originalID=" + originalID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			document.getElementById('popupBkg').style.display = 'block';
			document.getElementById('popupImage').style.display = 'block';
		}
	}
	xmlhttp.send(null);
}
function showPopupDrawing(drawingID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=showPopupDrawing&drawingID=" + drawingID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			document.getElementById('popupBkg').style.display = 'block';
			document.getElementById('popupImage').style.display = 'block';
		}
	}
	xmlhttp.send(null);
}

function showPopupCommission(commissionID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=showPopupCommission&commissionID=" + commissionID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			document.getElementById('popupBkg').style.display = 'block';
			document.getElementById('popupImage').style.display = 'block';
		}
	}
	xmlhttp.send(null);
}

function hidePopup(){
	document.getElementById('popupBkg').style.display = 'none';
	document.getElementById('popupImage').style.display = 'none';
}

function openNew(page, width, length){
	window.open (page,'info','width='+width+',height='+length+',resizable=yes,scrollbars=yes');
}

function showBookSlideshow(bookID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=showBookSlideshow&bookID=" + bookID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			document.getElementById('popupBkg').style.display = 'block';
			document.getElementById('popupImage').style.display = 'block';
		}
	}
	xmlhttp.send(null);
}

function getSlide(slide){
	if(slide != 1){
		numberSlides = document.getElementById('numberSlides').value; //alert(numberSlides);
		bookslideshowID = document.getElementById('bookslideshowID').value; //alert(bookslideshowID);
		xmlhttp.open("GET", "/ajaxHandler.php?object=getSlide&slide=" + slide + "&numberSlides=" + numberSlides + "&bookslideshowID=" + bookslideshowID);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				document.getElementById('slideContent').innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}else{
		bookID = document.getElementById('bookID').value;
		showBookSlideshow(bookID);
	}
}

function showBookSlideshowCommission(commissionID){
	xmlhttp.open("GET", "/ajaxHandler.php?object=showBookSlideshowCommission&commissionID=" + commissionID);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			document.getElementById('popupBkg').style.display = 'block';
			document.getElementById('popupImage').style.display = 'block';
		}
	}
	xmlhttp.send(null);
}

function getSlideCommission(slide){
	if(slide != 1){
		numberSlides = document.getElementById('numberSlides').value; //alert(numberSlides);
		commissionID = document.getElementById('commissionID').value; //alert(bookslideshowID);
		xmlhttp.open("GET", "/ajaxHandler.php?object=getSlideCommission&slide=" + slide + "&numberSlides=" + numberSlides + "&commissionID=" + commissionID);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				document.getElementById('imageArea').innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}else{
		commissionID = document.getElementById('commissionID').value;
		showBookSlideshowCommission(commissionID);
	}
}

function showBookSlideshowOP(ID){
	if(ID == 21){
		type = 'prints';
	}else{
		type = 'originals';
	}
	xmlhttp.open("GET", "/ajaxHandler.php?object=showBookSlideshowOP&ID=" + ID + "&type=" + type);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById('popupImage').innerHTML = xmlhttp.responseText; //alert(photoElementsString);
			document.getElementById('popupBkg').style.display = 'block';
			document.getElementById('popupImage').style.display = 'block';
		}
	}
	xmlhttp.send(null);
}

function getSlideOP(slide){
	ID = document.getElementById('slideID').value;
	if(ID == 21){
		type = 'prints';
	}else{
		type = 'originals';
	}
	if(slide != 1){
		numberSlides = document.getElementById('numberSlides').value; //alert(numberSlides);
		xmlhttp.open("GET", "/ajaxHandler.php?object=getSlideOP&slide=" + slide + "&numberSlides=" + numberSlides + "&ID=" + ID + "&type=" + type);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				document.getElementById('slideDiv').innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}else{
		showBookSlideshowOP(ID);
	}
}

function shipping(){
	window.open ('shippingpop.htm','definitions','width=520,height=450,resizable=yes,scrollbars=yes');
}

function emailFriend(printID){
	window.open ('/emailFriend.php?printID=' + printID, 'emailFriend' ,'width=685,height=500,resizable=yes,scrollbars=yes');
}

function showMore(){
	document.getElementById('moreFrame').style.display = 'block';
}

function hideMore(){
	document.getElementById('moreFrame').style.display = 'none';
}

function showExampleRemarque(div){
	document.getElementById('remarqueBookDefault').style.display = 'none';
	document.getElementById('example1').style.display = 'none';
	document.getElementById('example2').style.display = 'none';
	document.getElementById('example3').style.display = 'none';
	document.getElementById('example4').style.display = 'none';
	
	document.getElementById(div).style.display = 'block';
}

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
}	

function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
}

function paginationFadeInOut(){
	$(".newPagination").find("a").click( function () {
		$(".newPagination").find("a").css("text-decoration","none");
		$(this).css("text-decoration","underline");
		$(this).blur();
		var href = $(this).attr("href"); //alert(href);
		
		$(currentDiv).fadeOut("medium", function(){
			$(href).fadeIn('medium');
			currentDiv = href;
		})																				 
 });
}

// starting the script on page load
$(document).ready(function(){
	paginationFadeInOut();
});









