

function getSelectedOptionId(){
   if(document.images) {
      var which = document.productForm;

      for(i=0;i<which.length;i++) {
         var tempobj=which.elements[i];
         if(tempobj.name.substring(0,7)=='options' || tempobj.name.substring(0,16)=='checkbox_options') {
            var fieldType = tempobj.type;
            if(fieldType=='select-one'){
               if(tempobj.selectedIndex > -1){
                  //var myval = tempobj[tempobj.selectedIndex].value;
                  var myval = tempobj.selectedIndex;
               	  return myval;
               }

            } else {
				//ignore
            }
         }
      }
   }
}


function getChildOptionElement(){
   if(document.images) {
      var which = document.productForm;

      for(i=0;i<which.length;i++) {
         var tempobj=which.elements[i];
         if(tempobj.name.substring(0,10)=='options[2]') {
            return tempobj;           
         }
      }
   }
}

function updatePrice(){
   var which = document.productForm;
   var myoptions = getSelectedOptions();
   var productId = which.productID.value;
   var extraField = '';
   
   if(which.extraField){
       var extraField = which.extraField.value;
   }

   x_getLiveProductTotal(myoptions, productId, extraField, '1', totalHandler);
}

function totalHandler(response){
   if(response){
   		document.getElementById('price').innerHTML = response;
   }
}

function getSelectedOptions(){
   var myoptions = '';

   if(document.images) {
      var which = document.productForm;

      for(i=0;i<which.length;i++) {
         var tempobj=which.elements[i];
         if(tempobj.name.substring(0,7)=='options' || tempobj.name.substring(0,16)=='checkbox_options') {
            var fieldType = tempobj.type;
            if(fieldType=='select-one'){
               if(tempobj.selectedIndex > -1){
                  var myval = tempobj[tempobj.selectedIndex].value;
               	  myoptions += ',' + myval;
               }

            } else if(fieldType=='radio' || fieldType=='checkbox'){
               if(tempobj.checked){
                  var myval = tempobj.value;
                  myoptions += ',' + myval;
               }

            } else {
		//ignore 
            }
         }
      }
   }

   return myoptions;
}

$(document).ready( function (){
	
	$(".zoom").click( function(){
		
		
		var img = $(this).parent().find('div.imgholder');
		var imgzoom = $(this).parent().find('div.imgholder_zoom');

		if($(img).css('display') == 'block'){
			$(img).css('display', 'none');
			$(imgzoom).css('display', 'block');
			$(this).html('Zoom -');
		}else{
			$(img).css('display', 'block');
			$(imgzoom).css('display', 'none');
			$(this).html('Zoom +');
		}

	});

	$(".imgholder_zoom").mousemove( function(e){
		//position of the mouse inside the element
		var x = e.pageX - $(this).position().left;
		var y = e.pageY - $(this).position().top;

		//percentage of the mouse to the element
		var pw = (x / $(this).width()) * 100;
		var ph = (y / $(this).height()) * 100;

		//width and heigh of the image
		var img = $(this).find('img');
		var iw = $(img).width();
		var ih = $(img).height();

		//get the overflow of the image
		var ow = iw - $(this).width();
		var oh = ih - $(this).height();

		var movew = (ow / 100) * pw;
		var moveh = (oh / 100) * ph;

		$(img).css({
			'left' : '-'+Math.floor(movew)+'px',
			'top'  : '-'+Math.floor(moveh)+'px',
			position : 'absolute'
		});
	});

});
