var SpilPopup = 
{
	getSize: function(win) 
	{
		var innersize = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			if (win == 'ww') {
				innersize = window.innerWidth;
			} else {
				innersize = window.innerHeight;
			}
		} else if( document.documentElement &&
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			if (win == 'ww') {
				innersize = document.documentElement.clientWidth;
			} else {
				innersize = document.documentElement.clientHeight;
			}
	  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			if (win == 'ww') {
				innersize = document.body.clientWidth;
			} else {
				innersize = document.body.clientHeight;
			}
	  	}
	 	return innersize;
	},

	windowresize: function()
	{
		var arrFullUrl = window.location.href.split("?");
		if (arrFullUrl[1] != null) {
			var urlvars=arrFullUrl[1].split('&');
			for (var i=0;i<urlvars.length;i++) {
				var urlvar = urlvars[i].split('=');
				this[urlvar[0]]=urlvar[1];
			}
			SpilPopup.generate(unescape(this.page),this.w,this.h);
		}
	},

	//  detect XP OS Service Pack 2
	detectXP: function() 
	{
		var osVar = navigator.userAgent.toLowerCase();
			var spVar;
			var brVar = navigator.appName.toLowerCase();
			if (osVar.indexOf('windows nt 5.1')!=-1 && brVar.indexOf('microsoft internet explorer')!=-1){
				spVar = navigator.appMinorVersion.toLowerCase();
				if(spVar.indexOf('sp2')!=-1) {
					xpVar = 28;
				}
				else {
					xpVar = 0;
				}
			}
			else {
				xpVar = 0;
			}
		return xpVar;
	},

	generate: function(medialink,w,h) 
	{
		var xpVar;
		xpVar = SpilPopup.detectXP();
		//var comp = parseInt(h, 10) + xpVar;
		//window.resizeTo(w,comp);
		var filetype = medialink.substr(medialink.length-3, medialink.length);
		//winwidth = SpilPopup.getSize('ww');
		//winheight = SpilPopup.getSize('hw');
		
		if (filetype == 'swf') {
			
			$('popup').set('html', 
				'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width='+w+' height='+h+'>',
				'<param name="movie" value='+medialink+' />',
				'<param name="quality" value="high" />',
				'<param name="scale" value="noscale" />',
				'<param name="salign" value="lt" />',
				'<embed src='+medialink+' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+w+' height='+h+' scale="noscale" salign="lt"></embed>',
				'</object>'
			);
			
			// HVIS MOOTOOLS 1.2:
			// var so = new SWFObject(medialink, "mymovie", winwidth, winheight, "8", "#336699");
			// 			so.addParam("quality", "high");
			// 			so.addParam("scale", "noscale");
			// 			so.addParam("salign", "lt");
			// 			so.write("popup");
			
			// GAMMEL KODE:
			// document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+winwidth+'" height="'+winheight+'">');
			// 			document.write('<param name="movie" value="'+medialink+'" />');
			// 			document.write('<param name="quality" value="high" />');
			// 			document.write('<param name="scale" value="noscale" />');
			// 			document.write('<param name="salign" value="lt" />');
			// 			document.write('<embed src="'+medialink+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+winwidth+'" height="'+winheight+'" scale="noscale" salign="lt"></embed>');
			// 			document.write('</object>');
		} else {
			$('popup').set('html',
				'<iframe src='+medialink+' marginheight="0" marginwidth="0" width='+w+' height='+h+' frameborder="no" scrolling="no" id="media"></iframe>'
			);
				
			// HVIS MOOTOOLS 1.2:
			// var myIFrame = new IFrame({ 
			// 			    src: medialink,			 
			// 			    styles: {
			// 			        width: winwidth,
			// 			        height: winheight,
			// 			        border: 'none'
			// 			    }	 
			// 			});
			// 			
			// 			myIframe.inject($('popup'));
			
			// GAMMEL KODE:
			//document.write("<iframe src='"+medialink+"' marginheight='0' marginwidth='0' width='"+winwidth+"' height='"+winheight+"' frameborder='no' scrolling='no' id='media'></iframe>");
			//a = document.getElementById('media');
			//a.src = medialink;
		}
	}
};

window.addEvent('domready', function () {
	SpilPopup.windowresize();
});
