function RyLightbox(thisObject, name, outputTo, links, linksHeight, media, thumbLinks, thumbSize) {
    
	this.outputEle = outputTo;

    this.thisObject = thisObject; //for use if this object has to be referred to from outside this page
	this.name = name;

	this.links = links;
	this.linksHeight = (linksHeight > 0) ? linksHeight : 0;
	this.thumbLinks = thumbLinks;
	this.thumbLinks.arrowWidth = 20;
	this.thumbSize = (thumbSize > 0) ? thumbSize : 1;
	this.media = media;
	
	this.padding = 5; //to use for spacing between elements

	this.currentNumber = 0;
	this.currentMedia = this.media[this.currentNumber];

	this.currentImageEle = new Image();

	this.ele = null;
	this.thumbsEle = null;
	this.thumbsEleMiddle = null;
	this.imageField = null;
	this.overlay = null;
	this.linksEle = null;
	this.prevArrow = null;
	this.nextArrow = null;
	this.caption = null;
	this.captionHeight = null;

	this.resizeTime = 270;

	this.init();
}

function isdefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

RyLightbox.prototype.showRyLightbox = function() {
	this.calculatePosition();
	
	this.showOverlay();
	
	hideFlash(true);
}

function hideFlash(hide)
{
	var displayMode = "";
	if (hide) displayMode = "none";
	else displayMode = "block";
	var eles = document.getElementsByTagName("embed");
	if (eles.length > 0)
	{
		for (var idx = 0, len = eles.length; idx < len; idx++)
		{
			eles[idx].style.display = displayMode;
		}
	}
}

RyLightbox.prototype.resizeToWidth = function() {

	var diff = -(parseInt(this.imageField.style.width) - this.currentMedia.width);
	var minus = false;

	if (diff < 0) {
		minus = true;
		var timePeriod = this.resizeTime / -diff;

		for (var idx = 0, len = -diff; idx < len; idx++) {
			this.resizeToWidthHelper(idx, minus, (idx * timePeriod));
		}
	}
	else {
		var timePeriod = this.resizeTime / diff;

		for (var idx = 0, len = diff; idx < len; idx++) {
			this.resizeToWidthHelper(idx, minus, (idx * timePeriod));
		}
	}

	var closedRef = this;
	setTimeout(function() { closedRef.checkIfImageLoaded() }, this.resizeTime);
	setTimeout(function() { closedRef.growBottomLinksAfterWait() }, this.resizeTime * 2);
}

RyLightbox.prototype.resizeToWidthHelper = function(idx, minus, time) {
	var closedRef = this;

	if (minus == false) {
		setTimeout(function() {
			closedRef.ele.style.width = (parseInt(closedRef.ele.style.width) + 1) + "px";
			closedRef.imageField.style.width = (parseInt(closedRef.imageField.style.width) + 1) + "px";
			closedRef.calculatePositionMovingLeft();
		}, time);
	}
	else {
		setTimeout(function() {
			closedRef.ele.style.width = (parseInt(closedRef.ele.style.width) - 1) + "px";
			closedRef.imageField.style.width = (parseInt(closedRef.imageField.style.width) - 1) + "px";
			closedRef.calculatePositionMovingLeft();
		}, time);
	}
}

RyLightbox.prototype.resizeToHeight = function(period) {
	var diff = -(parseInt(this.imageField.offsetHeight) - this.currentMedia.height);
	var minus = false;

	if (diff < 0) {
		diff = -diff;
		minus = true;
	}

	var timePeriod = 0;

	if (period > 0)	timePeriod = period;
	else 		timePeriod = this.resizeTime / diff;

	for (var idx = 0, len = diff; idx < len; idx++) {
		this.resizeToHeightHelper(idx, minus, (idx * timePeriod));
	}

	var closedRef = this;
	setTimeout(function() { closedRef.resizeToWidth() }, (len * timePeriod));
}


RyLightbox.prototype.resizeToHeightInludingLinksShrink = function() {
	var period = this.resizeTime / 40;
	//var period = this.resizeTime / bottom-link-size;
	var closedRef = this;

	for (var idx = 1, len = 40; idx <= len; idx++) {
		this.growBottomLinksAfterWaitHelper(idx, period * idx, true);
	}

	setTimeout(function() { closedRef.resizeToHeight(period); }, this.resizeTime);

}

RyLightbox.prototype.resizeToHeightHelper = function(idx, minus, time) {
	var closedRef = this;

	if (minus == false) {
		setTimeout(function() {
			closedRef.ele.style.height = (parseInt(closedRef.ele.style.height) + 1) + "50px";
			closedRef.imageField.style.height = (parseInt(closedRef.imageField.style.height) + 1) + "px";
			closedRef.calculatePositionMovingTop();
		}, time);
	}
	else {
		setTimeout(function() {
			if (parseInt(closedRef.ele.style.height) > 0) {
				closedRef.ele.style.height = (parseInt(closedRef.ele.style.height) - 1) + "px";
				closedRef.imageField.style.height = (parseInt(closedRef.imageField.style.height) - 1) + "px";
				closedRef.calculatePositionMovingTop();
			}
			else {
//				alert( parseInt(closedRef.ele.style.height) );
			}
		}, time);
	}
}

RyLightbox.prototype.opacity = function(opacStart, opacEnd, millisec) { 
	//speed for each frame 
	var speed = Math.round(millisec / 100); 
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens 
	if (opacStart > opacEnd) {
		for (var i = opacStart; i >= opacEnd; i -= 3) {
			this.opacityHelper(i, this.overlay, timer, speed);
			timer++;
		}
	}

	else if (opacStart < opacEnd) {
		for (var i = opacStart; i <= opacEnd; i += 3) {
			this.opacityHelper(i, this.overlay, timer, speed);
			timer++;
		}
	}
}

RyLightbox.prototype.checkIfImageLoaded = function() {

	if (this.currentImageEle.complete) {
		this.imageField.style.visibility = "visible";
		return;
	}

	var closedRef = this;
	setTimeout(function() { closedRef.checkIfImageLoaded(); }, 50);
}

RyLightbox.prototype.opacityHelper = function(i, ele, timer, speed) {
	var closedRef = this;

	setTimeout(function() { closedRef.changeOpac(i, ele) }, (timer * speed)); 
}

RyLightbox.prototype.hidePrevArrow = function() {
	this.prevArrow.style.display = "none";
}

RyLightbox.prototype.hideNextArrow = function() {
	this.nextArrow.style.display = "none";
}

RyLightbox.prototype.showPrevArrow = function() {
	this.prevArrow.style.display = "block";
}

RyLightbox.prototype.showNextArrow = function() {
	this.nextArrow.style.display = "block";
}

//change the opacity for different browsers 
RyLightbox.prototype.changeOpac = function(opacity, ele) { 
	 var object = ele.style;
 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")"; 
}

RyLightbox.prototype.growBottomLinks = function() {
	var closedRef = this;
	
	if (this.linksEle != null) {
        this.linksEle.style.height = "1px";
        setTimeout(function() { closedRef.growBottomLinksAfterWait(); }, this.resizeTime); 	
	}
}

RyLightbox.prototype.hideBottomLinks = function() {
	var period = Math.round(this.resizeTime / 40);
	var closedRef = this;

	for (var idx = 1, len = 40; idx <= len; idx++) {
		this.growBottomLinksAfterWaitHelper(idx, period * idx, true);
	}	
}

RyLightbox.prototype.growBottomLinksAfterWait = function() {
    var heightCounter = this.thumbSize;

	var period = Math.round(this.resizeTime / heightCounter);
	var closedRef = this;

	for (var idx = 1, len = heightCounter; idx <= len; idx++) {
		this.growBottomLinksAfterWaitHelper(idx, period * idx);
	}
}

RyLightbox.prototype.makeOverlayCorrectSize = function() {
	var docHeight = this.docHeight();

	if ((this.ele.offsetHeight + 100) > this.docHeight()) {
		document.getElementById('overlayDiv').style.height = (this.ele.offsetHeight + 100) + "px";
	}
	else {
		document.getElementById('overlayDiv').style.height = docHeight + "px";
	}
}

RyLightbox.prototype.changeLinksHeight = function(idx, minus) {
	if (minus)	this.ele.style.height = (parseInt(this.ele.style.height) - 1) + "px";
	else		this.ele.style.height = (parseInt(this.ele.style.height) + 1) + "px";

    if (this.linksEle != null) this.linksEle.style.height = idx + "px";
	this.makeOverlayCorrectSize();
}

RyLightbox.prototype.growBottomLinksAfterWaitHelper = function(i, wait, minus) {
	var closedRef = this;

	setTimeout(function() { closedRef.changeLinksHeight(i, minus) }, wait); 
}

RyLightbox.prototype.calculatePositionMovingLeft = function() {
	this.ele.style.left = this.scrolledLeft() + Math.floor(this.BrowserWidth() / 2) - Math.ceil((parseInt(this.ele.style.width) + 10) / 2) + "px";
}

RyLightbox.prototype.calculatePositionMovingTop = function() {
	var suggestedPosition = this.scrolledTop() + Math.floor(this.BrowserHeight() / 2) - Math.ceil((parseInt(this.ele.style.height) + 60) / 2);

	if (suggestedPosition > 0) {
		this.ele.style.top = this.scrolledTop() + Math.floor(this.BrowserHeight() / 2) - Math.ceil((parseInt(this.ele.style.height) + 60) / 2) + "px";
	}
	else {
		this.ele.style.top = "10px";
	}
	
	this.makeOverlayCorrectSize();
}

RyLightbox.prototype.calculatePosition = function() {

    this.ele.style.left = this.scrolledLeft() + Math.floor(this.BrowserWidth() / 2) - ((this.ele.style.width.split('p')[0]) / 2) + "px";
    
	var suggestedTopPosition = this.scrolledTop() + Math.floor(this.BrowserHeight() / 2) - Math.ceil((parseInt(this.ele.style.height) + 60) / 2);
	if (suggestedTopPosition > 0) {
		//this.ele.style.top = this.scrolledTop() + Math.floor(this.BrowserHeight() / 2) - ((this.currentMedia.height + 60) / 2) + "px";
		this.ele.style.top = "10px"; //THIS LINE IS TEMPORARY WHILE THE LIGHTBOX IS STILL AT THE TOP OF THE SCREEN
	}
	else {
		this.ele.style.top = "10px";
	}
	
	this.makeOverlayCorrectSize();	
}

RyLightbox.prototype.hideRyMacBox = function() {
	this.ele.className = "rylightbox-container rylightbox-container-hidden";

	this.hideOverlay();
	
	hideFlash(false);
}

RyLightbox.prototype.showOverlay = function(dontGrow) {
	this.opacity(0, 90, 500);
	this.overlay.style.filter = "alpha(opacity=0);";
	this.overlay.className = "rylightbox-overlay";
	this.overlay.style.filter = "alpha(opacity=0);";

	this.growBottomLinks(500);

	var closedRef = this;
	setTimeout(function() { closedRef.ele.className = "rylightbox-container"; }, 500);
}

RyLightbox.prototype.hideOverlay = function() {
	var closedRef = this;	
	this.opacity(90, 0, 500);
	
	setTimeout(function() { closedRef.overlay.className = "rylightbox-overlay rylightbox-container-hidden"; }, 500);
}

RyLightbox.prototype.makeAreaFlash = function() {
	var flashvars = {};
	var params = { wmode: "transparent" };
	var attributes = {};

	var preHeight = parseInt(this.imageField.style.height);
	var preWidth = parseInt(this.imageField.style.width);

	swfobject.embedSWF(this.currentMedia.src, this.name + "_image_internal", this.currentMedia.width, this.currentMedia.height, "9.0.0", this.currentMedia.src, flashvars, params, attributes);

	this.imageField = document.getElementById(this.name + "_image_internal");

	this.imageField.style.height = preHeight + "px";
	this.imageField.style.width = preWidth + "px";

	this.imageField.style.visibility = "hidden";
}

RyLightbox.prototype.makeAreaImage = function() {
	document.getElementById(this.name + "_image_internal").removeNode(true);
	var closedRef = this;

	var preHeight = parseInt(this.imageField.style.height);
	var preWidth = parseInt(this.imageField.style.width);

	this.currentImageEle.src = this.currentMedia.src;
	
	var rylightboxImage = document.createElement("img");
	rylightboxImage.alt = "";
	rylightboxImage.src = this.currentImageEle.src;

	rylightboxImage.style.width = preWidth + "px";
	rylightboxImage.style.height = preHeight + "px";

	rylightboxImage.id = this.name + "_image_internal";
	rylightboxImage.style.visibility = "hidden";

	this.imageField = rylightboxImage;
	if (document.getElementById(this.name + "_image") != null)
	{
	    document.getElementById(this.name + "_image").appendChild(rylightboxImage);
	}
}

RyLightbox.prototype.changeMediaBack = function() {
	var originalType = this.currentMedia.type;
	var originalEleHeight = parseInt(this.ele.offsetHeight) - 10;

	if ((this.currentNumber - 1) >= 0) {
		this.currentNumber--;
	}

	this.currentMedia = this.media[this.currentNumber];

	// If the media type hasn't changed
	if (this.currentMedia.type == originalType) {
		this.imageField.src = this.currentMedia.src;	
	}
	else if ((originalType == "image")&&(this.currentMedia.type == "swf")) {
		this.makeAreaFlash();
	}

	else if ((originalType == "swf")&&(this.currentMedia.type == "image")) {
		this.makeAreaImage();
	}

	this.ele.style.height = originalEleHeight + "px";
}

RyLightbox.prototype.changeMediaForward = function() {
	var originalType = this.currentMedia.type;
	var originalEleHeight = parseInt(this.ele.offsetHeight) - 10;

	if ((this.currentNumber + 1) <  this.media.length) {
		this.currentNumber++;
	}

	this.currentMedia = this.media[this.currentNumber];


	// If the media type hasn't changed
	if (this.currentMedia.type == originalType) {
		this.imageField.src = this.currentMedia.src;
	}
	else if ((originalType == "image")&&(this.currentMedia.type == "swf")) {
		this.makeAreaFlash();
	}

	else if ((originalType == "swf")&&(this.currentMedia.type == "image")) {
		alert("Used to be an swf! Now its IMAGE!");
	}

	this.ele.style.height = originalEleHeight + "px";
}

RyLightbox.prototype.prevImage = function() {
	this.imageField.style.visibility = "hidden"; //need to get this loading thing working

	this.changeMediaBack();
	this.currentImageEle.src = this.currentMedia.src;

	//this.resizeToHeightInludingLinksShrink();
	this.resizeWindowFull(this.currentNumber);

	this.showNextArrow();

	if ((this.currentNumber - 1) < 0) {
		this.hidePrevArrow();
	}
	
	//update caption
	if (document.getElementById(this.name + "_caption") != null)
	{
	    document.getElementById(this.name + "_caption").innerHTML = this.media[this.currentNumber].caption;
	}
}

RyLightbox.prototype.nextImage = function() {
	this.imageField.style.visibility = "hidden"; //need to get this loading thing working

	this.changeMediaForward();

	//this.resizeToHeightInludingLinksShrink();
	this.resizeWindowFull(this.currentNumber);

	this.showPrevArrow();

	if ((this.currentNumber + 1) == this.media.length) {
		this.hideNextArrow();
	}
	
	//update caption
	if (document.getElementById(this.name + "_caption") != null)
	{
	    document.getElementById(this.name + "_caption").innerHTML = this.media[this.currentNumber].caption;
	}
}

RyLightbox.prototype.resizeWindowFull = function(imgIdx) {
    this.tomsResizeToWidth(imgIdx);
    this.tomsResizeToHeight(imgIdx);
    this.tomsResizeThumbs(imgIdx);
    
    this.calculatePosition();
    
    var closedRef = this;
    setTimeout(function() { closedRef.checkIfImageLoaded() }, this.resizeTime);
}

RyLightbox.prototype.widthHelper = function(grow) {
    if (grow) {
        setTimeout(function() {
            this.imageField.style.width = this.imageField.style.width.split('p')[0] + 1;
            alert("growing");
        }, 20);
    }
    else {
        setTimeout(function() { 
            this.imageField.style.width = this.imageField.style.width.split('p')[0] - 1;
            alert("shrinking");
        }, 20);
    }
}

RyLightbox.prototype.tomsResizeToWidth = function(imgIdx) {

    //resize the image field to take the correct sized image
    var targetImageWidth = this.media[imgIdx].width;
    this.imageField.style.width = targetImageWidth;
    
    /*
    if (targetImageWidth > this.imageField.style.width.split('p')[0]) {
        //while (this.imageField.style.width.split('p')[0] < targetImageWidth) {
            //this.imageField.style.width = this.imageField.style.width.split('p')[0] + 1;
            this.widthHelper(true);
            this.imageField.style.width = targetImageWidth;
        //}
    }
    else {
        while (this.imageField.style.width.split('p')[0] > targetImageWidth) {
            this.imageField.style.width = targetImageWidth;
        }
    }
    this.imageField.style.width = targetImageWidth;
    */
    
    //set the width of the lightbox
    var targetContainerWidth = this.padding + this.media[imgIdx].width + this.padding;
    this.ele.style.width = targetContainerWidth;
}

RyLightbox.prototype.tomsResizeToHeight = function(imgIdx) {
    
    //resize the image field to take the correct sized image
    this.imageField.style.height = this.media[imgIdx].height;
    //set the height of the lightbox
    this.ele.style.height = this.padding + this.media[imgIdx].height + this.captionHeight + this.thumbSize + this.padding + this.linksHeight + this.padding + "px";
}

RyLightbox.prototype.tomsResizeThumbs = function(imgIdx) {

    //thumbs width needs resizing to stop its images wrapping
    this.thumbsEle.style.width = this.currentMedia.width + "px";
    this.thumbsEleMiddle.style.width = this.getThumbsInView() * (this.thumbSize + (this.padding*2)) + "px";
    this.thumbsEleMiddle.style.marginLeft = "auto";
    this.thumbsEleMiddle.style.marginRight = "auto";
    
    this.updateThumbs();
}

RyLightbox.prototype.showSpecificImage = function(imgIdx) {
    this.imageField.style.visibility = "hidden"; //
    
    //resize box to new img size
    this.resizeWindowFull(imgIdx);
    
    //set the image to show
    var imgSrc = this.media[imgIdx].src;
    this.imageField.src = imgSrc;
    
    this.currentNumber = imgIdx;
    
    if ((this.currentNumber + 1) == this.media.length) {
		this.hideNextArrow();
		this.showPrevArrow();
	}
	else if ((this.currentNumber - 1) < 0) {
		this.hidePrevArrow();
		this.showNextArrow();
	}
	else if ((this.currentNumber < this.media.length)&&(this.currentNumber > 0))
	{
	    this.showPrevArrow();
	    this.showNextArrow();
	}
	
	//update caption
	if (document.getElementById(this.name + "_caption") != null)
	{
	    document.getElementById(this.name + "_caption").innerHTML = this.media[this.currentNumber].caption;
	}
}

RyLightbox.prototype.thumbsGoLeft = function () {
    
    //need to know how many thumbs are in view
    var thumbsInView = this.getThumbsInView();
    
    //if not all thumbnails are in view
    if (thumbsInView <= this.thumbLinks.length)
    {
        var startEle = "";
        //some of the thumbnails will have display:none on them so work out what to do
        if (document.getElementById('thumbLink0').style.display == "none") {
            //can scroll left
            //find the first thumbLink that is display:inline
            for (var idx = 1, len = this.thumbLinks.length; idx < len; idx++) { //starts from 1 because we know that element 0 is display:none
                var curElement = "thumbLink" + idx;
                if (document.getElementById(curElement).style.display != "none") {
                    //we've found the start of the displayed thumbs
                    startEle = idx;
                    //alert(startEle);
                    break;
                }
            }
            //now use the start ele to do the update
            //we know where we start seeing the thumbs from, and we know how many are on screen, so simply switch 
            //all the display modes of the relevant thumbs
            var count = 0;
            for (var idx = startEle - 1, len = this.thumbLinks.length; idx < len; idx++) {
                //see if the idx == to the element before the first one in view
                var curElement = "thumbLink" + idx;
                if (count < thumbsInView) {
                    document.getElementById(curElement).style.display = "inline";
                }
                else {
                    //we've altered enough images so set the remaining ones to display none
                    document.getElementById(curElement).style.display = "none";
                }
                count++;
            }
        }
        //else can't move left as the first one is already on show
    }
}

RyLightbox.prototype.thumbsGoRight = function() {
    
    //need to know how many thumbs are in view
    var thumbsInView = this.getThumbsInView();
    
    //if not all thumbnails are in view
    if (thumbsInView <= this.thumbLinks.length)
    {
        var startEle = "";
        //some of the thumbnails will have display:none on them so work out what to do
        var lastEle = "thumbLink" + (this.thumbLinks.length - 1);
        if (document.getElementById(lastEle).style.display == "none") {
            //can scroll right
            //find the first thumbLink from the end that is display:inline
            for (var idx = this.thumbLinks.length - 2, len = 0; idx >= len; idx--) { //starts from the penultimate one because we know that the last element is display:none
                var curElement = "thumbLink" + idx;
                if (document.getElementById(curElement).style.display != "none") {
                    //we've found the start of the displayed thumbs (counting backwards)
                    startEle = idx;
                    //alert(startEle);
                    break;
                }
            }
            //now use the start ele to do the update
            //we know where we start seeing the thumbs from, and we know how many are on screen, so simply switch 
            //all the display modes of the relevant thumbs
            var count = 0;
            for (var idx = startEle + 1, len = 0; idx >= len; idx--) {
                //see if the idx == to the element before the first one in view
                var curElement = "thumbLink" + idx;
                if (count < thumbsInView) {
                    document.getElementById(curElement).style.display = "inline";
                }
                else {
                    //we've altered enough images so set the remaining ones to display none
                    document.getElementById(curElement).style.display = "none";
                }
                count++;
            }
        }
        //else can't move right as the last one is already on show
    }
}

RyLightbox.prototype.updateThumbs = function() {
    //sets the display mode for all thumbs so the ones out of view have display:none and the rest have display:inline
        
    var startEle = 0;
    //look for the first thumbnail that is displayed
    for (var idx = 0, len = this.thumbLinks.length; idx < len; idx++) {
        var curElement = "thumbLink" + idx;
        if (document.getElementById(curElement).style.display != "none") {
            //the element is displayed
            startEle = idx;
            break;
        }
    }
    
    //find out how many elements are on show
    var thumbsInView = this.getThumbsInView();
    var count = 0;
    //using the startEle as reference, set the rest of the elements' display properties
    for (var idx = startEle, len = this.thumbLinks.length; idx < len; idx++) {
        //all previous elements already have display:none, so set the correct number to display:inline, then the rest to display:none
        var curElement = "thumbLink" + idx; 
        if (count < thumbsInView) {
            document.getElementById(curElement).style.display = "inline";
        }
        else {
            document.getElementById(curElement).style.display = "none";
        }
        count++;
    }
    //check to see if count == thumbsInView... if not then there will be some images 
    //AT THE START that are hidden, so get these in reverse order
    if (count < thumbsInView) {
        for (var idx = startEle - 1, len = 0; idx >= len; idx--) {
            var curElement = "thumbLink" + idx; 
            if (count < thumbsInView) {
                document.getElementById(curElement).style.display = "inline";
            }
            else {
                document.getElementById(curElement).style.display = "none";
            }
            count++;
        }
    }
}

RyLightbox.prototype.getThumbsInView = function () {
    //returns the number of thumbnails that are currently in view
    var thumbsSectionWidth = this.currentMedia.width - (this.thumbLinks.arrowWidth * 2) - (this.padding * 4);
    var maxThumbsInView = (thumbsSectionWidth / (this.thumbSize + (this.padding * 2)));
    var thumbsInView = (maxThumbsInView > this.thumbLinks.length) ? this.thumbLinks.length : maxThumbsInView;
    thumbsInView = Math.floor(thumbsInView);
    
    return thumbsInView;
}

RyLightbox.prototype.init = function() {

    var closedRef = this;

	var rylightboxContainer = document.createElement("div");
	rylightboxContainer.className = "rylightbox-container rylightbox-container-hidden";
	rylightboxContainer.style.width = (this.currentMedia.width + 10) + "px";
	rylightboxContainer.style.height = (this.currentMedia.height + 10) + "px";
	rylightboxContainer.id = this.name;

		var rylightboxClose = document.createElement("a");
		rylightboxClose.className = "rylightbox-close";
		rylightboxClose.href = "#";
		rylightboxClose.onclick = function() { closedRef.hideRyMacBox(); };
		if (rylightboxClose != null)
		{
		    rylightboxClose.innerHTML = "Close";
		}
		if (rylightboxContainer != null)
		{
		    rylightboxContainer.appendChild(rylightboxClose);
		}

		var rylightboxArea = document.createElement("div");
		rylightboxArea.className = "rylightbox-swfImage";
		rylightboxArea.id = this.name + "_image";

			if (this.currentMedia.type != "swf") {
		
				this.currentImageEle.src = this.currentMedia.src;
				
				var rylightboxImage = document.createElement("img");
				rylightboxImage.alt = "";
				rylightboxImage.src = this.currentImageEle.src;
				rylightboxImage.id = this.name + "_image_internal";
				rylightboxImage.style.width = this.currentMedia.width + "px";
				rylightboxImage.style.height = this.currentMedia.height + "px";

				rylightboxImage.style.visibility = "hidden";

                if (rylightboxArea != null)
                {
				    rylightboxArea.appendChild(rylightboxImage);
				}
			}
			else {
		
				var rylightboxImage = document.createElement("object");
				rylightboxImage.id = this.name + "_image_internal";

                if (rylightboxArea != null)
                {
				    rylightboxArea.appendChild(rylightboxImage);
				}
			}

        if (rylightboxContainer != null)
        {
		    rylightboxContainer.appendChild(rylightboxArea);
		}
		
		//caption area
	    var rylightboxCaption = document.createElement("div");
	    rylightboxCaption.id = this.name + "_caption";
	    rylightboxCaption.className = "rylightbox-caption";
	    if (rylightboxCaption != null)
	    {
	        rylightboxCaption.innerHTML = this.media[this.currentNumber].caption;
	    }
	    this.caption = rylightboxCaption;
	    if (this.caption != null)
	    {
	        if (this.caption.innerHTML != "") 
	        {
	            this.captionHeight = 25;
	        }
	        else
	        {
	            this.caption.style.display = "none";
	            this.captionHeight = 0;
	        }
	    }
	    if (rylightboxContainer != null)
	    {
	        rylightboxContainer.appendChild(rylightboxCaption);
	    }
		
		//thumbnail links	
		if (this.thumbLinks.length > 0)
		{
		    var rylightboxThumbs = document.createElement("div");
		    
		        rylightboxThumbs.id = this.name + "_thumbs";
                rylightboxThumbs.className = "rylightbox-thumbs";
                rylightboxThumbs.style.height = this.thumbLinks[0].height + "px";
                rylightboxThumbs.style.width = this.currentMedia.width + "px";
                rylightboxThumbs.style.overflow = "hidden";
		    
		        var rylightboxThumbsLeftSection = document.createElement("div");
		        rylightboxThumbsLeftSection.className = "rylightbox-thumbs-left";
		        rylightboxThumbsLeftSection.style.width = this.thumbLinks.arrowWidth + "px";
		    
		            //create the 'left' thumbnail scroller arrow
		            var rylightboxThumbsLeft = document.createElement("div");
		            rylightboxThumbsLeft.style.width = this.thumbLinks.arrowWidth + "px";
		            rylightboxThumbsLeft.style.height = "30px";
		            rylightboxThumbsLeft.style.marginTop = "20px";
		            rylightboxThumbsLeft.style.border = "1px solid #aaa";
		            rylightboxThumbsLeft.style.fontWeight = "bold";
		            rylightboxThumbsLeft.style.lineHeight = "30px";
		            rylightboxThumbsLeft.style.color = "#aaa";
		            if (rylightboxThumbsLeft != null)
		            {
		                rylightboxThumbsLeft.innerHTML = "<a href=\"#\" onclick=\"" + this.thisObject + ".thumbsGoLeft(" + this.thumbLinks.arrowWidth + "); return false;\">&nbsp;&lt&nbsp;</a>";
		            }
		            if (rylightboxThumbsLeftSection != null)
		            {
		                rylightboxThumbsLeftSection.appendChild(rylightboxThumbsLeft);
		            }
		        
		        if (rylightboxThumbs != null)
		        {	            
		            rylightboxThumbs.appendChild(rylightboxThumbsLeftSection);
		        }
		        
		        var rylightboxThumbsRightSection = document.createElement("div");
		        rylightboxThumbsRightSection.className = "rylightbox-thumbs-right";
		        rylightboxThumbsRightSection.style.width = this.thumbLinks.arrowWidth + "px";
		    
    		        //create the 'right' thumbnail scroller arrow
    		        var rylightboxThumbsRight = document.createElement("div");
    		        rylightboxThumbsRight.style.width = this.thumbLinks.arrowWidth + "px";
    		        rylightboxThumbsRight.style.height = "30px";
    		        rylightboxThumbsRight.style.marginTop = "20px";
    		        rylightboxThumbsRight.style.border = "1px solid #aaa";
    		        rylightboxThumbsRight.style.fontWeight = "bold";
    		        rylightboxThumbsRight.style.lineHeight = "30px";
    		        rylightboxThumbsRight.style.color = "#aaa";
    		        if (rylightboxThumbsRight != null)
    		        {
    		            rylightboxThumbsRight.innerHTML = "<a href=\"#\" onclick=\"" + this.thisObject + ".thumbsGoRight(20); return false;\">&nbsp;&gt&nbsp;</a>";
    		        }
    		        if (rylightboxThumbsRightSection != null)
    		        {
		                rylightboxThumbsRightSection.appendChild(rylightboxThumbsRight);
		            }
		        
		        if (rylightboxThumbs != null)
		        {
		            rylightboxThumbs.appendChild(rylightboxThumbsRightSection);
		        }
		        
		        var rylightboxThumbsMiddleSection = document.createElement("div");
		    
		            //get the thumbnails
		            var thumbsString = "";
		            for (idx = 0, len = this.thumbLinks.length; idx < len; idx++)
		            {
		                thumbsString += "<div id=\"thumbLink" + idx + "\" style=\"float: left; overflow: hidden;\">" + this.thumbLinks[idx].link + "</div>";
		            }
		            //put the thumbnails into the object
		            if (rylightboxThumbsMiddleSection != null)
		            {
		                rylightboxThumbsMiddleSection.innerHTML = thumbsString;
		            }
		            rylightboxThumbsMiddleSection.id = this.name + "_thumbs_MidSection";
		            
		        this.thumbsEleMiddle = rylightboxThumbsMiddleSection;
		        this.thumbsEleMiddle.style.width = this.currentMedia.width - (this.thumbLinks.arrowWidth * 2) - (this.padding * 4);
		        
		        if (rylightboxThumbs != null)
		        {
		            rylightboxThumbs.appendChild(rylightboxThumbsMiddleSection);
		        }
		        
		    this.thumbsEle = rylightboxThumbs;    		    
		    if (rylightboxContainer != null)
		    {
		        rylightboxContainer.appendChild(rylightboxThumbs);
		    }
		}

		this.imageField = rylightboxImage;

		var rylightboxArrowLeft = document.createElement("div");
		rylightboxArrowLeft.className = "rylightbox-arrow-left";

			var prevImage = document.createElement("a");
			prevImage.href = "#";
			if (prevImage != null)
			{
			    prevImage.innerHTML = "Previous Image";
			}
			prevImage.onclick = function() { closedRef.prevImage(); };

            if (rylightboxArrowLeft != null)
            {
			    rylightboxArrowLeft.appendChild(prevImage);
			}

		this.prevArrow = rylightboxArrowLeft;
		if (rylightboxContainer != null)
		{
	        rylightboxContainer.appendChild(rylightboxArrowLeft);
		}

		var rylightboxArrowRight = document.createElement("div");
		rylightboxArrowRight.className = "rylightbox-arrow-right";

			var nextImage = document.createElement("a");
			nextImage.href = "#";
			if (nextImage != null)
			{
			    nextImage.innerHTML = "Next Image";
			}
			nextImage.onclick = function() { closedRef.nextImage(); };
			if (rylightboxArrowRight != null)
			{
			    rylightboxArrowRight.appendChild(nextImage);
			}

		this.nextArrow = rylightboxArrowRight;
		if (rylightboxContainer != null)
		{
		    rylightboxContainer.appendChild(rylightboxArrowRight);
		}

        if (this.links.length > 0)
        {
		    var rylightboxLinks = document.createElement("ul");
		    rylightboxLinks.className = "rylightbox-" + this.links.length;

		    for (var idx = 0, len = this.links.length; idx < len; idx++) {
			    var rylightboxLinksLI = document.createElement("li");
    			
			    if (idx == (len - 1)) {
				    rylightboxLinksLI.className = "rylightbox-last";
			    }

				    var ryLink = document.createElement("a");
				    ryLink.href = "#none";
				    ryLink.onclick = this.links[idx].action;
				    if (ryLink != null)
				    {
				        ryLink.innerHTML = this.links[idx].name;
				    }
    				
    				if (rylightboxLinksLI != null)
    				{
				        rylightboxLinksLI.appendChild(ryLink);
				    }

                if (rylightboxLinks != null)
                {
			        rylightboxLinks.appendChild(rylightboxLinksLI);
			    }
		    }

		    this.linksEle = rylightboxLinks;
		    
		    if (rylightboxContainer != null)
		    {
		        rylightboxContainer.appendChild(rylightboxLinks);
		    }
		}
		
	if (document.getElementsByTagName("body")[0] != null)
	{
	    document.getElementsByTagName("body")[0].appendChild(rylightboxContainer);
	}
	
	this.ele = rylightboxContainer;

	if (this.currentMedia.type == "swf") {

		this.makeAreaFlash();
	}

	var backOverlay = document.createElement("div");
	backOverlay.className = "rylightbox-overlay rylightbox-container-hidden";
	if (document.getElementsByTagName("body")[0] != null)
	{
	    document.getElementsByTagName("body")[0].appendChild(backOverlay);
	}
	backOverlay.id = "overlayDiv";

	this.overlay = backOverlay;

	this.checkIfImageLoaded();

	this.hidePrevArrow();

	if ((this.currentNumber + 1) == this.media.length) {
		this.hideNextArrow();
	}

	var currentResize = window.onresize;
	window.onresize = function () {
		if (currentResize != null) currentResize();

		closedRef.calculatePosition();
	}
	
    //init the window size
    this.resizeWindowFull(0); //send 0 as there will always be 1 image
}

RyLightbox.prototype.scrolledLeft = function() {
	// Retun the amount the window has been scrolled from the left

	if (document.body) { // other Explorers
		return document.body.scrollLeft;
	}
	else if (self.innerHeight) { // all except Explorer
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return document.documentElement.scrollLeft;
	}
}

RyLightbox.prototype.scrolledTop = function() {
	// Return the amount the document is scrolled from the top

	if (document.body) { // other Explorers
		return document.body.scrollTop;
	}
	else if (self.innerHeight) { // all except Explorer
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return document.documentElement.scrollTop;
	}
}

RyLightbox.prototype.BrowserWidth = function() {
	// Return the browsers width

	if (self.innerHeight) { // all except Explorer
		return self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return document.documentElement.clientWidth;
	}
	else if (document.body) { // other Explorers
		return document.body.clientWidth;
	}
}

RyLightbox.prototype.BrowserHeight = function() {
	// Return the browsers height

	if (self.innerHeight) { // all except Explorer
		return self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		return document.documentElement.clientHeight;
	}
	else if (document.body) { // other Explorers
		return document.body.clientHeight;
	}
}

RyLightbox.prototype.docHeight = function() {
	// Height of the document

	if ((document.documentElement.scrollHeight > document.body.scrollHeight)&&(document.documentElement.scrollHeight > document.body.offsetHeight)) {
		return document.documentElement.scrollHeight;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		return document.body.scrollHeight;
	}
	else { // Explorer Mac; would also work in Explorer 6 Strict, Mozilla and Safari
		return document.body.offsetHeight;
	}
}