FLORIANEWALD = {
	common : {
		init : function(){
				
			this.setNaviBgWidth();
			this.setupAccordion();
			this.setWrapperBgHeight();
		},
		
		setupAccordion : function(){
			
			$('.accordion .pane-content').css('display','none');
			$('.accTrigger').css('cursor','pointer');
			$('.accTrigger').click(
				function(event){
					$('.accordion .pane-content').slideToggle('slow');
				});
			
			// accordion all other pages (h3 > div)
			$('.node h3').next().css('display','none');
			$('.node h3').css('cursor','pointer');
			$('.node h3').click( 
				function(event) {
					$content = $(this).next();
					if($(this).hasClass('expanded')){
						$content.slideToggle('slow');
						$content.removeClass('accOpen');
						$(this).removeClass('expanded');
					} else{
					$('.node h3').removeClass('expanded');
					$(this).addClass('expanded');
					$('.accOpen').slideToggle('slow').removeClass('accOpen');
					$content.slideToggle('slow');
					$content.addClass('accOpen');
				}
				}
			);
		},
		
		setNaviBgWidth	: function(){
			//console.log($('.secondary-links li.last').width()+" : "+$('.secondary-links li.last').position().left);
			if($('.secondary-links li').length){
				var wSub = $('.secondary-links li.last').width()+$('.secondary-links li.last').position().left+15;
				$('ul.secondary-links').width(wSub);
			}
			if($('#subsubLinks li').length){
				var wSubSub = $('#subsubLinks li.last').width()+$('#subsubLinks li.last').position().left+15;
				$('#subsubLinks').width(wSubSub);
			}
		},

		setWrapperBgHeight : function(){
			var mainWrapperHeight = $(document).height()-$('#mainWrapper').offset().top;
			$('#wrapper').height($(document).height()+80);
			$('#mainWrapper').height(mainWrapperHeight);
			$('#main').height($('#mainWrapper').height()-$('#mainWrapper').offset().top);
		//	console.log('doc vs window height:'+$(document).height()+' '+$(window).height());
		//	console.log('#wrapper, #mainWrapper, #main -> height:'+$('#wrapper').height()+' '+$('#mainWrapper').height()+' '+$('#main').height());
			
			if($('#tabsWrapper').length){
				$('#tabsWrapper').css('position','absolute').offset().bottom(20);
			}
		},

		finalize : function(){ 
			if($('.center-wrapper').length){
				var h = [];
				Array.max = function( array ){
				return Math.max.apply( Math, array );
				};
				$('.center-wrapper .panel-panel .inside').each(function(index) {
				    h.push($(this).height());
				});
				var maxH = Array.max(h);
				$('.center-wrapper .panel-panel .inside').height(maxH);
			}
		}
	},
	home : {
		init : function(){ 

		}
	},
	armoured_car : {
		init     : function(){ 
			this.carInfo();
//this.initSlider();
		},


		initSlider     : function(){ 
			var $scroll = $('.field-field-car-pictures');
			$scroll.css('overflow', 'hidden');
			
			var $container = $('.field-items');
			$scroll
			.before('<img class="ssScrollButtons left" src="' + pathToTheme + '/scroll_left.png" />')
			.after('<img class="ssScrollButtons right" src="' + pathToTheme + '/scroll_right.png" />');
			var $images = $('.field-item');
			$container.css('width', $images[0].offsetWidth * $images.length);

			$('.left').click(function(){
				$scroll.stop().scrollTo( 'img:eq(0)', 800 );
			});
			$('.right').click(function(){
				var $target = $container.find('.field-item:eq(5)');
				$scroll.stop().scrollTo( $target , 800 );
			});
		},
		carInfo : function(){ 
		//	var mainPicHeight = 
			var $mainPic = $('.carPicMain img');
			var mainPicHeight = $mainPic.height();
			var $txtInfo = $('.carInfo > .dataSheet');
			$txtInfo.height(mainPicHeight);
			//console.log('carInfo imgHeight: '+$txtInfo.text()); 
			$txtInfo.jScrollPane({showArrows: true});
			console.log('carInfo height: '+$('.carInfo').height());
			console.log('carInfo img height: '+$mainPic.height());
			$('.carInfo').height(mainPicHeight);
		}
	},
	helper : {
		showAccordionContent : function(){ 
			$('.contentBgWrapper').slideToggle();

		 }
	}
};

UTIL = {
	fire : function(func,funcname, args){
		var namespace = FLORIANEWALD;  // indicate your obj literal namespace here
		funcname = (funcname === undefined) ? 'init' : funcname;
		if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function'){
			namespace[func][funcname](args);
		}
	},
	
	loadEvents : function(){
		var bodyId = document.body.id;
		// hit up common first.
		UTIL.fire('common');
		UTIL.fire(bodyId);
		
		// do all the classes too.
		// $.each(document.body.className.split(/\s+/),function(i,classnm){
		// 	console.log(i+" : "+classnm);
		// 	UTIL.fire(classnm);
		// 	UTIL.fire(classnm,bodyId);
		// });
		UTIL.fire('common','finalize');
	} 
}; 

if (!window.console) console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};


// kick it all off here 
$(document).ready(UTIL.loadEvents);
