function showRyMacBox(id) {     
    var thisEle = $("#" + id).get(0);
    if (thisEle == null) return;
    
    var sidePos = 0;
    if ($("#product-page-container").get(0))
    {
        sidePos = ($("#product-page-container").offset().left) + ($("#product-page-container").width() / 2) - ($(thisEle).width() / 2);
    }
    else
    {
        sidePos = (($(window).width() / 2) - ($(thisEle).width() / 2));
    }
    if (sidePos < 0) sidePos = 0;
    sidePos += "px";
    $(thisEle).css("left", sidePos);
    
    var topPos = $(window).scrollTop() + ($(window).height() / 2) - ($(thisEle).height() / 2);
    if (topPos < 0) topPos = 0;
    topPos += "px";
    $(thisEle).css("top", topPos);
    
    $("#" + id).show();
}

function isdefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function hideRyMacBox(id) {
	$("#" + id).hide();
}

function RyMacBox(name, image, width, height, outputToEle, attributesObj, forceHeight) {

	// Required //
	//////////////

	this.image = image;
	this.image.isHtml = false;
	this.output = outputToEle;
	this.name = name;

	this.width = width;	// Width in pixels
	this.height = height;	// Height in pixels
	this.forceHeight = forceHeight;

	if (typeof(this.image) != "object") {
		var bits = this.image.split("|");

		if ((bits[0] == "swf")||(bits[0] == "SWF")) {
			var src = bits[1];
	
			this.image = {};
			this.image.src = src;
			this.image.isFlash = true;
		}
		else if ((bits[0] == "html")||(bits[0] == "HTML")) {
			var DATA = document.getElementById(bits[1]).innerHTML;
			
			this.image = {};
			this.image.object = document.getElementById(bits[1]);
			this.image.data = DATA;
			this.image.origEle = document.getElementById(bits[1]);
			this.image.isFlash = false;		
			this.image.isHtml = true;
		}
	}

	// Optional //
	//////////////

	this.oncloseFunc = "";
	this.onopenFunc = function() { };	
	
	this.caption = "";	// Caption

	// If extra attributes have been passed in
	if (typeof(attributesObj) == "object") {
		if (attributesObj.caption != undefined) {	this.caption = attributesObj.caption; }
		if (attributesObj.onclose != undefined) {	this.oncloseFunc = attributesObj.onclose; }
		if (attributesObj.onopen != undefined) {	this.onopenFunc = attributesObj.onopen; }		
	}

	var closedRef = this;
	setTimeout(function() { closedRef.init(); }, 500);
}

RyMacBox.prototype.init = function() {
    var closedRef = this;

	if ((isdefined("IsLoaded") == false)||(IsLoaded != 1)) {
		setTimeout(function() { closedRef.init(); }, 100);
		return;
	}

	var mbMainContainer = document.createElement("div");
	mbMainContainer.id = this.name;
	mbMainContainer.className = "macbox";
	mbMainContainer.style.width = this.width + 80 + "px";
		
		var mbTopLeft = document.createElement("div");
	    mbTopLeft.className = "macbox-top-left";
	    mbTopLeft.style.width = this.width + 40 + "px";
	    
	        var mbCloseLink = document.createElement("a");
	        mbCloseLink.className = "macbox-close";
		    mbCloseLink.innerHTML = "close";
		    mbCloseLink.href = "#";
		    var name = this.name;
		    mbCloseLink.onclick = function() {
		        hideRyMacBox(name); 
		        this.oncloseFunc;
		        return false;
            }
            
	    mbTopLeft.appendChild(mbCloseLink);
	    
	mbMainContainer.appendChild(mbTopLeft);
	    
	    var mbTopRight = document.createElement("div");
	    mbTopRight.className = "macbox-top-right";
	    
	mbMainContainer.appendChild(mbTopRight);
	        
        var mbMiddle = document.createElement("div");
        mbMiddle.className = "macbox-middle";
        mbMiddle.style.width = this.width + 80 + "px";
        
            var mbRight = document.createElement("div");
            mbRight.className = "macbox-right";
            mbRight.style.width = this.width + 40 + "px";
	        
	            var mbContent = document.createElement("div");
	            mbContent.className = "macbox-content";
	            mbContent.style.width = this.width + "px";
                if (this.image.isHtml) {
                    // Remove the original node
                    this.image.origEle.parentNode.removeChild(this.image.origEle);
                    //mbContent.innerHTML = this.image.data;
                    mbContent.appendChild(this.image.object);
                }
                else {
                    var mbImgContainer = document.createElement("div");
	                    var mbImg = document.createElement("img");
	                    mbImg.id = this.name + "_image";

	                    if (!this.image.isFlash) {
		                    mbImg.src = this.image.src;
		                    mbImg.alt = "";
	                    }
                    mbImgContainer.appendChild(mbImg);
		            mbContent.appendChild(mbImgContainer);

                    var mbCaption = document.createElement("div");
                    mbCaption.className = "macbox-caption";
		            mbCaption.innerHTML = this.caption;
		            mbContent.appendChild(mbCaption);
		        }
		    
		    mbRight.appendChild(mbContent);
		    
		mbMiddle.appendChild(mbRight);
			
    mbMainContainer.appendChild(mbMiddle);
			
		var mbBottomLeft = document.createElement("div");
		mbBottomLeft.className = "macbox-bottom-left";
		mbBottomLeft.style.width = this.width + 40 + "px";
	
	mbMainContainer.appendChild(mbBottomLeft);
		
		var mbBottomRight = document.createElement("div");
		mbBottomRight.className = "macbox-bottom-right";
		
	mbMainContainer.appendChild(mbBottomRight);
	
	$(mbMainContainer).hide();

	var closedRef = this;
	setTimeout(function() { closedRef.output.appendChild(mbMainContainer); }, 0);
	
	if (this.image.isFlash) {
		swfobject.embedSWF("images/test.swf", this.name + "_image", this.width, this.height, "9.0.0");  
	}
}