// PREDEFINE SHORTWRITING VARIABLES
var w, d, db, da;



// QUICK BROWSER CHECK [IE, FIREFOX, OPERA]
var opera = (self.opera) ? true : false;
var chrome = (navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('chrome') != -1) ? true : false;
var ie = (document.all && !opera && !chrome) ? true : false;
var firefox = (!document.all && !opera && !chrome) ? true : false;
//alert('Browser : ' + (ie ? "Internet Explorer" : (firefox ? "Firefox" : (opera ? "Opera" : (chrome ? "Google Chrome" : "Unknown browser")))));







function onDOMReady( args ){
	//	onDOMReady -	Copyright (c) 2009 Ryan Morr (ryanmorr.com)
	//								Additions (c) Martijn Smit (www.yomarty.nl)
	//
	//		onReady					::	(required) function to call onDOMReady
	//		useThis					::	(optional) define this for within calling function
	//		scriptsRequired	::	(optional) (array) list of scripts required (not full path and without ?...)


	if (!args && !args.onReady) return;

	var fn = args.onReady;
	var ctx = (args.useThis ? args.useThis : null);
	var src = (args.scriptsRequired ? args.scriptsRequired : null);
	var ready = 0, scriptsreq = 0, timer, i, j, scripts, srcstring;
	var d = document, w = window;

	var safeEval = function(s) { try{ eval(s); } catch(e){ return false; }; return true; };



	var onStateChange = function(e) {
		if (e && e.type == "DOMContentLoaded") { ready = 1; fireReady(); }
		else if (e && e.type == "load") { ready = 1; fireReady(); }
		else if(d.readyState) {
				if (d.readyState == "loaded" || d.readyState == "complete") { ready = 1; fireReady(); }
				else if (!!d.documentElement.doScroll) { try{ ready || d.documentElement.doScroll('left'); } catch(e){ return; } ready = 1; fireReady(); }
		}

		if (src) {
			scripts = d.getElementsByTagName("script");
			for (i = 0; i < src.length; i++) {
				if (src[i].ready == false) {
					for (j = 0; j < scripts.length; j++) if (scripts[j].src.indexOf(src[i].src) != -1) { src[i].ready = true; scriptsreq--; fireReady(); safeEval(scripts[j].innerHTML); }
				}
			}
		}

	};



	var fireReady = function() {
	if (ready == 1 && scriptsreq <= 0) {
			d.onreadystatechange = null; // first to clear
			w.onload = null; // first to clear
			clearInterval(timer); timer = null; // first to clear
			if(d.removeEventListener) d.removeEventListener("DOMContentLoaded", onStateChange, false);
			d._DOMREADY = true;
			fn = (fn.call(ctx || w) ? null: null); // last to execute
			//alert('ready: ' + ready + ' , scriptsreq: ' + scriptsreq);
		}
	};



	d._DOMREADY = false;
	if (src) for (i = 0; i < src.length; i++) { src[i] = { src: src[i], ready: false }; scriptsreq++; } // add to required scripts
	if(d.addEventListener) d.addEventListener("DOMContentLoaded", onStateChange, false); d.onreadystatechange = onStateChange; timer = setInterval(onStateChange, 10); w.onload = onStateChange;
}









function safe_eval(str) { try{ eval(str); } catch(err){ return false; }; return true; }






	//var _DOCOLSCR = []; // DocumentOnloadScript object
	//function attachDocumentOnloadScript( scr ) { if (scr && scr.toString()) _DOCOLSCR.push(scr); }
	//function execDocumentOnloadScript( scr ) { if (_DOCOLSCR) safe_eval(_DOCOLSCR.join('\n')); }





	function EXECifDomReady() {
		var objs = document.getElementsByTagName("img");
		for (var i = 0;  i < objs.length; i++) {
			if ((objs[i].className+'').toUpperCase() == 'EXECIFDOMREADY') {
				try{ objs[i].onload = (objs[i].onload() ? null: null); } catch(err){ continue; }; // execute and kill function at same time
			}
		}
	}



	function attachEventListener(obj, evt, func) {
		if (obj && evt && func) {
			if (obj.addEventListener) obj.addEventListener(evt, func, false);
			if (obj.attachEvent) obj.attachEvent(evt, func);
		}
	}



	function detachEventListener(obj, evt, func) {
		if (obj && evt && func) {
			if (obj.removeEventListener) obj.removeEventListener(evt, func, false);
			if (obj.detachEvent) obj.detachEvent(evt, func);
		}
	}






function exif_Initialize(fid)
	{
		if (!window.execFlash) window.execFlash = {}; // only once
		var io = window.execFlash[fid] = {}; // new interface object inside execFlash

		// trace reference to flash object inside window
		if (document[fid]) io._obj = document[fid];
		else if (frames && frames.length > 0) {  for (var f, i = 0; i < frames.length; i++) { f = frames[i]; if (f.document[fid]) { io._obj = f.document[fid]; break; } } }

		io.id = fid; // save name of flash object
		io.send = function(o) { this._obj.receiveFromFlash(o); }; // create function

		if (ie && !window.execFlash.available) window.onbeforeunload = function() { __flash_savedUnloadHandler = null; } // IE MULTIPLE EXT.INTERFACE 'OUT OF MEM' FIX
		window.execFlash.available = true;
	}






//function exif_unescape(x) { return x.split('').reverse().join(''); }
																														 // USED IN NORMAL SITE OF SIMSALABOEK TOO!!!!!!!!!!!
function exif_unescape(x) { return unescape(decodeURI(x)); } // very slow in ie (old way preserving unicode characters)





function exif_receiveExternalData(args)
	{
		//startTime=new Date().getTime(); // start processing speed
		if (args.exif_data) {
			var x = args.exif_data, y = '';
			for (var i = 0, n = x.length; i < n; i++) y+= x[i].split('').reverse().join(''); //  join array chunks & reverse back string
			args.exif_data = y;
		}

		//endTime=new Date().getTime();	args.exif_data = ((endTime-startTime)/1000) + ' seconds.</br>' + args.exif_data; // end and show processing speed
		if (args.exif_onload) window[args.exif_onload](args); // if onload
	}




function embedFlashOrAlternate(a) {
 // bugfix (IE):	to to prevent "object doesn't support.." error, don't give a flash object the same name/id
 //								as other objects (like divs etc..)
 									
 // version 1.1:	incl. menu and base properties

 if (a && a.src && a.target) {
  a.name = (a.name ? a.name : 'flashmovie'); // name property or nothing
  a.id = a.name; // id property (copy of name)

	a.width = (a.width ? 'width:' + a.width + ';' : ''); // width (style) or nothing
	a.height = (a.height ? 'height:' + a.height + ';' : ''); // height (style) or nothing
	//a.width = (a.width ? ' width="' + a.width + '" ' : ' '); // width tag or nothing
	//a.height = (a.height ? ' height="' + a.height + '" ' : ' '); // height tag or nothing

	a.quality = (a.quality ? a.quality : 'HIGH'); // quality, default is HIGH
  a.bgcolor = (a.bgcolor ? a.bgcolor : '#ffffff'); // bgcolor, default is #ffffff
  a.flashvars = (a.flashvars ? a.flashvars : ''); // flashvars, default is ''
  a.wmode = (a.wmode ? a.wmode : 'window'); // wmode, default is window
  a.base = (a.base ? a.base : '.'); // base, default is '.' path

  var str = '<object tabindex="-1" id="' + a.id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="' + a.width + a.height
          + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
					+ '<param name="menu" value="false" /><param name="base" value="' + a.base + '" />'
					+ '<param name="movie" value="' + a.src + '" /><param name="quality" value="' + a.quality + '" />'
          + '<param name="bgcolor" value="' + a.bgcolor + '" /><param name="allowScriptAccess" value="sameDomain" />'
          + '<param name="flashvars" value="' + a.flashvars + '" /><param name="wmode" value="' + a.wmode + '" />'
          + '<embed tabindex="-1" name="' + a.name + '" src="' + a.src + '" quality="' + a.quality + '" menu="false"'
          + ' bgcolor="' + a.bgcolor + '" style="' + a.width + a.height + '" base="' + a.base + '"'
          + ' flashvars="' + a.flashvars + '" wmode="' + a.wmode + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" '
          + 'pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed><\/object>';

	a.target.innerHTML = str;
 }
}
