/*
###
###                               
###    LONNEKE.COM
###                                 
###    v 3.0 (2010-04-11)            
###                                   
#+-----------------------------------------+
#|                                         |
#|     Nick C. Kaye                        |
#|     www.NickKaye.com                    |
#|     ©2010 Outright Mental Directive     |
#|                                         |
#|     use of any part of this             |
#|     software or source code             |
#|     is strictly forbidden.              |
#|                                         |
#+-----------------------------------------+
###
*/
var om = {
/*




  ___ ___  _ __ ___ 
 / __/ _ \| '__/ _ \
| (_| (_) | | |  __/
 \___\___/|_|  \___|

*/
	// head container
	hC : Object,
	hCid: String,
	// body container
	bC : Object,
	bCwidth : Number,
	bCid: String,
	// body background container
	bgC : Object,
	bgCid: String,
	// body flash container
	bfC : Object,
	bfCid: String,
	// body iframe container
	biC : Object,
	biCid: String,
	// nav container
	nC : Object,
	nCid: String,
	// pointer x,y
	pX : Number,
	pY : Number,
	// viewport width,height
	vW : Number,
	vH : Number,
	
	config : new Object(),
	area : new Object(),
	
	init: function(hCid, bCid, bgCid, bfCid, biCid, nCid, language, area, group, entry) { // pass in the id of the group, entry master container elements

		// process language
		if (language=='NL') {
			om.config.language='NL';
			om.config.altLang='_altlangA';
		} else {
			om.config.language='EN';
			om.config.altLang='';
			}

		// process area
		if (area!=null) { om.config.area = area; } else { om.config.area = ""; }	

		// process group
		if (group!=null) { om.config.group = group; } else { om.config.group = ""; }

		// process entry
		if (entry!=null) { om.config.entry = entry; } else { om.config.entry = ""; }

		// get & prep the head container
		om.hCid = hCid;
		om.hC = $(hCid);
		Element.extend(om.hC);
	
		// get & prep the body html container
		om.bCid = bCid;
		om.bC = $(bCid);
		Element.extend(om.bC);
	
		// get & prep the body background container
		om.bgCid = bgCid;
		om.bgC = $(bgCid);
		Element.extend(om.bgC);
	
		// get & prep the body swf container
		om.bfCid = bfCid;
		om.bfC = $(bfCid);
		Element.extend(om.bfC);
	
		// get & prep the body iframe container
		om.biCid = biCid;
		om.biC = $(biCid);
		Element.extend(om.biC);
	
		// get & prep the nav container
		om.nCid = nCid;
		om.nC = $(nCid);
		Element.extend(om.nC);
	
		// viewport scrolling/resizing
		window.onscroll = function() { om.onViewportChange(); };
		window.onresize = function() { om.onViewportChange(); };
		
		// viewport init
		om.onViewportChange();
	
		// mouse
		// only switch this on if it's necessary for an interface,
		// if used in tandem with flash it's a bit taxing
		/*
		om.setupMouse();
		*/
		
		// nav init
		om.setupNavSWF();
		
		// micronav init
		om.setupMicroNavSWF();
		
		},
		
	modeCur : String,
	mode : function( mode ) {
		if (!om.modeCur) {
			om.modeCur = "";
			}
		if( !mode ) {
		} else {
			if ( om.modeCur != mode ) {
				switch( mode ) {
				case "group":
					break;
				case "entry":
					break;
				default:
					break;
					}
				} else {
					}
				om.modeCur = mode;
			}
			return om.modeCur;
		},
/*





          _               
         | |              
 ___  ___| |_ _   _ _ __  
/ __|/ _ \ __| | | | '_ \ 
\__ \  __/ |_| |_| | |_) |
|___/\___|\__|\__,_| .__/ 
                   | |    
                   |_|   


*/
	setupMouse : function() {
		Event.observe(document, 'mousemove', function(event){
			om.pX = Event.pointerX(event);
			om.pY = Event.pointerY(event);
			});
		},
		
	navSWF : Object,
		
	setupNavSWF : function() {
//		om.nC.update("<script type='text/javascript'>om.launchSWF( 'swf_nav', 'sub/nav', 1024, 150 );</script>");	
		var swfID = om.nCid + "_swf";
		om.navSWF = new Element( "span", { id: swfID } );  om.nC.appendChild( om.navSWF );
		swfobject.embedSWF(om.config.url_site + "assets/swf/nav.swf", swfID, "100%", "150", "8.0.0", null, om.config );
// swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn
		},

	micronavSWF : Object,
		
	setupMicroNavSWF : function() {
//		om.nC.update("<script type='text/javascript'>om.launchSWF( 'swf_nav', 'sub/nav', 1024, 150 );</script>");	
		var swfID = om.hCid + "_swf";
		om.micronavSWF = new Element( "span", { id: swfID } );  om.hC.appendChild( om.micronavSWF );
		swfobject.embedSWF(om.config.url_site + "assets/swf/micronav.swf", swfID, "100%", "20", "8.0.0", null, om.config );
		},

	bodySWF : Object,

	setupBodySWF : function( swfFilePath ) {
		if (swfFilePath!=null) {
			// there is a filepath; load the swf
			var swfID = om.bfCid + "_swf";
			om.bodySWF = new Element( "span", { id: swfID } );  om.bfC.appendChild( om.bodySWF );
			swfobject.embedSWF(om.config.url_site + swfFilePath, swfID, "100%", "100%", "8.0.0", null/* replace null with express install swf*/, om.config, null, {id: swfID});
		} else {
			// no filepath; clear the swf
			var swfClear = $(om.bfCid + "_swf");
			if (swfClear!=null) {
				swfClear.remove();
				}
			}
		},
		
	setupFixedSWF : function( swfFilePath, width, height ) {
		var swfID = om.bfCid + "_swf";
		var swfClear = $(swfID);
		if (swfClear!=null) {
			swfClear.remove();
			alert("removed?");
			}
		if (swfFilePath!=null) {
			// there is a filepath; load the swf
			om.bodySWF = new Element( "span", { id: swfID } );  om.bfC.appendChild( om.bodySWF );
			swfobject.embedSWF(om.config.url_site + swfFilePath, swfID, width, height, "8.0.0", null/* replace null with express install swf*/, om.config, null, {id: swfID});
			}
		},

	setupYouTubeSWF : function( swfCid, ytID, width, height ) {
		var embedID = "om_ytplayer";
		var swfID = swfCid + "_swf";
		var swfClear = $(swfID);
		if (swfClear!=null) {
			swfClear.remove();
			}
		if (ytID!==undefined) {
			var swfClear = $(embedID);
			if (swfClear!=null) {
				swfClear.remove();
				}
			if (width==undefined) { width = 480; }
			if (height==undefined) { height = 385; }
			// there is a filepath; load the swf
			om.bodySWF = new Element( "span", { id: swfID } );  $(swfCid).appendChild( om.bodySWF );
			var params = {
				allowScriptAccess: "always",
				color2: "0xffffff",
				color1: "0x000000",
				allowfullscreen: "true"
				};
			var atts = { id: swfID };
			swfobject.embedSWF("http://www.youtube.com/v/" + ytID + "?enablejsapi=1&playerapiid=ytplayer", swfID, width, height, "8", null, null, params, atts);
			$(swfCid).show();			
			}
		},


		
	bodyIFrame : Object,
	
	setupBodyIFrame : function( iFrameURL ) {
		if (iFrameURL!=null) {
			// there is a filepath; load the swf
			var swfID = om.biCid + "_iframe";
			om.bodyIFrame = new Element( "iframe", { id: swfID, src: iFrameURL, width:"100%", height:"100%" } );  om.biC.appendChild( om.bodyIFrame );
		} else {
			// no filepath; clear the swf
			var swfClear = $(om.biCid + "_iframe");
			if (swfClear!=null) {
				swfClear.remove();
				}
			}
		},



/*





             _   _ _                                _   _____ _                            
            | | | (_)                              | | /  __ \ |                           
  ___  _ __ | | | |_  _____      ___ __   ___  _ __| |_| /  \/ |__   __ _ _ __   __ _  ___ 
 / _ \| '_ \| | | | |/ _ \ \ /\ / / '_ \ / _ \| '__| __| |   | '_ \ / _` | '_ \ / _` |/ _ \
| (_) | | | \ \_/ / |  __/\ V  V /| |_) | (_) | |  | |_| \__/\ | | | (_| | | | | (_| |  __/
 \___/|_| |_|\___/|_|\___| \_/\_/ | .__/ \___/|_|   \__|\____/_| |_|\__,_|_| |_|\__, |\___|
                                  | |                                            __/ |     
                                  |_|                                           |___/      

*/
onViewportChange : function() {
	om.vH = document.viewport.getHeight();
	om.vW = document.viewport.getWidth();
	om.contentSetSize();
	},
/*





     _ _       _   _             
    (_) |     | \ | |            
 ___ _| |_ ___|  \| | __ ___   __
/ __| | __/ _ \ . ` |/ _` \ \ / /
\__ \ | ||  __/ |\  | (_| |\ V / 
|___/_|\__\___\_| \_/\__,_| \_/  
                                 
*/
navGo : function( area_id ) {
	om.siteContent( area_id );
	},

navLanguage : function( language ) {
	om.config.language = language;
	if (language=="NL") { 
		om.config.altLang = "_altlangA";
	} else {
		om.config.altLang = null;
		}
	om.siteContent();
	},
/*




     _ _       _____             _             _   
    (_) |     /  __ \           | |           | |  
 ___ _| |_ ___| /  \/ ___  _ __ | |_ ___ _ __ | |_ 
/ __| | __/ _ \ |    / _ \| '_ \| __/ _ \ '_ \| __|
\__ \ | ||  __/ \__/\ (_) | | | | ||  __/ | | | |_ 
|___/_|\__\___|\____/\___/|_| |_|\__\___|_| |_|\__|                                 
*/
siteContentID : String,

siteContent : function( area_id ) {

	if (!area_id) { area_id = om.config.area; }

	if (area_id) {

		if (om.area[area_id].type == "external") {
			window.open(om.area[area_id].url,"_blank");
		} else {
			om.contentClearAndGoLoadingState( "lonnekeContent" );
			om.config.area = area_id;
			om.contentClearAndGoLoadingState();
			om.contentSetSize( om.area[area_id].width );
			om.contentSetBackground( area_id );
			switch( om.area[area_id].type ) {
				case "html":
					om.contentSetActive( "body" );
					om.contentRequestText( om.config.url_content + area_id + '/' + om.config.language + ".html" );
					break;
				case "iframe":
					om.contentSetActive( "bodyiframe" );
					om.setupBodyIFrame( om.area[area_id].url );
					break;
				case "articles":
					om.contentSetActive( "body" );
					omC.articles.init(om.bC , om.config.altLang );
					break;
				case "tiles":
					om.contentSetActive( "body" );
					omC.tiles.init(om.bC , om.config.altLang );
					break;
				case "page":
					om.contentSetActive( "body" );
					omC.page.init(om.bC , om.config.altLang );
					break;
				case "wallpapers":
					om.contentSetActive( "body" );
					omC.wallpapers.init(om.bC , om.config.altLang );
					break;
				case "swf":
					om.contentSetActive( "bodyflash" );
					om.setupBodySWF("assets/swf/" + om.area[area_id].swf + ".swf");
					break;
				case "guestbook":
					om.contentSetActive( "fixedflashandhtml" );
					om.setupFixedSWF("assets/swf/" + om.area[area_id].swf + ".swf", om.area[area_id].width, om.area[area_id].height);
					omC.guestbook.init(om.bC , om.config.altLang );
					break;
				case "theater":
					om.contentSetActive( "body" );
					omC.theater.init(om.bC , om.config.altLang );
					break;
				}
			}
		}
	},
	
	contentSetBackground : function( area_id ) {
		if ( om.area[area_id].backgroundImage!==undefined && om.area[area_id].backgroundImage.length>0) {
			om.bgC.setStyle( {backgroundImage:"url("+om.area[area_id].backgroundImage+")"} );
			if (om.area[area_id].backgroundRepeat!==undefined && om.area[area_id].backgroundRepeat.length>0) {
				om.bgC.setStyle( {backgroundRepeat:om.area[area_id].backgroundRepeat} );
				}
			if (om.area[area_id].backgroundPosition!==undefined && om.area[area_id].backgroundPosition.length>0) {
				om.bgC.setStyle( {backgroundPosition:om.area[area_id].backgroundPosition} );
				}
			om.bgC.show();
		} else {
			om.bgC.setStyle( {backgroundImage:""} );
			om.bgC.hide();
			}
		},

	contentGetActive : String,

	contentSetActive : function( type ) {
		om.contentGetActive = type;
		switch( type ) {
			case "body":
				om.bC.show();
				om.biC.hide();
				om.bfC.hide();
				// body container in front
//				om.bC.style.zIndex = "5000";
//				om.biC.style.zIndex = "4000";
//				om.bfC.style.zIndex = "3000";	
				break;
			case "bodyflash":
				om.bC.hide();
				om.biC.hide();
				om.bfC.show();
				// body flash container in front
				om.bfC.style.zIndex = "5000";
				om.biC.style.zIndex = "4000";
				om.bC.style.zIndex = "3000";	
				break;
			case "fixedflashandhtml":
				om.bC.show();
				om.biC.hide();
				om.bfC.show();
				// body flash container in front
				om.bfC.style.zIndex = "5000";
				om.biC.style.zIndex = "4000";
				om.bC.style.zIndex = "3000";	
				break;
			case "bodyiframe":
				om.bC.hide();
				om.biC.show();
				om.bfC.hide();
				// body iframe container in front
				om.biC.style.zIndex = "5000";
				om.bfC.style.zIndex = "4000";
				om.bC.style.zIndex = "3000";
				break;
			}
		},

	contentSetSize : function( ) {
	
		var width = 0;
		var height = 0;
	
		if (om.area[om.config.area] != undefined) {
			if (om.area[om.config.area].width != undefined) {
				width=om.area[om.config.area].width;
				}
			if (om.area[om.config.area].height != undefined) {
				height=om.area[om.config.area].height;
				}
			}
			
		if (!om.bCwidth) { om.bCwidth=0; }

		if (width!=null) {
			if (width==0) {
				if (om.vW!=null & om.vW>0) {
					om.bCwidth = om.vW;
					}
			} else if (width>0) {
				om.bCwidth = width;
				}
			}

		if (om.vH>0) {
			om.bgC.style.height = (om.vH - 190 - height) + "px";
			om.bgC.style.top = (20 + height) + "px";
			if (height>0) {
				om.bC.style.height = (om.vH - 190 - height) + "px";
				om.bfC.style.height = height + "px";
				om.bC.style.top = (20 + height) + "px";
			} else {
				om.bC.style.height = (om.vH - 190) + "px";
				om.bfC.style.height = (om.vH - 180) + "px";
				om.bC.style.top = "20px";
				}
			}

		if (om.bCwidth>0) {
			om.bC.style.width = om.bCwidth + "px";
			om.bfC.style.width = om.bCwidth + "px";
			}

		if (om.bCwidth>0 && om.vW>0) {
			om.bC.style.left = ( ( om.vW - om.bCwidth ) / 2 ) + "px";
			om.bfC.style.left = ( ( om.vW - om.bCwidth ) / 2 ) + "px";
			}
			
		},

	contentClearAndGoLoadingState : function() {
		om.bC.update();
		om.setupBodySWF();
		om.setupBodyIFrame();
//		om.bC.update("loading...");
		},

	contentRequestText : function( url ) {
		new Ajax.Request( url, {
				method: "post",
				onComplete: om.contentReceiveText,
				parameters: om.config
				});
		},
		
		contentReceiveText : function( ajaxresponse ) {
			if ( ajaxresponse.status == 200 ) {
				om.bC.update( ajaxresponse.responseText.replace( "[url_content]", om.config.url_content + om.config.area + "/" ) );
			} else {
				if(om.debugOn){ om.debug("<strong>XML| http fail / code " + ajaxresponse.status + "<br/></strong>"); }
				}
	
			},
/*




     _      _                 
    | |    | |                
  __| | ___| |__  _   _  __ _ 
 / _` |/ _ \ '_ \| | | |/ _` |
| (_| |  __/ |_) | |_| | (_| |
 \__,_|\___|_.__/ \__,_|\__, |
                         __/ |
                        |___/ 
*/
	
	initDebug : function() {
		om.debugOn = true;
		$("debug_holder").style.display = "block";
		$("debug_controls").style.display = "block";
		$("debug_scroller").style.display = "block";
		$("debug_fixed").style.display = "block";
		om.dScroller = $("debug_scroller");
		om.dFixedA = $("debug_fixed_A");
		om.dFixedB = $("debug_fixed_B");
		},

	debugOn : Boolean,

	debug: function(strS, strA, strB) {
		if ( strS != null && om.dScroller != undefined ) { om.dScroller.innerHTML = strS + "<br/>" + om.dScroller.innerHTML; }
		if ( strA != null && om.dFixedA != undefined ) { om.dFixedA.innerHTML = strA; }
		if ( strB != null && om.dFixedB != undefined ) { om.dFixedB.innerHTML = strB; }
		},

	dScroller : Object,
	dFixedA : Object,
	dFixedB : Object,
/*




______ ________  ___
|  _  \  _  |  \/  |
| | | | | | | .  . |
| | | | | | | |\/| |
| |/ /\ \_/ / |  | |
|___/  \___/\_|  |_/

*/
	dom : {
		prune: function( obj, conformArray ) {
			// force the children of obj to be the elements by id conformArray, in that order, and kill any others.
			// kill elements not on the list
			for ( i=0; i<obj.childNodes.length; i++ ) {
				if ( obj.childNodes[i].id != undefined && conformArray.indexOf( obj.childNodes[i].id ) < 0 ) {
					obj.childNodes[i].remove();
					if(om.debugOn){ om.debug( "removed " + obj.childNodes[i].id); }
				} else {
					}
				}
			// place a "rake" span at position 0.
			var my_firstChild = obj.firstChild;
			var my_Rake = new Element( "span" );
			obj.insertBefore(my_Rake, my_firstChild);
			// organize the elements which are in our list
			for ( var i=0; i<conformArray.length; i++ ) {
				obj.insertBefore( $(conformArray[i]), my_Rake );
				}
			// kill the rake
			my_Rake.remove();
			}
	}
/*









 _ _ _   _   _        _          _                     
| (_) | | | | |      | |        | |                    
| |_| |_| |_| | ___  | |__   ___| |_ __   ___ _ __ ___ 
| | | __| __| |/ _ \ | '_ \ / _ \ | '_ \ / _ \ '__/ __|
| | | |_| |_| |  __/ | | | |  __/ | |_) |  __/ |  \__ \
|_|_|\__|\__|_|\___| |_| |_|\___|_| .__/ \___|_|  |___/
                                  | |                  
                                  |_|                  

*/
	};