$(function() {
	$('#productDetailContainer').hide();
	});

var prev;
var next;
var curr;

// Calculates the object's absolute position, and width and height
function GetAbsPosition(object) {
	var position = new Object;
	position.x = 0;
	position.y = 0;

	if( object ) {
		position.x = object.offsetLeft;
		position.y = object.offsetTop;

		if( object.offsetParent ) {
			var parentpos = GetAbsPosition(object.offsetParent);
			position.x += parentpos.x;
			position.y += parentpos.y;
			}
		}

	position.cx = object.offsetWidth;
	position.cy = object.offsetHeight;
	return position;
	}


function getDetail(item, row) {
	thisPhoto = $('#itemPhoto'+item).html();
	thisTitle = $('#itemTitle'+item).html();
	thisContent = $('#itemContent'+item).html();
	//thisContent = thisContent.replace("\n","<br />");
	$("#productDetailPhoto").html("<img src=\"/products/images/_large/" 
+ thisPhoto + "\" border=\"0\" alt=\"" + thisTitle + "\" />");
	$("#productDetailInfo").html("<h3>" + thisTitle + "</h3>");
	if(thisContent != "") {
		$("#productDetailInfo").append("<p>" + thisContent + "</p>");
		}

	// Position the pop-up based on the row
	if(row) {
		var offset = 250 + (row*150);
		$("#productDetailContainer").css("top",offset+"px");
		}

	showDetail();
	curr = parseInt(item);
	next = curr+1;
	if(next > (count-1)) {
		next = 0;
		}
	
	prev = curr-1;
	if(prev < 0) {
		prev = count-1;
		}
	}

var pdrag;

function showDetail() {
	$("#productDetailContainer").fadeIn();
	$("#productDetailContainer").draggable();
	}

function hideDetail() {
	$("#productDetailContainer").fadeOut();	
	}