/*
###
###                               
###    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 omC = {

altLang : String,
/*
                        
 _ __   __ _  __ _  ___ 
| '_ \ / _` |/ _` |/ _ \
| |_) | (_| | (_| |  __/
| .__/ \__,_|\__, |\___|
| |           __/ |     
|_|          |___/                               
*/
page : {
	
		base : Object,
		baseOne : Object,
		
		init : function( baseObj, altLang ) {
			omC.altLang = altLang ? altLang : "";
			omC.page.base = baseObj;
			omC.page.requestXML( om.config.url_content + om.config.area + "/publish.xml?refresh=" + Math.floor(Math.random()*9999).toString() );
			omC.page.baseOne = new Element( "div" , { id:"omC_pOne" } ).hide(); omC.page.base.appendChild( omC.page.baseOne );
			},

		requestXML : function( url_xml ) {
			new Ajax.Request( url_xml, {
					method: "post",
					onComplete: omC.page.receiveXML
					});
			},
			
		receiveXML : function( ajaxresponse ) {
			omC.ingestAreaXML( ajaxresponse );
			omC.page.setup("one");
			},

		setup : function( template, entry_id, paragraph ) {
		
			var el1, el2, el3, el4, el5, el6, el7, el8, el9;
			var clickTop, clickBtm;
			var curY, curH, myH, curP, panelHeight, startP;
			var procEnd;
			var procStart;
			
			if (!entry_id) { entry_id=1; }

			// meta_title
			var myHeadline = omC.hashEntry.get(entry_id+".meta_title"+omC.altLang); // start with the alternate language
			if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(entry_id+".meta_title"); } // go back to beginning if null or unnecessary

			// meta_text
			var myText = omC.hashEntry.get(entry_id+".meta_text"+omC.altLang); // start with the alternate language
			if (!omC.altLang || !myText) { myText = omC.hashEntry.get(entry_id+".meta_text"); } // go back to beginning if null or unnecessary

			if (!myText || !myHeadline) {

				// if something's wrong, re-initialize
//				om.siteContent();

			} else {

				// otherwise, go ahead
				omC.page.baseOne.hide();
	
				switch( template ) {
					case "one":
						omC.page.baseOne.update();
	
						// init paragraphs
						curP = 0;
						curH = 0;
						if(paragraph==undefined) {
							var startP = 0;
						} else {
							var startP = paragraph;
							}
						procEnd = false;
						procStart = false;
						
						panelHeight = omC.page.baseOne.getHeight();
	
						// a
						el1 = new Element( "a", { id:"omC_oIA" } ); omC.page.baseOne.appendChild( el1 );
							// img
							el2 = new Element( "img", { id:"omC_oI", src: om.config.url_content + om.config.area + "/" + entry_id + "_large.jpg" } ); el1.appendChild( el2 );
						// div
						el1 = new Element( "div", { id:"omC_oCC" } ); omC.page.baseOne.appendChild( el1 );
							// h2
							el3 = new Element( "p" ).update( myHeadline ).addClassName("headline"); el1.appendChild( el3 );
	
							// span
							el3 = new Element( "span" ).update( omC.util.entryDate( entry_id ) ).addClassName("sub"); el1.appendChild( el3 );
							myText.split("\n").each(function(_p){
								if ( (curP >= startP) && !procEnd ) {
									// FOR EACH PARAGRAPH after the start point
									// p
									el3 = new Element( "p" ).update( _p ); el1.appendChild( el3 );
									
									myH = (_p.length / 50 ) * 13 + 26; // calculated from text
	//								alert( "( (!"+procStart+") || ( ( " + curH + " + " + myH + " ) <= ( " + panelHeight + " - 120 ) ) )" )
									if ( (!procStart) || ( ( curH + myH ) <= ( panelHeight - 120 ) ) ) {
										// there's enough room for this next paragraph
										procStart = true;
										curH += myH;
									} else {
										// there's not enough room to add another
										el3.remove();
										procEnd = true;
										clickBtm = new Element( "a", { href:"javascript:omC.page.setup('one',1," + curP + ");" } ).addClassName("more").update( "more..." ); el1.appendChild( clickBtm );
										$('omC_oIA').setAttribute("href", "javascript:omC.page.setup('one',1," + curP + ");");
										}
									}
								
								curP++;
								});
	
						if (!procEnd) {
							clickBtm = new Element( "a", { href:"javascript:omC.page.setup('one',1);" } ).addClassName("more").update( "back to the beginning" ); el1.appendChild( clickBtm );
							$('omC_oIA').setAttribute("href", "javascript:omC.page.setup('one',1);");
							}
	
						omC.page.baseOne.show();
						break;
					}
				}
			},
			
		go : function( template, entry_id ) {
			switch( template ) {
				case "one":
					omC.page.baseOne.show();
					break;
				}
			}
	
	},
/*

            _   _      _           
           | | (_)    | |          
  __ _ _ __| |_ _  ___| | ___  ___ 
 / _` | '__| __| |/ __| |/ _ \/ __|
| (_| | |  | |_| | (__| |  __/\__ \
 \__,_|_|   \__|_|\___|_|\___||___/                                   
*/
articles : {
	
		base : Object,
		baseIndex : Object,
		baseOne : Object,
		
		init : function( baseObj, altLang ) {
			omC.altLang = altLang ? altLang : "";
			omC.articles.base = baseObj;
			omC.articles.requestXML( om.config.url_content + om.config.area + "/publish.xml?refresh=" + Math.floor(Math.random()*9999).toString() );
			omC.articles.baseIndex = new Element( "div" , { id:"omC_aIndex" } ).hide(); omC.articles.base.appendChild( omC.articles.baseIndex );
			omC.articles.baseIndexPages = new Element( "div" , { id:"omC_aIndexPages" } ).hide(); omC.articles.base.appendChild( omC.articles.baseIndexPages );
			omC.articles.baseOne = new Element( "div" , { id:"omC_aOne" } ).addClassName("omC_aOne_" + om.config.area + " omC_aOne").hide(); omC.articles.base.appendChild( omC.articles.baseOne );
			},

		requestXML : function( url_xml ) {
			new Ajax.Request( url_xml, {
					method: "post",
					onComplete: omC.articles.receiveXML
					});
			},
			
		receiveXML : function( ajaxresponse ) {
			omC.ingestAreaXML( ajaxresponse );
			omC.articles.setup("index");
			},

		setup : function( template, entry_id, page, paragraph ) {
			var el1, el2, el3, el4, el5, el6, el7, el8, el9;
			var clickTop, clickBtm;
			var curY, curH, myH, curP, panelHeight, startP;
			var procEnd;
			var procStart;
		
			omC.articles.baseIndex.hide();
			omC.articles.baseIndexPages.hide();
			omC.articles.baseOne.hide();

			switch( template ) {
				case "index":
					omC.articles.baseIndex.update();
					var curY = 0;
					var thisIndex = 0;

					var itemsPerPage = Math.floor( omC.articles.baseIndex.getHeight() / 85 );
					var maxPage = Math.ceil( omC.indexEntry.length / itemsPerPage ) - 1;
					if(page==undefined) {
						var curPage = 0;
					} else {
						var curPage = Math.min(maxPage, page);
						}

					// populate index
					omC.indexGroup.each(function(_id){
						// throw a group header here if we like
						omC.hashGroup.get(_id+".publish_contents").split(",").each(function(_id){
							// if this one is on the current page
							if ( thisIndex >= ( curPage * itemsPerPage ) && thisIndex < ( ( curPage + 1 ) * itemsPerPage ) ) {

								// get headline
								var myHeadline = omC.hashEntry.get(_id+".meta_title"+omC.altLang); // start with the alternate language
								if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(_id+".meta_title"); } // go back to beginning if null or unnecessary

								// div entry container
								el1 = new Element( "div", { id:"omC_aD_" + _id, onclick:"omC.articles.setup('one','" + _id + "'," + curPage + ");" } ).addClassName("omC_aD").addClassName("omC_aD_"+om.config.area); omC.articles.baseIndex.appendChild( el1 );
								el1.style.top = curY + "px";
								curY += 85;
									// div
									el2 = new Element( "div", { valign:"top", align:"left" } ).addClassName("L"); el1.appendChild( el2 );
										// a href:javascript
										el3 = new Element( "a", { href: "javascript:omC.articles.setup('one','" + _id + "'," + curPage + ");" } ); el2.appendChild( el3 );
											// img
											el4 = new Element( "img", { src: om.config.url_content + om.config.area + "/" + _id + "_index.jpg" } ); el3.appendChild( el4 );
									// div
									el2 = new Element( "div", { valign:"top", align:"left" } ).addClassName("R"); el1.appendChild( el2 );
										// a href:javascript
										el3 = new Element( "a", { href: "javascript:omC.articles.setup('one','" + _id + "'," + curPage + ");" } ); el2.appendChild( el3 );
											// a
											el4 = new Element( "p", { valign: "top" } ).update( myHeadline ).addClassName("item"); el3.appendChild( el4 );
								}
							thisIndex++;
							});
						});
						
					// populate index pages
					omC.articles.baseIndexPages.update();
					if (maxPage>1) {
						for ( var i=0; i<=maxPage; i++ ) {
							el1 = new Element( "a", { href:"javascript:omC.articles.setup('index',null," + i.toString() + ");" } ).update( i+1 );
							if ( i == curPage ) { el1.addClassName("on"); }
							omC.articles.baseIndexPages.appendChild(el1);
							}
						}
						
					omC.articles.baseIndex.show();
					omC.articles.baseIndexPages.show();
					break;
				case "one":
					omC.articles.baseOne.update();
					// init paragraphs
					curP = 0;
					curH = 0;
					if(paragraph==undefined) {
						var startP = 0;
					} else {
						var startP = paragraph;
						}
					procEnd = false;
					procStart = false;
					
					panelHeight = omC.articles.baseOne.getHeight();

					// get headline
					var myHeadline = omC.hashEntry.get(entry_id+".meta_title"+omC.altLang); // start with the alternate language
					if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(entry_id+".meta_title"); } // go back to beginning if null or unnecessary

					// get text
					var myText = omC.hashEntry.get(entry_id+".meta_text"+omC.altLang); // start with the alternate language
					if (!omC.altLang || !myText) { myText = omC.hashEntry.get(entry_id+".meta_text"); } // go back to beginning if null or unnecessary

					// a
					el1 = new Element( "div", { id:"omC_oIL" } ); omC.articles.baseOne.appendChild( el1 );
						// a
						el2 = new Element( "a", { id:"omC_oIA" } ); el1.appendChild( el2 );
							// img
							el3 = new Element( "img", { id:"omC_oI", src: om.config.url_content + om.config.area + "/" + entry_id + "_large.jpg" } ); el2.appendChild( el3 );
						// link A
						var myLinkURL = omC.hashEntry.get(entry_id+".meta_linkA_url");
						if (myLinkURL != undefined) {
							var myLinkName = omC.hashEntry.get(entry_id+".meta_linkA_title");
							if (myLinkName == undefined) { myLinkName = myLinkURL; }
							// a
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "a", { href:myLinkURL, target:'_blank' }).addClassName('presslink').update(myLinkName); el1.appendChild( el2 );
							}
						// link B
						var myLinkURL = omC.hashEntry.get(entry_id+".meta_linkB_url");
						if (myLinkURL != undefined) {
							var myLinkName = omC.hashEntry.get(entry_id+".meta_linkB_title");
							if (myLinkName == undefined) { myLinkName = myLinkURL; }
							// a
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "a", { href:myLinkURL, target:'_blank' }).addClassName('presslink').update(myLinkName); el1.appendChild( el2 );
							}
						// link C
						var myLinkURL = omC.hashEntry.get(entry_id+".meta_linkC_url");
						if (myLinkURL != undefined) {
							var myLinkName = omC.hashEntry.get(entry_id+".meta_linkC_title");
							if (myLinkName == undefined) { myLinkName = myLinkURL; }
							// a
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "a", { href:myLinkURL, target:'_blank' }).addClassName('presslink').update(myLinkName); el1.appendChild( el2 );
							}
							


					// div
					el1 = new Element( "div", { id:"omC_oCC" } ); omC.articles.baseOne.appendChild( el1 );
						// h2
						el3 = new Element( "p" ).update( myHeadline ).addClassName("headline"); el1.appendChild( el3 );

						// span
						el3 = new Element( "span" ).update( omC.util.entryDate( entry_id ) ).addClassName("sub"); el1.appendChild( el3 );
						myText.split("\n").each(function(_p){
							if ( (curP >= startP) && !procEnd ) {
								// FOR EACH PARAGRAPH after the start point
								// p
								el3 = new Element( "p" ).update( _p ); el1.appendChild( el3 );
								
								myH = 160; // default
								myH = (_p.length / 50 ) * 13 + 26; // calculated from text
//								alert( "( (!"+procStart+") || ( ( " + curH + " + " + myH + " ) <= ( " + panelHeight + " - 120 ) ) )" )
								if ( (!procStart) || ( ( curH + myH ) <= ( panelHeight - 120 ) ) ) {
									// there's enough room for this next paragraph
									procStart = true;
									curH += myH;
								} else {
									// there's not enough room to add another
									el3.remove();
									procEnd = true;
									clickBtm = new Element( "a", { href:"javascript:omC.articles.setup('one'," + entry_id + "," + page + "," + curP + ");" } ).addClassName("more").update( "more..." ); el1.appendChild( clickBtm );
									$('omC_oIA').setAttribute("href", "javascript:omC.articles.setup('one'," + entry_id + "," + page + "," + curP + ");");
									}
								}
							
							curP++;
							});

					if (!procEnd) {
						clickBtm = new Element( "a", { href:"javascript:omC.articles.setup('index'," + entry_id + "," + page + ");" } ).addClassName("more").update( "back to the articles" ); el1.appendChild( clickBtm );
						$('omC_oIA').setAttribute("href", "javascript:omC.articles.setup('index'," + entry_id + "," + page + ");");
						}

					omC.articles.baseOne.show();
					break;
				}
			},
			
		go : function( template, entry_id ) {
			switch( template ) {
				case "index":
					omC.articles.baseIndex.show();
					omC.articles.baseIndexPages.show();
					omC.articles.baseOne.hide();
					break;
				case "one":
					omC.articles.baseOne.show();
					omC.articles.baseIndex.hide();
					omC.articles.baseIndexPages.hide();
					break;
				}
			}
	
	},

/*


 _   _                _            
| | | |              | |           
| |_| |__   ___  __ _| |_ ___ _ __ 
| __| '_ \ / _ \/ _` | __/ _ \ '__|
| |_| | | |  __/ (_| | ||  __/ |   
 \__|_| |_|\___|\__,_|\__\___|_|   
*/
theater : {
	
		base : Object,
		baseIndex : Object,
		baseOne : Object,
		
		init : function( baseObj, altLang ) {
			omC.altLang = altLang ? altLang : "";
			omC.theater.base = baseObj;
			omC.theater.requestXML( om.config.url_content + om.config.area + "/publish.xml?refresh=" + Math.floor(Math.random()*9999).toString() );
			omC.theater.baseIndex = new Element( "div" , { id:"omC_vIndex" } ).hide(); omC.theater.base.appendChild( omC.theater.baseIndex );
			omC.theater.baseIndexPages = new Element( "div" , { id:"omC_vIndexPages" } ).hide(); omC.theater.base.appendChild( omC.theater.baseIndexPages );
			omC.theater.baseOne = new Element( "div" , { id:"omC_vOne" } ).addClassName("omC_vOne_" + om.config.area + " omC_vOne").hide(); omC.theater.base.appendChild( omC.theater.baseOne );
			},

		requestXML : function( url_xml ) {
			new Ajax.Request( url_xml, {
					method: "post",
					onComplete: omC.theater.receiveXML
					});
			},
			
		receiveXML : function( ajaxresponse ) {
			omC.ingestAreaXML( ajaxresponse );
			omC.theater.setup("index");
			},

		setup : function( template, entry_id, page, paragraph ) {
			var el1, el2, el3, el4, el5, el6, el7, el8, el9;
			var clickTop, clickBtm;
			var curY, curH, myH, curP, panelHeight, startP;
			var procEnd;
			var procStart;
		
			omC.theater.baseIndex.hide();
			omC.theater.baseIndexPages.hide();
			omC.theater.baseOne.hide();

			switch( template ) {
				case "index":
					omC.theater.baseIndex.update();
					var curY = 0;
					var thisIndex = 0;

					var itemsPerPage = Math.floor( omC.theater.baseIndex.getHeight() / 105 );
					var maxPage = Math.ceil( omC.indexEntry.length / itemsPerPage ) - 1;
					if(page==undefined) {
						var curPage = 0;
					} else {
						var curPage = Math.min(maxPage, page);
						}

					// populate index
					omC.indexGroup.each(function(_id){
						// throw a group header here if we like
						omC.hashGroup.get(_id+".publish_contents").split(",").each(function(_id){
							// if this one is on the current page
							if ( thisIndex >= ( curPage * itemsPerPage ) && thisIndex < ( ( curPage + 1 ) * itemsPerPage ) ) {

								// get headline
								var myHeadline = omC.hashEntry.get(_id+".meta_title"+omC.altLang); // start with the alternate language
								if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(_id+".meta_title"); } // go back to beginning if null or unnecessary

								// div entry container
								el1 = new Element( "div", { id:"omC_vD_" + _id, onclick:"omC.theater.setup('one','" + _id + "'," + curPage + ");" } ).addClassName("omC_vD").addClassName("omC_vD_"+om.config.area); omC.theater.baseIndex.appendChild( el1 );
								el1.style.top = curY + "px";
								curY += 105;
									// div
									el2 = new Element( "div", { valign:"top", align:"left" } ).addClassName("L"); el1.appendChild( el2 );
										// a href:javascript
										el3 = new Element( "a", { href: "javascript:omC.theater.setup('one','" + _id + "'," + curPage + ");" } ); el2.appendChild( el3 );
											// img
											el4 = new Element( "img", { src: om.config.url_content + om.config.area + "/" + _id + "_thumb.jpg" } ); el3.appendChild( el4 );
									// div
									el2 = new Element( "div", { valign:"top", align:"left" } ).addClassName("R"); el1.appendChild( el2 );
										// a href:javascript
										el3 = new Element( "a", { href: "javascript:omC.theater.setup('one','" + _id + "'," + curPage + ");" } ); el2.appendChild( el3 );
											// a
											el4 = new Element( "p", { valign: "top" } ).update( myHeadline ).addClassName("item"); el3.appendChild( el4 );
								}
							thisIndex++;
							});
						});
						
					// populate index pages
					omC.theater.baseIndexPages.update();
					if (maxPage>1) {
						for ( var i=0; i<=maxPage; i++ ) {
							el1 = new Element( "a", { href:"javascript:omC.theater.setup('index',null," + i.toString() + ");" } ).update( i+1 );
							if ( i == curPage ) { el1.addClassName("on"); }
							omC.theater.baseIndexPages.appendChild(el1);
							}
						}
						
					omC.theater.baseIndex.show();
					omC.theater.baseIndexPages.show();
					break;
				case "one":
					omC.theater.baseOne.update();
					// init paragraphs
					curP = 0;
					curH = 0;
					if(paragraph==undefined) {
						var startP = 0;
					} else {
						var startP = paragraph;
						}
					procEnd = false;
					procStart = false;
					
					panelHeight = omC.theater.baseOne.getHeight();

					// get headline
					var myHeadline = omC.hashEntry.get(entry_id+".meta_title"+omC.altLang); // start with the alternate language
					if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(entry_id+".meta_title"); } // go back to beginning if null or unnecessary

					// div
					el1 = new Element( "div", { id:"omC_oCC" } ); omC.theater.baseOne.appendChild( el1 );

					// go back link
					el2 = new Element( "a", { id:"omC_oCC_goBack", href:"javascript:omC.theater.setup('index'," + entry_id + "," + page + ");" } ).update("go back to the videos"); el1.appendChild( el2 );

					// youtube player
					om.setupYouTubeSWF("omC_oCC", omC.hashEntry.get(entry_id+".youtube_id"),790,400);


					omC.theater.baseOne.show();
					break;
				}
			},
			
		go : function( template, entry_id ) {
			switch( template ) {
				case "index":
					omC.theater.baseIndex.show();
					omC.theater.baseIndexPages.show();
					omC.theater.baseOne.hide();
					break;
				case "one":
					omC.theater.baseOne.show();
					omC.theater.baseIndex.hide();
					omC.theater.baseIndexPages.hide();
					break;
				}
			}
	
	},

/*
                       _   _                 _    
                      | | | |               | |   
  __ _ _   _  ___  ___| |_| |__   ___   ___ | | __
 / _` | | | |/ _ \/ __| __| '_ \ / _ \ / _ \| |/ /
| (_| | |_| |  __/\__ \ |_| |_) | (_) | (_) |   < 
 \__, |\__,_|\___||___/\__|_.__/ \___/ \___/|_|\_\
  __/ |                                           
 |___/                                      
*/
guestbook : {
	
		base : Object,
		baseIndex : Object,
		baseOne : Object,
		
		init : function( baseObj, altLang ) {
			omC.altLang = altLang ? altLang : "";
			omC.guestbook.base = baseObj;
			omC.guestbook.requestXML( om.config.url_content + om.config.area + "/publish.xml?refresh=" + Math.floor(Math.random()*9999).toString() );
			omC.guestbook.baseIndex = new Element( "div" , { id:"omC_gIndex" } ).hide(); omC.guestbook.base.appendChild( omC.guestbook.baseIndex );
			omC.guestbook.baseIndexPages = new Element( "div" , { id:"omC_gIndexPages" } ).hide(); omC.guestbook.base.appendChild( omC.guestbook.baseIndexPages );
			omC.guestbook.baseOne = new Element( "div" , { id:"omC_gOne" } ).hide(); omC.guestbook.base.appendChild( omC.guestbook.baseOne );
			},

		requestXML : function( url_xml ) {
			new Ajax.Request( url_xml, {
					method: "post",
					onComplete: omC.guestbook.receiveXML
					});
			},
			
		receiveXML : function( ajaxresponse ) {
			omC.ingestAreaXML( ajaxresponse );
			omC.guestbook.setup("index");
			},

		setup : function( template, entry_id, page, paragraph ) {
			var el1, el2, el3, el4, el5, el6, el7, el8, el9;
			var clickTop, clickBtm;
			var curY, curH, myH, curP, panelHeight, startP;
			var procEnd;
			var procStart;
		
			omC.guestbook.baseIndex.hide();
			omC.guestbook.baseIndexPages.hide();
			omC.guestbook.baseOne.hide();

			switch( template ) {
				case "index":
					omC.guestbook.baseIndex.update();
					var curY = 25;
					var thisIndex = 0;

					var itemsPerPage = Math.floor( omC.guestbook.baseIndex.getHeight() / 85 );
					var maxPage = Math.ceil( omC.indexEntry.length / itemsPerPage ) - 1;
					if(page==undefined) {
						var curPage = 0;
					} else {
						var curPage = Math.min(maxPage, page);
						}

//					alert( "omC.guestbook.baseIndex.getHeight()" + omC.guestbook.baseIndex.getHeight() + "\nitemsPerPage:"+itemsPerPage+"\nmaxPage:"+maxPage+"\ncurPage:"+curPage);

					var myGuestbookScroll = "";

					// populate index
					omC.indexEntry.each(function(_id){
						// if this one is on the current page
						if ( thisIndex >= ( curPage * itemsPerPage ) && thisIndex < ( ( curPage + 1 ) * itemsPerPage ) ) {

							// get headline
							var myText = omC.hashEntry.get(_id+".meta_text"+omC.altLang); // start with the alternate language
							if (!omC.altLang || !myText) { myText = omC.hashEntry.get(_id+".meta_text"); } // go back to beginning if null or unnecessary

							// add to buffer
							myGuestbookScroll += ("<p>"+myText+"</p>");
							}

						thisIndex++;
						});

					// div entry container
					omC.guestbook.baseIndex.update( myGuestbookScroll );

					// populate index pages
					omC.guestbook.baseIndexPages.update();
/*
					for ( var i=0; i<=maxPage; i++ ) {
						el1 = new Element( "a", { href:"javascript:omC.guestbook.setup('index',null," + i.toString() + ");" } ).update( i+1 );
						if ( i == curPage ) { el1.addClassName("on"); }
						omC.guestbook.baseIndexPages.appendChild(el1);
						}
*/
					if ( curPage > 0 ) {
						el1 = new Element( "a", { href:"javascript:omC.guestbook.setup('index',null," + (curPage-1).toString() + ");" } ).update( "newer&nbsp;entries" );
						omC.guestbook.baseIndexPages.appendChild(el1);
						}					

					if ( curPage > 0 && curPage < maxPage) {
						el1 = new Element( "span" ).addClassName("centerwait").setStyle({fontWeight:"bold"}).update( "&nbsp;/&nbsp;" );
						omC.guestbook.baseIndexPages.appendChild(el1);
						}

					if ( curPage < maxPage ) {
						el1 = new Element( "a", { href:"javascript:omC.guestbook.setup('index',null," + (curPage+1).toString() + ");" } ).update( "previous&nbsp;entries" );
						omC.guestbook.baseIndexPages.appendChild(el1);
						}


					omC.guestbook.baseIndex.show();
					omC.guestbook.baseIndexPages.show();
					break;

				}
			},
			
		go : function( template, entry_id ) {
			switch( template ) {
				case "index":
					omC.guestbook.baseIndex.show();
					omC.guestbook.baseIndexPages.show();
					omC.guestbook.baseOne.hide();
					break;
				case "one":
					omC.guestbook.baseOne.show();
					omC.guestbook.baseIndex.hide();
					omC.guestbook.baseIndexPages.hide();
					break;
				}
			}
	
	},

/*


 _   _ _           
| | (_) |          
| |_ _| | ___  ___ 
| __| | |/ _ \/ __|
| |_| | |  __/\__ \
 \__|_|_|\___||___/                   
*/
tiles : {
	
		base : Object,
		baseIndex : Object,
		baseOne : Object,
		color_L : String,
		color_M : String,
		color_H : String,
		color_Ta : String,
		color_Tb : String,

		init : function( baseObj, altLang) {
			omC.altLang = altLang ? altLang : "";
			omC.tiles.base = baseObj;
			omC.tiles.requestXML( om.config.url_content + om.config.area + "/publish.xml?refresh=" + Math.floor(Math.random()*9999).toString() );
			omC.tiles.baseIndex = new Element( "div" , { id:"omC_tIndex" } ).hide(); omC.tiles.base.appendChild( omC.tiles.baseIndex );
			omC.tiles.baseIndexPages = new Element( "div" , { id:"omC_tIndexPages" } ).hide(); omC.tiles.base.appendChild( omC.tiles.baseIndexPages );
			omC.tiles.baseOne = new Element( "div" , { id:"omC_tOne" } ).addClassName("omC_tOne_" + om.config.area + " omC_tOne").hide(); omC.tiles.base.appendChild( omC.tiles.baseOne );
			},

		requestXML : function( url_xml ) {
			new Ajax.Request( url_xml, {
					method: "post",
					onComplete: omC.tiles.receiveXML
					});
			},
			
		receiveXML : function( ajaxresponse ) {
			omC.ingestAreaXML( ajaxresponse );
			omC.tiles.setup("index");
			},

		setup : function( template, entry_id, page, paragraph ) {
			var el1, el2, el3, el4, el5, el6, el7, el8, el9;
			var clickTop, clickBtm;
			var curY, curH, myH, curP, panelHeight, startP;
			var procEnd;
			var procStart;

			switch( template ) {
				case "index":
					omC.tiles.baseIndex.hide();
					omC.tiles.baseIndexPages.hide();
					omC.tiles.baseOne.hide();
					omC.tiles.baseIndex.update();

					var itemsPerPage = Math.max(1,Math.floor( omC.tiles.baseIndex.getHeight() / 130 ))*5;
					var maxPage = Math.ceil( omC.indexEntry.length / itemsPerPage ) - 1;
					if(page==undefined) {
						var curPage = 0;
					} else {
						var curPage = Math.min(maxPage, page);
						}

					// populate index
					var publishContents = Array();
					omC.indexGroup.each(function(_id){
						omC.hashGroup.get(_id+".publish_contents").split(",").each(function(_id){
							publishContents.push(_id);
							});
						});

					// cycle through publishContents
					var _id;
					var curY = 20;
					var curX = undefined;
					for (var i=0; i<publishContents.length; i++) {
						_id = publishContents[i];
						// if this one is on the current page
						if ( i >= ( curPage * itemsPerPage ) && i < ( ( curPage + 1 ) * itemsPerPage ) ) {

							// new row
							if (curX==undefined) {
								var numLeft = publishContents.length - i;
								if (numLeft>=5) { // enough for a whole row
									curX = 0;
								} else { // setup a partial row
									curX = (5-numLeft) * 70;
									}
								}
							
							// get headline
							var myHeadline = omC.hashEntry.get(_id+".meta_title"+omC.altLang); // start with the alternate language
							if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(_id+".meta_title"); } // go back to beginning if null or unnecessary

							// div entry container
							el1 = new Element( "div", { id:"omC_tD_" + _id, onclick:"omC.tiles.setup('one','" + _id + "'," + curPage + ");" } ).addClassName("omC_tD").addClassName("omC_tD_"+om.config.area); omC.tiles.baseIndex.appendChild( el1 );
							el1.style.left = curX + "px";
							el1.style.top = curY + "px";
							
							curX += 160;
							if ( curX > 790 ) {
								curX = null;
								curY += 130;
								}

							// a
							el2 = new Element( "a", { href: "javascript:omC.tiles.setup('one','" + _id + "'," + curPage + ");" } ).addClassName( "basecontent" ); el1.appendChild( el2 );
								// img
								el3 = new Element( "img", { src: om.config.url_content + om.config.area + "/" + _id + "_tile.jpg" } ).addClassName( "basecontent" ); el2.appendChild( el3 );

							// a
							el3 = new Element( "a", { href: "javascript:omC.tiles.setup('one','" + _id + "'," + curPage + ");" } ).setStyle( {color:omC.tiles.color_Ta} ).addClassName( "toplink" ).update(myHeadline); el1.appendChild( el3 );
							// a
							el3 = new Element( "a" ).addClassName( "toplinkbox" ).setStyle( {backgroundColor:omC.tiles.color_Tb, color:omC.tiles.color_Tb} ).update(myHeadline); el1.appendChild( el3 );

							}
						}
						
					// populate index pages
					omC.tiles.baseIndexPages.update();
					if (maxPage>0) {
						for ( var i=0; i<=maxPage; i++ ) {
							el1 = new Element( "a", { href:"javascript:omC.tiles.setup('index',null," + i.toString() + ");" } ).update( i+1 );
							if ( i == curPage ) { el1.addClassName("on"); }
							omC.tiles.baseIndexPages.appendChild(el1);
							}
						}
						
					omC.tiles.baseIndex.show();
					omC.tiles.baseIndexPages.show();
					break;
				case "one":
					// get headline
					var myHeadline = omC.hashEntry.get(entry_id+".meta_title"+omC.altLang); // start with the alternate language
					if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(entry_id+".meta_title"); } // go back to beginning if null or unnecessary

					// get text
					var myText = omC.hashEntry.get(entry_id+".meta_text"+omC.altLang); // start with the alternate language
					if (!omC.altLang || !myText) { myText = omC.hashEntry.get(entry_id+".meta_text"); } // go back to beginning if null or unnecessary

					if (myText!==undefined && myText.length>0) {

						omC.tiles.baseIndex.hide();
						omC.tiles.baseIndexPages.hide();
						omC.tiles.baseOne.hide();
						omC.tiles.baseOne.update();
						// init paragraphs
						curP = 0;
						curH = 0;
						if(paragraph==undefined) {
							var startP = 0;
						} else {
							var startP = paragraph;
							}
						procEnd = false;
						procStart = false;
						
						panelHeight = omC.tiles.baseOne.getHeight();
						
						// a
						el1 = new Element( "div", { id:"omC_oIL" } ); omC.tiles.baseOne.appendChild( el1 );
							// a
							el2 = new Element( "a", { id:"omC_oIA" } ); el1.appendChild( el2 );
								// img
								el3 = new Element( "img", { id:"omC_oI", src: om.config.url_content + om.config.area + "/" + entry_id + "_large.jpg" } ); el2.appendChild( el3 );	
	
						// div
						el1 = new Element( "div", { id:"omC_oCC" } ); omC.tiles.baseOne.appendChild( el1 );
							// h2
							el3 = new Element( "p" ).update( myHeadline ).addClassName("headline"); el1.appendChild( el3 );
	
							// span
							el3 = new Element( "span" ).update( omC.util.entryDate( entry_id ) ).addClassName("sub"); el1.appendChild( el3 );
							myText.split("\n").each(function(_p){
								if ( (curP >= startP) && !procEnd ) {
									// FOR EACH PARAGRAPH after the start point
									// p
									el3 = new Element( "p" ).update( _p ); el1.appendChild( el3 );
									
									myH = 160; // default
									myH = (_p.length / 50 ) * 13 + 26; // calculated from text
	//								alert( "( (!"+procStart+") || ( ( " + curH + " + " + myH + " ) <= ( " + panelHeight + " - 120 ) ) )" )
									if ( (!procStart) || ( ( curH + myH ) <= ( panelHeight - 120 ) ) ) {
										// there's enough room for this next paragraph
										procStart = true;
										curH += myH;
									} else {
										// there's not enough room to add another
										el3.remove();
										procEnd = true;
										clickBtm = new Element( "a", { href:"javascript:omC.tiles.setup('one'," + entry_id + "," + page + "," + curP + ");" } ).addClassName("more").update( "more..." ); el1.appendChild( clickBtm );
										$('omC_oIA').setAttribute("href", "javascript:omC.tiles.setup('one'," + entry_id + "," + page + "," + curP + ");");
										}
									}
								
								curP++;
								});
	
						if (!procEnd) {
							clickBtm = new Element( "a", { href:"javascript:omC.tiles.setup('index'," + entry_id + "," + page + ");" } ).addClassName("more").update( "back to " + om.config.area + " area" ); el1.appendChild( clickBtm );
							$('omC_oIA').setAttribute("href", "javascript:omC.tiles.setup('index'," + entry_id + "," + page + ");");
							}

						// link A
						var myLinkURL = omC.hashEntry.get(entry_id+".meta_linkA_url"+omC.altLang); // start with the alternate language
						if (!omC.altLang || !myLinkURL) { myLinkURL = omC.hashEntry.get(entry_id+".meta_linkA_url"); } // go back to beginning if null or unnecessary
						if (myLinkURL != undefined) {
							var myLinkName = omC.hashEntry.get(entry_id+".meta_linkA_title"+omC.altLang); // start with the alternate language
							if (!omC.altLang || !myLinkName) { myLinkName = omC.hashEntry.get(entry_id+".meta_linkA_title"); } // go back to beginning if null or unnecessary

							if (myLinkName == undefined) { myLinkName = myLinkURL; }
							// a
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "br" ); el1.appendChild( el2 );
							el2 = new Element( "a", { href:myLinkURL, target:'_blank' }).addClassName('presslink').update(myLinkName); el1.appendChild( el2 );
							}

						omC.tiles.baseOne.show();
					} else {
						var myLinkURL = omC.hashEntry.get(entry_id+".meta_linkA_url"+omC.altLang); // start with the alternate language
						if (!omC.altLang || !myLinkURL) { myLinkURL = omC.hashEntry.get(entry_id+".meta_linkA_url"); } // go back to beginning if null or unnecessary
						if (myLinkURL !== undefined && myLinkURL.length>0) {
							window.open(myLinkURL);
							}
						}
					break;
				}
			},
			
		go : function( template, entry_id ) {
			switch( template ) {
				case "index":
					omC.tiles.baseIndex.show();
					omC.tiles.baseIndexPages.show();
					omC.tiles.baseOne.hide();
					break;
				case "one":
					omC.tiles.baseOne.show();
					omC.tiles.baseIndex.hide();
					omC.tiles.baseIndexPages.hide();
					break;
				}
			}
	
	},
/*
               _ _                                 
              | | |                                
__      ____ _| | |_ __   __ _ _ __   ___ _ __ ___ 
\ \ /\ / / _` | | | '_ \ / _` | '_ \ / _ \ '__/ __|
 \ V  V / (_| | | | |_) | (_| | |_) |  __/ |  \__ \
  \_/\_/ \__,_|_|_| .__/ \__,_| .__/ \___|_|  |___/
                  | |         | |                  
                  |_|         |_|                  
*/
wallpapers : {
	
		base : Object,
		baseOne : Object,
		
		init : function( baseObj, altLang ) {
			omC.altLang = altLang ? altLang : "";
			omC.wallpapers.base = baseObj;
			omC.wallpapers.requestXML( om.config.url_content + om.config.area + "/publish.xml?refresh=" + Math.floor(Math.random()*9999).toString() );
			},

		requestXML : function( url_xml ) {
			new Ajax.Request( url_xml, {
					method: "post",
					onComplete: omC.wallpapers.receiveXML
					});
			},
			
		receiveXML : function( ajaxresponse ) {
			omC.ingestAreaXML( ajaxresponse );
			omC.wallpapers.setup("wallpapers");
			},

		setup : function( template ) {
			var el1, el2, el3, el4, el5, el6, el7, el8, el9;			
		
			omC.wallpapers.base.hide();

			switch( template ) {
				case "wallpapers":
					omC.wallpapers.base.update();

					// populate index
					omC.indexGroup.each(function(_id){
						// throw a group header here if we like
						omC.hashGroup.get(_id+".publish_contents").split(",").each(function(_id){
							// get headline
							var myHeadline = omC.hashEntry.get(_id+".meta_title"+omC.altLang); // start with the alternate language
							if (!omC.altLang || !myHeadline) { myHeadline = omC.hashEntry.get(_id+".meta_title"); } // go back to beginning if null or unnecessary

							// p
							el1 = new Element( "p" ).addClassName("pageHP"); omC.wallpapers.base.appendChild( el1 );
								// span
								el2 = new Element( "span" ).addClassName("pageHeadline").update( myHeadline ); el1.appendChild( el2 );
							// p
							el1 = new Element( "p" ).addClassName("pageP"); omC.wallpapers.base.appendChild( el1 );
								// a
								el2 = new Element( "a", { target: "_blank", href: om.config.url_content + om.config.area + "/" + _id + "_large.jpg" } ).addClassName("pageImage"); el1.appendChild( el2 );
									// img
									el3 = new Element( "img", { src: om.config.url_content + om.config.area + "/" + _id + "_index.jpg" } ).addClassName("pageImage"); el2.appendChild( el3 );

							});
						});
					omC.wallpapers.base.show();
					break;
				}
			},
			
		go : function( template, entry_id ) {
			switch( template ) {
				case "one":
					omC.wallpapers.baseOne.show();
					break;
				}
			}
	
	},
/*




__   _____  ___ _     
\ \ / /|  \/  || |    
 \ V / | .  . || |    
 /   \ | |\/| || |    
/ /^\ \| |  | || |____
\/   \/\_|  |_/\_____/
*/

	/* XML FOR GROUP/ENTRY */

	ingestAreaXML : function( ajaxresponse ) {
			if ( ajaxresponse.status == 200 ) {
				// get GROUP	
				var x_data_group = ajaxresponse.responseXML.getElementsByTagName('group');
				omC.hashMashXML( "group", x_data_group, true);
	
				// get ENTRY
				var x_data_entry = ajaxresponse.responseXML.getElementsByTagName('entry');	
				omC.hashMashXML( "entry", x_data_entry, true);
	
			} else {
				}
	
			},
/*




 _               _     
| |             | |    
| |__   __ _ ___| |__  
| '_ \ / _` / __| '_ \ 
| | | | (_| \__ \ | | |
|_| |_|\__,_|___/_| |_|

*/

	indexGroup : new Array(),
	indexEntry : new Array(),
	hashGroup : new Hash(),
	hashEntry : new Hash(),

	// FUNCTION TO INTERPRET XML RESPONSE INTO hashMash INDEXED indexMash
	hashMashXML : function( mashBase, xmlNodes, hashClear ) {
		if (hashClear) {
			if (mashBase=="group") {
				omC.hashGroup = new Hash();
				omC.indexGroup = new Array();
			} else {
				omC.hashEntry = new Hash();
				omC.indexEntry = new Array();
				}
			}
		var g_Id, data;

		for (var i = 0; i < xmlNodes.length; i++ ) {

			// grab the id of incoming data
			g_Id = xmlNodes[i].getAttribute('id');
			if (hashClear) {
				if (mashBase=="group") {
					omC.indexGroup.push(g_Id);
				} else {
					omC.indexEntry.push(g_Id);
					}
				}			

			// add xml key/value pairs to hashMash
			// example: id "5" + node "meta_title" --> stored at key "5.metatitle"
			for ( var j = 0; j < xmlNodes[i].childNodes.length; j++ ) {
				if ( xmlNodes[i].childNodes[j].nodeType == 1) {
					if (xmlNodes[i].childNodes[j].childNodes[0] != null) {
						data = xmlNodes[i].childNodes[j].childNodes[0].data;
					} else {
						data = " ";
						}
					if (mashBase=="group") {
						omC.hashGroup.set( g_Id + "." + xmlNodes[i].childNodes[j].nodeName, data );
					} else {
						omC.hashEntry.set( g_Id + "." + xmlNodes[i].childNodes[j].nodeName, data );
						}
					}
				}

			}
			
		},
/*


       _   _ _ 
      | | (_) |
 _   _| |_ _| |
| | | | __| | |
| |_| | |_| | |
 \__,_|\__|_|_|
*/
	util : {
		entryDate : function( _id ) {
			var year, month, day, season, datestring;
			var months = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
			var seasons = ["", "Winter", "Spring", "Summer", "Fall" ];
			// create date string
			season = seasons[omC.hashEntry.get(_id+".meta_date_season")];
			year = omC.hashEntry.get(_id+".meta_date_year");
			month = months[omC.hashEntry.get(_id+".meta_date_month")];
			day = omC.hashEntry.get(_id+".meta_date_day");
			if ( year!=null && month!=null && day!=null ) {
				datestring = year + "&nbsp;" + month + "&nbsp;" + day;
			} else if ( year!=null && month!=null ) {
				datestring = year + "&nbsp;" + month;
			} else if ( year!=null ) {
				datestring = year;
			} else {
				datestring = "";
				}
			if ( season!= null ) {
				datestring = season + "&nbsp;" + datestring;
				}
			return datestring;
			}
		}

};