var films 		= new Array("beuk-tijdelijk.mp4", "beukrijs03-02-12.mp4");
var filmnummer	= 1;//rand(0,1);
var film		= films[filmnummer];


window.addEvent('domready', function() {
	var agent		= navigator.userAgent.toLowerCase();
	var is_iphone 	= (agent.indexOf('iphone')!=-1);
	//startAfilm();
	if(is_iphone){	
		$('stylesheet').setProperty('href', 'css/mobile.css');
		startQt();
	}else{
		startFlash();		
	}
	 
});

window.addEvent('resize', function() {
	scale();
});


function scale(firstrun){
	wh =window.getCoordinates();
	$('deflvplayer').setStyles({width: wh.width, height:wh.height})	
	c 			= $('c').getCoordinates();
	f 			= 250;//$('f').getCoordinates().height;
	thestyles 	= (firstrun) ? {'min-height':c.height, 'height':(wh.height-f)} :{'height':(wh.height-f)} ;
	$('c').setStyles(thestyles);
	
	console.log(wh.height-f);
}

function email(add){	
document.location.href="mailto:"+Base64.decode(add);	
}

function rand (min, max) {
	var argc = arguments.length;
	    if (argc === 0) {
	        min = 0;
	        max = 2147483647;    } else if (argc === 1) {
	        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
	    }
	    return Math.floor(Math.random() * (max - min + 1)) + min;

	}


function startQt(){
	var qtc = "<object\n" + 
			"classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B'\n" + 
			"codebase='http://www.apple.com/qtactivex/qtplugin.cab'\n" + 
			"height='175'\n" + 
			"width='310' >\n" + 
			"<param name='src' value='http://www.statuur.nl/mediaplayer/"+film+"'/>\n" + 
			"<param name='controller' value='false'/>\n" + 
			"<param name='target\" value='QuickTimePlayer'/>\n" + 
			"<param name='href\" value='http://www.statuur.nl/mediaplayer/"+film+"'/>\n" + 
			"<embed\n" + 
			"type='video/quicktime'\n" + 
			"pluginspage='http://www.apple.com/quicktime/download/'\n" + 
			"height='175'\n" + 
			"width='310'\n" + 
			"src='http://www.statuur.nl/mediaplayer/"+film+"'\n" + 
			"controller='false'\n" + 
			"target='QuickTimePlayer'\n" + 
			"href='http://www.statuur.nl/mediaplayer/"+film+"' />\n" + 
			"</object>";
	$('qt').innerHTML=qtc;
}

function startFlash(){
wh =window.getCoordinates();
	


		var flashvars = {
			file 				: "../mediaplayer/"+film,
			"viral.onpause"		: false,
			screencolor 		: "#fff",
			image 				: "mediaplayer/preview.zip",		
			backcolor 			: "#282724",		
			frontcolor 			: "#fff",
			autostart			: true, 
			repeat				: 'always', 
			menu				: false, 
			stretching 			: "exactfit", 
			controlbar			: "none",
			skin				: "mediaplayer/mare.zip"
	 };

	 var params 			= {
			allowfullscreen 	: true,
			allowscriptaccess	: "always",
			wmode 				: "opaque"
	};

		var attributes 		= {
				id 				: "deflvplayer",
				name 			: "deflvplayer"
				};

	swfobject.embedSWF("mediaplayer/player.swf", "film_wrapper", wh.width, wh.height, "9.0.0","mediaplayer/expressInstall.swf", flashvars, params, attributes);
	
	//}
	
	
	 scale(1);
	}





/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}


