
/**
 * restores the previously saved image on the given element
 *
 * ARGS: { id: 'id of image element to swap to original' }
 * EXAMPLE: restoreImage( {id: 'Image1' } )
 */		
function restoreImage(args) {
	$('img').each(
		function() {
			if( $(this).data('oSrc') ) {
				$(this).attr('src', $(this).data('oSrc'));
			}
		}
	);
}

/**
 * swaps the image of the element with the given img
 * stores the old img on the element for later use (see restoreImag())
 *
 * ARGS: { id: 'id of image element', img: 'src path to img' }
 * EXAMPLE: swapImage( [{id:'Image1',img:'images/projekte/thumbnails/01b.jpg'}, ... (as many as you want)] )
 */
function swapImage(args) {
	$(args).each(
		function() {
			var element = $('#'+$(this).attr('id'));

			if (element != null) {
				if(!element.data('oSrc')) {
					element.data('oSrc', element.attr('src'));
				}
				element.attr('src', $(this).attr('img'));
			}
		}
	);	
}

/**
 * will show/hide the element with the given id
 * this is all based on the args passed into the function
 * 
 * ARGS: 'id of the element to be shown/hidden', 'not sure what this does', 'show or hide', .. (as many as you want)
 * EXAMPLE: MM_showHideLayers('FrameProjekte','','show','ProjekteTN','','hide')
 */	
function MM_showHideLayers() { //v9.0
	var p,v,obj,args=MM_showHideLayers.arguments;
	for (var i=0; i<(args.length-2); i+=3) { 
		with (document) {
			if (getElementById && ((obj=getElementById(args[i]))!=null)) { 
				v=args[i+2];
				if (obj.style) { 
					obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
				}
				obj.visibility=v;
				obj.display=(v=='visible')?'':'none';
			}
		}
	}
}

/**
 * will do a click on the element with the given id
 * i'm actually not sure why this is even needed
 *
 * ARGS: 'the id of the element to be clicked'
 * EXAMPLE: MM_openMenu('archiv1_0')
 */
function MM_openMenu(target) {
	$(document.getElementById(target)).click();
}

/**
 * calls unmarkMenu() then will add the css class 'markieren'
 * to the element with the given id.
 * this basically highlights/unhighlight the menu elements
 * 
 * ARGS: {id: 'id of the element that needs marking'}
 * EXAMPLE: markMenu( {id:'wanger2'} )
 */
function markMenu(args) {
	unmarkMenu();
	if ($.isArray(args)) {
		$(args).each(
			function() {
				$( '#'+this ).addClass("markieren");
			}
		);
	}
	else {
		$( '#'+args ).addClass("markieren");
	}
}

/**
 * will remove the css class 'markieren' from all the
 * elements that have the class set at the moment
 */
function unmarkMenu() {
	$(".markieren").removeClass("markieren");
}

function initProjectEvents() {

	$('li#projectMenu a').filter(':not(.avoidEventCreation)').each(function(i) {

		// mousedown event
		$(this).mousedown( function(event) {
		     // mark menu
		     markMenu($(this).attr('id'));

		     // show'n'hide layers
		     var show = $(this).data('args').show;
		     var hide = $(this).data('args').hide;
		     $(show).each(
				     function() {
				    	 MM_showHideLayers(this, '', 'show');
				     }
			 );
		     $(hide).each(
				     function() {
				    	 MM_showHideLayers(this, '', 'hide');
				     }
			 );
		});

		// mousemove event
		$(this).mousemove( function(event) {
			// swap image
			swapImage( $(this).data('args').swap );
		});

		// mouseout event
		$(this).mouseout( function(event) {
			// swap image
			restoreImage( $(this).data('args').swap );
		});
	});

	$('div#ProjekteTN a').filter(':not(.avoidEventCreation)').each(function(i) {
		
		// click event
		$(this).mousedown( function(event) {
		     markMenu($(this).attr('id'));

		     // set iframe src to href of current object
		     var iframe = $('iframe'); 
		     $(iframe).attr('src', $(this).attr('href'));
		     
		     // show'n'hide layers
		     var hide = $(this).data('args').hide;
		     var show = $(this).data('args').show;
		     $(hide).each(
				     function() {
				    	 MM_showHideLayers(this, '', 'hide');
				     }
			 );
			$(show).each(
				     function() {
			    		 MM_showHideLayers(this, '', 'show');
			    		 return false;
				     }
			 );	

			
		     return false;
		});

		// mouseover event
		$(this).mouseover( function(event) {
			markMenu( $(this).data('args').markmenuid );
			swapImage( $(this).data('args').swap );
		});

		// mouseout event
		$(this).mouseout( function(event) {
			restoreImage();
			unmarkMenu();
		});
	});
}

function initProject2Events() {

	$('li#project2Menu a').filter(':not(.avoidEventCreation)').each(function(i) {

		// mousedown event
		$(this).mousedown( function(event) {
		     // mark menu
		     markMenu($(this).attr('id'));

		     // show'n'hide layers
		     var show = $(this).data('args').show;
		     var hide = $(this).data('args').hide;
		     $(show).each(
				     function() {
				    	 MM_showHideLayers(this, '', 'show');
				     }
			 );
		     $(hide).each(
				     function() {
				    	 MM_showHideLayers(this, '', 'hide');
				     }
			 );
		});

		// mousemove event
		$(this).mousemove( function(event) {
			// swap image
			swapImage( $(this).data('args').swap );
		});

		// mouseout event
		$(this).mouseout( function(event) {
			// swap image
			restoreImage( $(this).data('args').swap );
		});
	});

	$('div#Projekte2TN a').filter(':not(.avoidEventCreation)').each(function(i) {
		
		// click event
		$(this).mousedown( function(event) {
		     markMenu($(this).attr('id'));

		     // set iframe src to href of current object
		     var iframe = $('iframe'); 
		     $(iframe).attr('src', $(this).attr('href'));
		     
		     // show'n'hide layers
		     var hide = $(this).data('args').hide;
		     var show = $(this).data('args').show;
		     $(hide).each(
				     function() {
				    	 MM_showHideLayers(this, '', 'hide');
				     }
			 );
			$(show).each(
				     function() {
			    		 MM_showHideLayers(this, '', 'show');
				     }
			 );	

			
		     return false;
		});

		// mouseover event
		$(this).mouseover( function(event) {
			markMenu( $(this).data('args').markmenuid );
			swapImage( $(this).data('args').swap );
		});

		// mouseout event
		$(this).mouseout( function(event) {
			restoreImage();
			unmarkMenu();
		});
	});
}
