$(document).ready(function(){
	
	/**************************
	Alternate Photos of Jewelry
	***************************/
	$("#altPhotos a").live("click",function(){
		// Find out if this is QuickLook
		var QL = ($(this).parent().attr("class")=="QL") ? true : false;
		if(QL){var prodPhotoImg = "prodPhotoImgQL";var prodPhotoControls = "prodPhotoControlsQL";}
		else {var prodPhotoImg = "prodPhotoImg";var prodPhotoControls = "prodPhotoControls";}
		// Get random number issued to flash player and controller
		var date = new Date();
		var rand = date.getTime();
		//var rand = $("#"+prodPhotoImg+" object#zoomimg param[name='flashvars']").attr("value");
		//rand = rand.substring(rand.indexOf("id_")+3,rand.indexOf("&"));
		// Get src of new photo to be displayed
		var newSRC = $(this).attr("href");
		var newIMG = newSRC.substring(newSRC.lastIndexOf("/")+1);
		// Is this a Zoom image or not?
		var isZoom = ($(this).attr("rel")=="zoom") ? true : false;
		// Set height of container div, to make sure it doesn't collapse
		$("#"+prodPhotoImg).css("height",299);
		
		// Is Flash using OBJECT or EMBED?
		/*var html = $("#"+prodPhotoImg).html();
		if(html.indexOf("object")!=-1){
			
		}*/
		
		if(isZoom){
			// Fade out flash and replace with new flash photo
			$("#"+prodPhotoImg+" object, #"+prodPhotoImg+" embed, #"+prodPhotoImg+" img").fadeOut(400,function(){
			   $("#"+prodPhotoImg).html("")
				var FO = { movie:"zooming.swf", width:"393", height:"296", majorversion:"6", build:"0", id:"zoomimg", wmode:"opaque", allowScriptAccess:"sameDomain", flashvars:"movieID=id_"+rand+"&imgSource=shopimages/"+newIMG+"&QuickLook="+QL};
				//$("#"+prodPhotoImg).hide();
				UFO.create(FO, prodPhotoImg);
				//$("#"+prodPhotoImg).fadeIn(1000);
			});
			// Reinitiate/reload flash controls
			//var controls = $("#"+prodPhotoControls).html();
			//$("#"+prodPhotoControls).html(controls);
			var FO = { movie:"zoomnav.swf", width:"170", height:"50", majorversion:"6", build:"0", id:"zoomnav3", wmode:"opaque", allowScriptAccess:"sameDomain", flashvars:"movieID=id_"+rand+"&QuickLook="+QL };
			UFO.create(FO, prodPhotoControls);
		} else {
			$("#"+prodPhotoImg+" object, #"+prodPhotoImg+" embed, #"+prodPhotoImg+" img").fadeOut(400,function(){
				$("#"+prodPhotoImg).html('<img src="'+ newSRC +'" alt="" width="393" height="296" border="0" />');
				$("#"+prodPhotoControls).html('');
			});
		}
		
		// Change active state on thumbnails
		$("#altPhotos a").removeClass("active");
		$(this).addClass("active");
		
		return false;
	});
	
	
});


// Prep the emailForm email field for signing up for Emails
var emailCleared = 0;
function prepareEmailForm(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm")) return false;
	var el = document.getElementById("email");
	el.onfocus = function(){
		if(emailCleared==0)	{
			el.value = "";
			emailCleared = 1;
		}
	}
	el.onblur = function(){
		if(el.value == "") {
			el.value = "Email";
			emailCleared = 0;
		}
	}
}
addLoadEvent(prepareEmailForm);
var email2Cleared = 0;
function prepareEmail2Form(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm2")) return false;
	var el = document.getElementById("email2");
	el.onfocus = function(){
		if(email2Cleared==0) {
			el.value = "";
			email2Cleared = 1;
		}
	}
	el.onblur = function(){
		if(el.value == "") {
			el.value = "Email";
			email2Cleared = 0;
		}
	}
}
addLoadEvent(prepareEmail2Form);

function prepareEmailSubmit(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm")) return false;
	var el = document.getElementById("emailSubmit");
	el.onclick = function(){
		document.getElementById("emailForm").submit();
		return false;
	}
}
addLoadEvent(prepareEmailSubmit);

function prepareEmail2Submit(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("emailForm2")) return false;
	var el = document.getElementById("email2Submit");
	el.onclick = function(){
		document.getElementById("emailForm2").submit();
		return false;
	}
}
addLoadEvent(prepareEmail2Submit);

//Submit order on checkout
function submitOrder() {
	if (!document.getElementById) return false;
	if (!document.getElementById("submitLinkWrapper")) return false;
	if (!document.getElementById("submitLink")) return false;
	var link=document.getElementById("submitLink");
	link.onclick=function(){
		document.getElementById("submitLinkWrapper").innerHTML="<span>Processing Order...</span>";
		document.shop3.submit();
	}
}
addLoadEvent(submitOrder);


// Clear the Search field
var searchCleared = 0;
function prepareSearchForm(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("searchForm")) return false;
	var el = document.getElementById("search");
	el.onfocus = function(){
		if(searchCleared==0)	el.value = "";
		searchCleared = 1;
	}
	el.onblur = function(){
		if(el.value == "") el.value = "Search";
		searchCleared = 0;
	}
}
addLoadEvent(prepareSearchForm);

// Adds functions to onload event
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Setup Enter/Return to trigger function in Shop's pagination
function shopPagination(){
	if (!document.getElementsByTagName) return false;
	var el = document.getElementsByTagName("input");
	for(i=0; i<el.length; i++){
		if(el[i].className == "pageOf"){
			el[i].onkeypress = function(e){
				var evt = (e) ? e : window.event;
				if(evt.keyCode==13){
					jumpToPage(this.name)
				}
			}
		}
	}
}
addLoadEvent(shopPagination);










// !!!!!!!!! DISABLED AND REPLACED WITH LIGHTBOX 2 !!!!!!!!!!!!!!!
// Preps the photos on Scene@23 section for launching popup window
/*function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  var gallery = document.getElementById("imagegallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
    links[i].onkeypress = links[i].onclick;
  }
}
//addLoadEvent(prepareGallery);
// Launches largeImage page for Scene@23 section
function showPic(whichpic) {
  var source = whichpic.getAttribute("href");
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  window.open('joannesEye_gallery_largeImage.cfm?img='+source+'&title='+text,'sceneAt','width=670,height=630,location=0,toolbars=0')
  return false;
}*/
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

