$(window).load(function() {
	
	if ($('#slider').length) {
		$('#slider').nivoSlider({
	        effect: 'boxRain', // Specify sets like: 'fold,fade,sliceDown'
	        animSpeed: 500, // Slide transition speed
	        pauseTime: 4000, // How long each slide will show
	        keyboardNav: false, // Use left & right arrows
	        pauseOnHover:true, // Stop animation while hovering
	        manualAdvance:false, // Force manual transitions
	        captionOpacity: 0.0, // Universal caption opacity
	        directionNav: false, // Next & Prev navigation
	        controlNav: false
	    });
	}
	
	if ($('#tabs').length) {
		$(function() {	$("#tabs").tabs();	});
	}
	
	if ($('#formID').length) {
		jQuery(document).ready(function(){
	    	jQuery("#formID").validationEngine();
		});
		
		$('#men').hide();
		$('#women').hide();
		$('#terms-field').hide();
		
		$('#model_sex').change(function() {
			if($(this).attr('value') == "men") {
				$('#men').show();
				$('#women').hide();
				$('.women-option').removeClass('validate[required]');
				$('.men-option').addClass('validate[required]');
			} else if($(this).attr('value') == "women") {
				$('#men').hide();
				$('#women').show();
				$('.men-option').removeClass('validate[required]');
				$('.women-option').addClass('validate[required]');
			} else {
				$('#men').hide();
				$('#women').hide();
			}
		});
		
		$('#model_locality').change(function() {
			if($(this).attr('value') == "-") {
				$("#other_city").css("visibility","visible");
				$('#model_other_locality').addClass('validate[required]');
// 				$('#model_other_locality').css('display','');
// 			if($(this).attr('value') == "warszawa") {
// 				$('#model_other_locality').attr("disabled", true);
				
			} else {
				$('#model_other_locality').removeClass('validate[required]');
// 				$('#model_other_locality').css('display','none');
// 				$('#model_other_locality').value=' ';
				$("#other_city").css("visibility","hidden");
// 				$('#model_other_locality').removeAttr("disabled");
			}
		});
	}
	
	if ($('#relation-photos').length) {
		jQuery(document).ready(function($) {
			
			$('#model-info').css('display', 'block');
			// Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			var onMouseOutOpacity = 0.6;
			$('#thumbs ul.thumbs li').opacityrollover({
				mouseOutOpacity:   onMouseOutOpacity,
				mouseOverOpacity:  1.0,
				fadeSpeed:         'fast',
				exemptionSelector: '.selected'
			});
			
			// Initialize Advanced Galleriffic Gallery
			var gallery = $('#thumbs').galleriffic({
				delay:                     2500,
				numThumbs:                 5,
				preloadAhead:              10,
				enableTopPager:            false,
				enableBottomPager:         false,
				maxPagesToShow:            7,
				imageContainerSel:         '#slideshow',
				controlsContainerSel:      '#controls',
				captionContainerSel:       '#caption',
				loadingContainerSel:       '#loading',
				renderSSControls:          false,
				renderNavControls:         false,
				playLinkText:              'Play Slideshow',
				pauseLinkText:             'Pause Slideshow',
				prevLinkText:              '&lsaquo; Previous Photo',
				nextLinkText:              'Next Photo &rsaquo;',
				nextPageLinkText:          'Next &rsaquo;',
				prevPageLinkText:          '&lsaquo; Prev',
				enableHistory:             true,
				autoStart:                 false,
				syncTransitions:           false,
				defaultTransitionDuration: 900,
				onSlideChange:             function(prevIndex, nextIndex) {
					// 'this' refers to the gallery, which is an extension of $('#thumbs')
					this.find('ul.thumbs').children()
						.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
						.eq(nextIndex).fadeTo('fast', 1.0);
					
				},
				onPageTransitionOut:       function(callback) {
					this.fadeTo('fast', 0.0, callback);
				},
				onPageTransitionIn:        function() {
					var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
					var nextPageLink = this.find('a.next').css('visibility', 'hidden');
		
					// Show appropriate next / prev page links
					if (this.displayedPage > 0) {
						prevPageLink.css('visibility', 'visible');
					}
					var lastPage = this.getNumPages() - 1;
					if (this.displayedPage < lastPage) {
						nextPageLink.css('visibility', 'visible');
					}
					this.fadeTo('fast', 1.0);
				}
			});
			
			gallery.find('a.prev').click(function(e) {
				$('#thumbs').hide();
				gallery.previousPage();
				e.preventDefault();
				$('#thumbs').fadeTo('fast', 0.5);
			});
		
			gallery.find('a.next').click(function(e) {
				//$('#thumbs').hide();
				gallery.nextThumb();
				e.preventDefault();
				//$('#thumbs').fadeTo('fast', 0.5);
			});
		
			/**** Functions to support integration of galleriffic with the jquery.history plugin ****/
		
			// PageLoad function
			// This function is called when:
			// 1. after calling $.historyInit();
			// 2. after calling $.historyLoad();
			// 3. after pushing "Go Back" button of a browser
			function pageload(hash) {
				// alert("pageload: " + hash);
				// hash doesn't contain the first # character.
				if(hash) {
					$.galleriffic.gotoImage(hash);
				} else {
					gallery.gotoIndex(0);
				}
			}
		
			// Initialize history plugin.
			// The callback is called at once by present location.hash. 
			$.historyInit(pageload, "advanced.html");
		
			// set onlick event for buttons using the jQuery 1.3 live method
			$("a[rel='history']").live('click', function(e) {
				if (e.button != 0) return true;
				
				var hash = this.href;
				hash = hash.replace(/^.*#/, '');
		
				// moves to a new page. 
				// pageload is called at once. 
				// hash don't contain "#", "?"
				$.historyLoad(hash);
		
				return false;
			});
		
			/****************************************************************************************/
		});
	}
	
	/*if ($('#model-info').length) {
		jQuery(document).ready(function($) {
			
			$('#model-info').css('display', 'block');
			// Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			var onMouseOutOpacity = 0.6;
			$('#thumbs ul.thumbs li').opacityrollover({
				mouseOutOpacity:   onMouseOutOpacity,
				mouseOverOpacity:  1.0,
				fadeSpeed:         'fast',
				exemptionSelector: '.selected'
			});
			
			// Initialize Advanced Galleriffic Gallery
			var gallery = $('#thumbs').galleriffic({
				delay:                     2500,
				numThumbs:                 8,
				preloadAhead:              10,
				enableTopPager:            false,
				enableBottomPager:         false,
				maxPagesToShow:            7,
				imageContainerSel:         '#slideshow',
				controlsContainerSel:      '#controls',
				captionContainerSel:       '#caption',
				loadingContainerSel:       '#loading',
				renderSSControls:          false,
				renderNavControls:         false,
				playLinkText:              'Play Slideshow',
				pauseLinkText:             'Pause Slideshow',
				prevLinkText:              '&lsaquo; Previous Photo',
				nextLinkText:              'Next Photo &rsaquo;',
				nextPageLinkText:          'Next &rsaquo;',
				prevPageLinkText:          '&lsaquo; Prev',
				enableHistory:             true,
				autoStart:                 false,
				syncTransitions:           true,
				defaultTransitionDuration: 900,
				onSlideChange:             function(prevIndex, nextIndex) {
					// 'this' refers to the gallery, which is an extension of $('#thumbs')
					this.find('ul.thumbs').children()
						.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
						.eq(nextIndex).fadeTo('fast', 1.0);
					
				},
				onPageTransitionOut:       function(callback) {
					this.fadeTo('fast', 0.0, callback);
				},
				onPageTransitionIn:        function() {
					var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
					var nextPageLink = this.find('a.next').css('visibility', 'hidden');
		
					// Show appropriate next / prev page links
					if (this.displayedPage > 0) {
						prevPageLink.css('visibility', 'visible');
					}
					var lastPage = this.getNumPages() - 1;
					if (this.displayedPage < lastPage) {
						nextPageLink.css('visibility', 'visible');
					}
					this.fadeTo('fast', 1.0);
				}
			});
			
			gallery.find('a.prev').click(function(e) {
				//$('#thumbs').hide();
				gallery.previousPage();
				e.preventDefault();
				//$('#thumbs').fadeTo('fast', 0.5);
			});
		
			gallery.find('a.next').click(function(e) {
				//$('#thumbs').hide();
				//gallery.nextPage();
				gallery.nextThumb();
				e.preventDefault();
				//$('#thumbs').fadeTo('fast', 0.5);
			});
		
			
		
			// PageLoad function
			// This function is called when:
			// 1. after calling $.historyInit();
			// 2. after calling $.historyLoad();
			// 3. after pushing "Go Back" button of a browser
			function pageload(hash) {
				// alert("pageload: " + hash);
				// hash doesn't contain the first # character.
				if(hash) {
					$.galleriffic.gotoImage(hash);
				} else {
					gallery.gotoIndex(0);
				}
			}
		
			// Initialize history plugin.
			// The callback is called at once by present location.hash. 
			$.historyInit(pageload, "advanced.html");
		
			// set onlick event for buttons using the jQuery 1.3 live method
			$("a[rel='history']").live('click', function(e) {
				if (e.button != 0) return true;
				
				var hash = this.href;
				hash = hash.replace(/^.*#/, '');
		
				// moves to a new page. 
				// pageload is called at once. 
				// hash don't contain "#", "?"
				$.historyLoad(hash);
		
				return false;
			});
		
			
		});
	}*/
});

function show_gallery_image(src) {
	$('#image-cointainer img').fadeTo('slow', 0.3);
	$('#image-cointainer').html('<img src="/assets/images/models/' + src + '" alt="image"/>');
	$('#image-cointainer img').fadeTo('slow', 1.0);
}

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1
    });
});
