/**
 * Project:		PROJECT
 * 
 * @author:		<ap@okapi.de>
 * @version:	1.0
 * @date:		xx/2010
 *
 */




var APJ = function($){
	
/* ////// DEFINITION AND NAMING OF ALL RELEVANT ELEMENTS	*/

	var selectors = {
		
		
	};
	
	
	var defaults = {
		
		
	};

	
	
/* ////// HELPER-FUNCTIONS	*/
	
	/* purpose:
	 *	recursivly retrieves every item of any (multidimensional) var, array or object
	 *	and passes each found value as argument to the callback-function (callbackFn)
	 *
	 *	example:
	 *	iterate trough the predifined, multidimensional "selctors" -object and
	 *	its whole sub-object / sub-array -structure and pass all jquery-"selectors"
	 *	to the "removeBubble"-function
	 */
	function mdVarSolver( mdVar, callbackFn ){
		
		/* if is object */
		if( $.isPlainObject( mdVar ) ){
			
			// console.log( "found object: " + mdVar );
			for( var elmnt in mdVar ){
				arraySolver( mdVar[elmnt], callbackFn );
			}
		}
		
		/* if is array */
		else if( $.isArray( mdVar ) ){
			
			// console.log( "found array: " + mdVar );
			for( var i=0, l=mdVar.length; i<l; i++ ){
				arraySolver( mdVar[i], callbackFn );
			}
		}
		
		/* if is value */
		else { 
			
			// console.log( "found item: " + mdVar );
			callbackFn( mdVar );
		}
	};
	
	


/* ////// EVENT-RELATED/PROCESSING FUNCTIONS	*/
	
	/* purpose:
	 *	removes default bevhavior of any given html-element (links, buttons, etc.)
	 *	jQuery substitute for: return false;
	 */
	function removeBubbles( selector ){
		
		if( $(selector).length ){
				
			$(selector).live("click", function(e){
				
				e.preventDefault();
			});
		}
	};


	
	
/* ////// FUNCTIONS CONTROLLING THE INTIAL PAGE/EVENT SET-UP	*/	

	

	
/* ////// EXECUTE/ADD ALL FEATURES THAT NEED TO BE INITALIZED	*/

	function initPage(){
		
		
	};
	
	


/* ////// RETURN/MAKE PUBLIC ALL FUNCTIONS/VARIABLES THAT MAY NEED TO BE ACCESSED FROM THE OUTSIDE	*/

	return {	
		// PUBLIC VARIABLES
		selectors			:	selectors,
		defaults				:	defaults,
		
		// PUBLIC FUNCTIONS
		initPage				:	initPage,
		removeBubbles		:	removeBubbles
	};
	
	
}(jQuery);




/**
 * AVOID CONFLICTS WITH ADDITIONAL FRAMEWORKS
 */
(function($){
	// DO THIS WHEN DOM IS READY
	var slimboxOptions = {
	        overlayOpacity: 0.7,
			resizeDuration: 300,
			imageFadeDuration:400,
	        //resizeEasing: "easeOutElastic",
	        captionAnimationDuration: 200,
	        counterText: "Bild {x} von {y}",
			loop: true
	};
	
	function changeThumbLinks(){
		$("div.thumbs > ul > li").hover(
		  function () {
		    $(this).find('.description').show();
		  }, 
		  function () {
		    $(this).find('.description').hide();
		  }
		);
		$("div.videothumbs > ul > li").click (function(){
			location.href = $(this).find('a').attr('href');
		});
	
		
		$("div.gallerythumbs > ul > li").click (function(event){
			var images=[];
			var index;
			var clickedimage = $(this).find('a').attr('href');
			$(this).parents(".gallerythumbs").find('li').each(function(i){
				var image = $(this).find('a').attr('href');
				var description = $(this).find('.description-content')[0].innerHTML;
				//console.log(description);
				if (clickedimage == image) {
					index = i;
				}
				images.push([image, description]);
			});
		//	console.log("click", images, index);
			
			jQuery.slimbox(images, index, slimboxOptions);
		});
	
	};
	
	function setupVitaSlideToggle(){
	//	console.log('sgF'+$("li.vitaitem > h2"));
		$("li.vitaitem > h1 a").click(function(e) {
			e.preventDefault();
		});
	
		$("li.vitaitem > h1").click(function(e) {
			e.preventDefault();
			$(this).next().slideToggle('fast', function() {
		    // Animation complete.
				$(this).parent().toggleClass('hidden');
			});
		});
		$("li.vitaitem > h1 + .vitaItemContent").slideToggle(0, function() {
	    // Animation complete.
			$(this).parent().toggleClass('hidden');
		});
		
	};
	
	$(document).ready( function () {
		APJ.initPage();
		changeThumbLinks();
		setupVitaSlideToggle();
		// thumbs
		
	});
})(jQuery);
