// ------------------------------------------------------------------------------
// PRELOAD IMAGES
// ------------------------------------------------------------------------------

//=============================================================================
// Image Preloader
function ImagePreloader(images,callback)
{
	// make sure we can make a nice preloading effect while loading images
	if(document.getElementById('preloadLoading') != undefined && document.getElementById('preloadLoading') != 'undefined')
	{
		// set preloader gif
		document.getElementById('preloadLoading').innerHTML = '<table cellspacing="" cellpadding="0" border="0"><tr><td><img src="'+config['a_url']+'inc/gfx/loading.gif"/></td><td style="padding: 0 5px 0 0;">Laddar in bild</td><td id="preloadStatus">'+('1 av ' + mcmsImgPopup.get_picture_bank_length())+'</td></tr></table><br/><br/>'
		
		// store the callback
		this.callback = callback;
	
		// initialize internal state.
		this.nLoaded = 0;
		this.nProcessed = 0;
		this.aImages = new Array;
	 
		// record the number of images.
		this.nImages = images.length;
	
		// for each image, call preload()
		for ( var i = 0; i < images.length; i++ ) 
			this.preload(images[i]);
	}
	else
	{
		alert("Preload effect DIVs missing:\n\nUse following html\n<div id=\"preloadLoading\"></div>\n<div id=\"preloadLoaded\">Images to be preloaded goes here</div>");
	}
}
ImagePreloader.prototype.preload = function(image)
{
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);
	
	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	
	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;
	
	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}
ImagePreloader.prototype.onload = function()
{
	document.getElementById('preloadStatus').innerHTML = (parseInt(this.oImagePreloader.nLoaded)+2) + ' av ' + mcmsImgPopup.picture_bank.length;
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
function onPreload(aImages)
{
	if(document.getElementById('preloadLoading') != undefined && document.getElementById('preloadLoading') != 'undefined')
	{
		document.getElementById('preloadLoading').style.display = 'none';
		document.getElementById('preloadLoaded').style.display = 'block';
	}
	
	// set iframe height (content height)
	goSetHeight();
}



// ------------------------------------------------------------------------------
// PRELOAD IMAGES (one image)
// ------------------------------------------------------------------------------

//=============================================================================
// Image Preloader
var global_strObjImgPopupName = "";
var oImage = "";
function ImagePreloader_individual(images,callback,strObjImgPopupName)
{
	// store name of "image popup" object in global var
	global_strObjImgPopupName = strObjImgPopupName;
	
	// make sure we can make a nice preloading effect while loading images
	if(parent.document.getElementById('preloadLoading_individual_'+global_strObjImgPopupName) != undefined && 
	   parent.document.getElementById('preloadLoading_individual_'+global_strObjImgPopupName) != 'undefined')
	{
		// set preloader gif
		parent.document.getElementById('preloadLoading_individual_'+global_strObjImgPopupName).innerHTML = '<table cellspacing="" cellpadding="0" border="0"><tr><td><img src="'+config['a_url']+'inc/gfx/loading.gif"/></td><td style="padding: 0 5px 0 0;">Laddar in bild</td><td id="preloadStatus_individual">'+('1 av ' + eval(global_strObjImgPopupName+".get_picture_bank_length()") )+'</td></tr></table><br/><br/>'
		
		// store the callback
		this.callback = callback;
	
		// initialize internal state.
		this.nLoaded = 0;
		this.nProcessed = 0;
		this.aImages = new Array;
	 
		// record the number of images.
		this.nImages = images.length;
	
		// for each image, call preload()
		for ( var i = 0; i < images.length; i++ ) 
			this.preload(images[i]);
	}
	else
	{
		alert("Preload effect DIVs missing:\n\nUse following html\n<div id=\"preloadLoading_individual_"+global_strObjImgPopupName+"\"></div>\n<div id=\"preloadLoaded_individual_"+global_strObjImgPopupName+"\">Images to be preloaded goes here</div>");
	}
}
ImagePreloader_individual.prototype.preload = function(image)
{
	// create new Image object and add to array
	oImage = new Image;
	this.aImages.push(oImage);
	
	// set up event handlers for the Image object
	oImage.onload = ImagePreloader_individual.prototype.onload;
	oImage.onerror = ImagePreloader_individual.prototype.onerror;
	oImage.onabort = ImagePreloader_individual.prototype.onabort;
	
	// assign pointer back to this.
	oImage.oImagePreloader_individual = this;
	oImage.bLoaded = false;
	oImage.source = image;
	
	// assign the .src property of the Image object
	oImage.src = image;
}
ImagePreloader_individual.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages )
		this.callback(this.aImages);
}
ImagePreloader_individual.prototype.onload = function()
{
	parent.document.getElementById('preloadStatus_individual').innerHTML = (parseInt(this.oImagePreloader_individual.nLoaded)+2) + ' av ' + eval(global_strObjImgPopupName+".picture_bank.length");
	this.bLoaded = true;
	this.oImagePreloader_individual.nLoaded++;
	this.oImagePreloader_individual.onComplete();
}
ImagePreloader_individual.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader_individual.onComplete();
}
ImagePreloader_individual.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader_individual.onComplete();
}
function onPreload_individual(aImages)
{
	if(parent.document.getElementById('preloadLoading_individual_'+global_strObjImgPopupName) != undefined && parent.document.getElementById('preloadLoading_individual_'+global_strObjImgPopupName) != 'undefined')
	{
		parent.document.getElementById('preloadLoading_individual_'+global_strObjImgPopupName).style.display = 'none';
		parent.document.getElementById('preloadLoaded_individual_'+global_strObjImgPopupName).style.display = 'block';
		
		// enable image gallery
		eval(global_strObjImgPopupName+".individual_image_show();");
	}
	
	// set iframe height (content height)
	goSetHeight();
}