
LOCAL = {
	debug: function(debugObj, debugHint) {
		debugObj = debugObj||false;
		debugHint = debugHint||'';
		
		if( typeof console != 'undefined' ) {
			if (debugHint.length > 0) {
				console.log('-----------------------------------');
				console.log(debugHint);
				console.log(debugObj);
				console.log('-----------------------------------');
			} else { console.log(debugObj); }
		}
	},
	common: {
		getUrlParam: function(strParamName, currentUri) {
			currentUri = currentUri||false;
			strReturn = '';
			
			if( currentUri ) { procCurrentUri = currentUri; }
			else { procCurrentUri = location.href; }
			
			if ( procCurrentUri.indexOf("?") > -1 ){
				var strQueryString = procCurrentUri.substr(procCurrentUri.indexOf("?")).toLowerCase();
				var aQueryString = strQueryString.split("&");
				for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
					if ( aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
						var aParam = aQueryString[iParam].split("=");
						strReturn = aParam[1];
						break;
					}
				}
			}
			return unescape(strReturn);
		},
		openPopup: function(url, title, width, height) {
			if (screen.availWidth) {
				popupCenterX = screen.availWidth / 2 - width / 2;
				popupCenterY = screen.availHeight / 2 - height / 2;
			}
			else {
				popupCenterX = 0;
				popupCenterY = 0;
			}
			
			popupWindow = window.open( url, title, 'width='+width+',height='+height+',status=no,location=no,left='+popupCenterX+',top='+popupCenterY+',screenX='+popupCenterX+',screenY='+popupCenterY );
			popupWindow.focus();
			
			return false;
		},
		openPopupLink: function(linkElem) {
			popupUrl = jQuery(linkElem).attr('href');
			popupTitle = jQuery(linkElem).attr('rel');
			popupSizeRaw = jQuery(linkElem).attr('rev');
			popupWidth = 400;
			popupHeight = 400;
			
			if( popupSizeRaw ) {
				var popupSizeArr = popupSizeRaw.split(',');
				popupWidth = popupSizeArr[0];
				popupHeight = popupSizeArr[1];
			}
			
			this.openPopup( popupUrl, '', popupWidth, popupHeight );
			
			return false;
		},
		preloadImages: function(imageList, callback) {
			var count = 0;
			var loading = false;
			var loadNext = function(){
				if(!loading){
					loading = true;
					count++;
					pic = new Image();
					pic.onload = function(){
						loading = false;
						if(count >= imageList.length-1){
								clearInterval(loadInterval);
								callback();
						}
					}
					pic.src = imageList[count];
				}
			}
			var loadInterval = window.setInterval(loadNext, 50);
		},
		randomXToY: function(minVal,maxVal,floatVal) {
			var randVal = minVal+(Math.random()*(maxVal-minVal));
			return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
		},
		boxLink: function(selector) {
			jQuery(selector).click(function(){
				var currLinkElem = jQuery('a', this);
				var linkHref = currLinkElem.attr('href');
				var linkTarget = currLinkElem.attr('target');
				
				if( linkTarget=='_blank' ) {
					window.open(linkHref);
				}
				else {
					window.location.href = linkHref;
				}
				return false;
			});
		}
	},
	layout: {
		init: function() {
			jQuery.fx.interval = 40;
			
			this.adjustContentHeight();
			LOCAL.intervalAssist.initInterval();
			jQuery('#headerSlideshow').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '505px' });
			LOCAL.topNewsSlider.init();
			
			jQuery('.noonOpen, .noonClosed').hover(function(){
				var openTimesBox = jQuery(this).parents('.mitgliederListContainer').find('.mitgliederListContainer-shopHours');
				jQuery(openTimesBox).show();
			}, function(){
				var openTimesBox = jQuery(this).parents('.mitgliederListContainer').find('.mitgliederListContainer-shopHours');
				jQuery(openTimesBox).hide();
			});
		},
		initFadeButtons: function() {
			jQuery('.fadeBtn span').css('opacity', '0');
			jQuery('.fadeBtn span').hover(function(){
				jQuery(this).stop().animate({ opacity: 1 }, 'slow');
			}, function(){
				jQuery(this).stop().animate({ opacity: 0 }, 'slow');
			});
		},
		adjustContentHeight: function() {
			var containerContentHeight = jQuery('#containerContent').height();
			var contentHeight = jQuery('#content').height();
			var sidebarHeight = jQuery('#sidebarWrap').height();
			
			if( contentHeight > containerContentHeight ) {
				containerContentHeight = contentHeight;
				jQuery('#content').height(contentHeight+'px');
			}
			
			if( sidebarHeight > containerContentHeight ) {
				jQuery('#content').height(sidebarHeight+'px');
			}
			
		}
	},
	intervalAssist: {
		intervalCount: 0,
		intervalTime: 2000,
		intervalHookObj: [],
		windowHasFocus: true,
		initInterval: function() {
			window.onblur = function () {
				LOCAL.intervalAssist.windowHasFocus = false;
				//LOCAL.debug('focus false');
			}
			window.onfocus = function () {
				LOCAL.intervalAssist.windowHasFocus = true;
				//LOCAL.debug('focus true');
			}
			
			setInterval( "LOCAL.intervalAssist.callInterval()", this.intervalTime );
		},
		callInterval: function() {
			LOCAL.intervalAssist.intervalCount++;
			var currentIntervalCalc = LOCAL.intervalAssist.intervalCount*LOCAL.intervalAssist.intervalTime;
			
			if( LOCAL.intervalAssist.intervalHookObj.length > 0 ) {
				for(var i in LOCAL.intervalAssist.intervalHookObj) {
					if (LOCAL.intervalAssist.intervalHookObj[i].time) {
						if (currentIntervalCalc % LOCAL.intervalAssist.intervalHookObj[i].time == 0) {
							LOCAL.intervalAssist.intervalHookObj[i].respectWindowFocus = LOCAL.intervalAssist.intervalHookObj[i].respectWindowFocus || false;
							
							if (LOCAL.intervalAssist.intervalHookObj[i].respectWindowFocus) {
								if (LOCAL.intervalAssist.windowHasFocus == true) {
									//LOCAL.debug( 'callInterval: '+ LOCAL.intervalAssist.intervalHookObj[i].name +' ['+ LOCAL.intervalAssist.intervalCount +']' );
									LOCAL.intervalAssist.intervalHookObj[i].callFunc();
								}
							}
							else {
								//LOCAL.debug( 'callInterval: '+ LOCAL.intervalAssist.intervalHookObj[i].name +' ['+ LOCAL.intervalAssist.intervalCount +']' );
								LOCAL.intervalAssist.intervalHookObj[i].callFunc();
							}
						}
					}
				}
			}
		}
	},
	topNewsSlider: {
		mouseOver: false,
		sliderInterval: 10000,
		init: function() {
			this.initSliderHtml();
			
			jQuery('.topNewsNav a').click(function(){
				LOCAL.topNewsSlider.showSlide(this);
				
				return false;
			});
			
			this.autoSwitchSlide();
			
			jQuery('.topNewsContent').hover(function(){
				LOCAL.topNewsSlider.mouseOver = true;
			}, function(){
				LOCAL.topNewsSlider.mouseOver = false;
			});
			
			// save to interval hook obj
			LOCAL.intervalAssist.intervalHookObj.push({
				name: 'contentSlider',
				time: this.sliderInterval,
				respectWindowFocus: true,
				callFunc: function(){ LOCAL.topNewsSlider.autoSwitchSlide(); }
			});
		},
		initSliderHtml: function() {
			jQuery('.topNewsContainer').each(function(index){
				var currContainer = jQuery(this);
				var currContent = currContainer.children('.topNewsContent');
				var currNav = currContainer.children('.topNewsNav');
				
				currContent.children('.topNewsContentEntry').each(function(index) {
					var currArticle = jQuery(this);
					var currArticleLinkUrl = currArticle.find('a').attr('href');
					var currArticleNav = currArticle.find('.nav');
					
					newNavElem = jQuery('<a>', {
						id: currArticleNav.attr('id'),
						href: currArticleLinkUrl
					}).html(
						currArticleNav.html()
					).appendTo(currNav);
				});
				
			});
			jQuery('.topNewsContainer').find('.topNewsNav a:first-child').addClass('active');
			jQuery('.topNewsContainer').find('.topNewsContent .topNewsContentEntry:first-child').addClass('active');
		},
		autoSwitchSlide: function() {
			var activeSlide = jQuery('.topNewsNav a.active');
			if( activeSlide.length==0 ) { jQuery('.topNewsNav a:last-child'); }
			
			var nextSlide = activeSlide.next().length ? activeSlide.next() : jQuery('.topNewsNav a:first-child');
			jQuery(nextSlide).click();
		},
		showSlide: function(elem) {
			var elem = elem||jQuery('.topNewsNav a:first-child');
			var currNavElem = jQuery(elem);
			var currContainer = currNavElem.parent().parent();
			var currNavContainer = currNavElem.parent();
			var activeElem = currContainer.find('.topNewsContentEntry.active');
			var activeNavElem = currNavContainer.find('.active');
			var activeElemAnimated = activeElem.is(':animated');
			
			
			if( (currNavElem.is('.active') || activeElemAnimated || LOCAL.topNewsSlider.mouseOver) ) {
				return false;
			}
			else {
				var newActiveElem = currContainer.find('#topNews_'+currNavElem.attr('id'));
				activeElem.find('.topNewsTeaser').slideUp('slow', function(){
					fadeImg = jQuery('<div>', { id: 'sliderImgFade'} )
								.html( activeElem.find('.topNewsImg a').html() )
								.appendTo(currContainer);
					
					activeElem.removeClass('active');
					activeNavElem.removeClass('active');
					newActiveElem.addClass('active');
					currNavElem.addClass('active');
					
					fadeImg.fadeOut('slow', function(){
						jQuery(this).detach();
						newActiveElem.find('.topNewsTeaser').slideDown('slow', function(){});
					});
				});
				
			}
			
		}
	}
}

