function openBox(theprodID) {
if (theprodID != "") {displayPopup(theprodID);}
}



function displayPopup(prodID) {
	$('#popup').html($('.loading').html());
	$('#cinzaBox').show();

  $.get(loadUrl, {action: "ajax_product", prodID: prodID, nothing: now},  
    	   function(responseText){  
			$('#popup').html(responseText);
			resize('mainimage', '300', '');
			$('#zoomit').loupe();
			$('#popup').center();
			getnext(prodID);
	       },  
       "html"  
      );           

			document.body.style.overflow='hidden';

			$('#popup').show();
			$('#popup').center();
	
	

}

function openSuggestBox(theprodID) {
	if (theprodID != "") {displaySuggestPopup(theprodID);}
}

function displaySuggestPopup(prodID) {
  $.get(loadUrl, {action: "ajax_suggestproducts", prodID: prodID, cartID: theid, nothing: now},  
    	   function(responseText){
			if (responseText == "nosuggest") {suggesting = "";} 
			else {  
				suggesting = "true";
				$('#cinzaBox').show();
				$('#popup').html(responseText);
				$('#popup').center();
				$('#popup').show();
				$('#popup').center();
				document.body.style.overflow='hidden';

			}
	       },  
       "html"  
      );           

		if (suggesting == "true") {
				$('#popup').show();
				$('#popup').center();
				document.body.style.overflow='hidden';
		}
	

}

jQuery.fn.closeBox = function(init)
{
		$('#cinzaBox').hide();
	
	document.body.style.overflow='auto';
	$('#popup').hide();
}




jQuery.fn.center = function(init) {
		
	var object = $('#popup');

	if(!init) {
		object.css('margin-top', $(window).height() / 2 - this.height() / 2);
		object.css('margin-left', $(window).width() / 2 - this.width() / 2);
			
		$(window).resize(function() {
			object.center(!init);
		});
		
	} else {
	
		var marginTop = $(window).height() / 2 - this.height() / 2;
		var marginLeft = $(window).width() / 2 - this.width() / 2;
			
		marginTop = (marginTop < 0) ? 0 : marginTop;
		marginLeft = (marginLeft < 0) ? 0 : marginLeft;

		object.stop();
		object.animate(
			{
				marginTop: marginTop, 
				marginLeft: marginLeft
			}, 
			150, 
			'linear'
		);
		
	}
}

function getnext(prodID) {
	for (var i=0; i<prodids.length; i++) {
		if (prodids[i] == prodID) {
		var y = i + 1;
		var next = prodids[y];
		var y = y - 2
		var prev = prodids[y];
		}
	}

	if (next != undefined) {
		$('.nextproduct').attr('id', next);
	}
	if (prev != undefined) {
		$('.prevproduct').attr('id', prev);
	}

}










