$(window).load(function() {/* Webkit browser braucht geladenes bild um dimensionen erfassen zu können */
		iExplorer = jQuery.browser.msie ? 1 : 0;
		caption_header = '#big_pic .captionHeadingContainer';
		$('#thumb_section').wrap('<div>').parent().attr('id', 'gallery').prepend('<div id="big_pic"></div>');

		$.fn.BigPic = function(){
			$('#big_pic').html('<img id="big_img" src="' + $(this).attr('src') + '"/><div class="clear"></div><div class="captionContainer">' + $(this).next().html() + '</div><div id="caption_switch"></div><div class="clear"></div>')
			if(iExplorer) $('#caption_switch').css({'left': '0px'});
			img_width = $('#big_pic img').not('.captionContainer img').width();
			caption_header_height = $(caption_header).height() + parseInt($(caption_header).css('padding-top')) + parseInt($(caption_header).css('padding-bottom'));
			SwitchHeight();
			$('#big_pic').css('height', $('#big_img').outerHeight(true) + caption_header_height);
			$('#big_pic, #caption_switch, #big_pic .captionTextContainer').css('width', img_width);
			$(caption_header).css('width', img_width);
			caption_height = parseInt($('#big_pic .captionContainer').height());

			$('#caption_switch').hover(function(){
				$('#big_pic .captionContainer').stop().animate({top: '-' + caption_height + 'px'});
				$('#caption_switch').css({'margin': '-' + caption_height + 'px 0px -' + caption_height + 'px 0px', 'height': caption_height + caption_header_height + 'px'});
				$('#big_pic .captionMore').css({'color': 'white'});
			}, 
			function(){
				$('#big_pic .captionContainer').stop().animate({top:'0px'});
				SwitchHeight();
				$('#big_pic .captionMore').css('color', original_more_color);
			});
		}

		function SwitchHeight(){
			$('#caption_switch').css({'margin': '0px', 'height': caption_header_height + 'px', 'width': img_width + 'px'});
		}


		$('#thumb_section img, #big_img').live('click', function(e){
			if (e.button != 0) return true;
			$('.thumb_active').removeClass('thumb_active');
			if($(this).parent().attr('id') == 'big_pic'){
				current_photo = current_photo ==  $('#thumb_section img').not('.captionContainer img').size() ? 1 : current_photo + 1;
				$('#img_nr_' + current_photo).addClass('thumb_active').BigPic()
			}else{
				current_photo = parseInt($(this).attr('id').replace('img_nr_', ''));
				$(this).addClass('thumb_active').BigPic();
			}
		})

		$('#thumb_section img:first').BigPic();

		current_photo = 1;
		i = 0;
		$('#thumb_section img').not('.captionContainer img').each(function(){
			i++;
			$(this).attr('id', 'img_nr_' + i)
		})

		$('#thumb_section img:first').addClass('thumb_active');
		original_more_color = $('#big_pic .captionMore').css('color');
	});
