var Topview = new Class({
	initialize: function (options) {
		el = $E(options.selector);
		
		if (!el) {
			// new Logger(options.selector+' not found');
			return;
		}
		//geen resultmodus switcher!
		try {
			$E('.resultmodelist').setStyle('display', 'none');
		} catch (e) {
			//er is geen resultmodeswitcher ...
			//geen probleem
		}
		try {
		$('detailpaginering').setStyle('display', 'none');
		} catch(e) {}

		//maak een container aan om flikkerende pagina's te voorkomen:
		var container = $('topview_container');
		if (!container) {
			var container = new Element('div', {
				'id':'topview_container',
				'styles': {
					'width': options.width,
					'height': options.height
				}
			});
			container.injectBefore(el);
			el.injectInside(container);
		}

		var _id = el.id.replace(/^topview\_/, '');
		
		/*
		//pas doen als afbeeldinging is ingeladen:
		var images=[];
		$(el.id).getElements('img').each(function(img){
			images.push(img.src);
		});
		new Asset.images(images, {
		    onComplete: function(){
				swfobject.embedSWF(
						options.swf, 
						el.id, 
						options.width,
						options.height,
						'8.0.0', 
						options.express, 
						{'xmlpath' : escape(options.url.replace(/{ID}/, _id))}, 
						{
						    wmode : 'window',
							allowFullScreen : 'true',
							swliveconnect: 'true',
							bgcolor : options.bgcolor
						},
						{'class':'topview'}
					);
		    }
		});
		*/
		
		swfobject.embedSWF(
				options.swf, 
				el.id, 
				options.width,
				options.height,
				'8.0.0', 
				options.express, 
				{'xmlpath' : escape(options.url.replace(/{ID}/, _id))}, 
				{
				    wmode : 'window',
					allowFullScreen : 'true',
					swliveconnect: 'true',
					bgcolor : options.bgcolor
				},
				{'class':'topview'}
			);
	}
});

function topview_action(task, files, params)
{
	switch (task) {
		case 'navigate':
			if (TopviewOptions.url.match(/tstart=\d+/)) {
				TopviewOptions.url = TopviewOptions.url.replace(/tstart=\d+/, 'tstart='+params.imageIndex);
			} else {
				TopviewOptions.url += (TopviewOptions.url.match(/\?/) ? '&' : '?');
				TopviewOptions.url += 'tstart=' + params.imageIndex;
			}
			TopviewOptions.selector = 'object.topview';
			new Topview(TopviewOptions);
			break;
		case 'crop':
			if (params.cropwidth<=5 || params.cropheight<=5) return;
			if(!TopviewOptions.cropurl) {
				alert('this function is not available'); 
				return;
			}
			var url = TopviewOptions.cropurl
				.replace(/\{cropx\}/, params.cropx)
				.replace(/\{cropy\}/, params.cropy)
				.replace(/\{cropwidth\}/, params.cropwidth)
				.replace(/\{cropheight\}/, params.cropheight) + files[0].replace(/\/topview/, '').replace(/^\//, '');
			//window.open(url);
			window.document.location.href = url;
			break;
		default:
			new Logger('unkown task in topview.js: ' + task);
			break;
	}
}

