//jQuery closure
(function($) {
	//document ready
	$(document).ready(function() {
		$('#portrait-selection form').submit(function(e){
			var $form = $(this);
			var $checkboxes = $form.find('input[type="checkbox"]').filter('*[checked]');
			var arSelected = [];
			
			$checkboxes.each(function(){
				arSelected.push($(this).attr('value'));
			});
			
			//$checkboxes.remove();
			//console.log(arSelected);
			//e.preventDefault();
			$form.find('input[name="filter"]').attr('value',arSelected.join('-'));
		});
	});
	
	$(window).load(function() {
		$('#slider').nivoSlider({
			effect:'sliceUpDown', // Specify sets like: 'fold,fade,sliceDown'
			slices:15, // For slice animations
			boxCols: 8, // For box animations
			boxRows: 4, // For box animations
			animSpeed:500, // Slide transition speed
			pauseTime:4000, // How long each slide will show
			startSlide:0, // Set starting Slide (0 index)
			directionNav:true, // Next & Prev navigation
			directionNavHide:true, // Only show on hover
			controlNav:false, // 1,2,3... navigation
			controlNavThumbs:false, // Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, // Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', // Replace this with...
			controlNavThumbsReplace: '.jpg', // ...this in thumb Image src
			keyboardNav:true, // Use left & right arrows
			pauseOnHover:true, // Stop animation while hovering
			manualAdvance:false, // Force manual transitions
			captionOpacity:0.8, // Universal caption opacity
			prevText: '&laquo;', // Prev directionNav text
			nextText: '&raquo;', // Next directionNav text
			beforeChange: function(){}, // Triggers before a slide transition
			afterChange: function(){}, // Triggers after a slide transition
			slideshowEnd: function(){}, // Triggers after all slides have been shown
			lastSlide: function(){}, // Triggers when last slide is shown
			afterLoad: function(){} // Triggers when slider has loaded
		});
		$('#modelslider').nivoSlider({
			effect:'fold', // Specify sets like: 'fold,fade,sliceDown'
			slices:15, // For slice animations
			boxCols: 8, // For box animations
			boxRows: 4, // For box animations
			animSpeed:500, // Slide transition speed
			pauseTime:5000, // How long each slide will show
			startSlide:0, // Set starting Slide (0 index)
			directionNav:true, // Next & Prev navigation
			directionNavHide:false, // Only show on hover
			controlNav:true, // 1,2,3... navigation
			controlNavThumbs:true, // Use thumbnails for Control Nav
			controlNavThumbsFromRel:true, // Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', // Replace this with...
			controlNavThumbsReplace: '.jpg', // ...this in thumb Image src
			keyboardNav:true, // Use left & right arrows
			pauseOnHover:false, // Stop animation while hovering
			manualAdvance:false, // Force manual transitions
			captionOpacity:0.8, // Universal caption opacity
			prevText: '', // Prev directionNav text
			nextText: '', // Next directionNav text
			beforeChange: function(){}, // Triggers before a slide transition
			afterChange: function(){}, // Triggers after a slide transition
			slideshowEnd: function(){}, // Triggers after all slides have been shown
			lastSlide: function(){}, // Triggers when last slide is shown
			afterLoad: function(){} // Triggers when slider has loaded
		});
		
		//set model gallery size
		var thumbCount = $('#modelslider .nivo-controlNav a').size();
		if (thumbCount > 0) {
			var rows = thumbCount / 3;
			if (thumbCount % 3 != 0) {
				rows = Math.floor(rows) + 1;
			}
			var newHeight = 30+552+18+35+(rows*180);
			$('.model>div>section.gallery').css('height',newHeight);
		}
		
		$('#gallery-expand').click(function(e){
			e.preventDefault();
			var $slider = $('#modelslider');
			//var currentImgUrl = urldecode($slider.css('background-image'));
			var fullImgUrl = '';
			//alert($slider.attr('data-current-slide'));
			var $currentImg = $slider.find('img').eq($slider.attr('data-current-slide'));
			if ($currentImg.attr('data-img-src') != '') {
				$('#model-img-large')
				.lightbox_me()
				.find('img')
				.attr('src',$currentImg.attr('data-img-src'));
			}
		});
		
		$('#gallery-pause').click(function(e){
			e.preventDefault();
			
			var $slider = $('#modelslider');
			
			if ($(this).hasClass('pause')) {
				//pause
				$slider.trigger('pos-pause');
				$(this).removeClass('pause');
				$(this).addClass('play');
				$(this).text('fortsetzen');
			}
			else {
				//play
				$slider.trigger('pos-continue');
				$(this).removeClass('play');
				$(this).addClass('pause');
				$(this).text('anhalten');
			}
		});
		
		//WP gallery lightbox
		$('.gallery-icon>a').colorbox({scalePhotos: true, maxWidth: "100%", maxHeight: "100%", rel:"group1"});
	});
})(jQuery);
