﻿$(document).ready(function() {


	jQuery.fn.exists = function(){return jQuery(this).length>0;}



	// Dossier slide

	function gSlider() {
		var slOnStart = 0;
		var currentUL = 0;
		var ivSLShow;

		$('.prev').hide();

		$('.dossierSlide').each(function() {
		
			var gSliderUl_el = $('ul', this);
			var ulWidth = $('.dossierSlide .content').width();				
			var colNumber = 0;
			var cols = Math.ceil($('li', gSliderUl_el).length / 1);
			
			// Animation
			function showNextPhotos() {
				$('.prev').fadeIn('fast');
				colNumber = colNumber + 1;
				if (colNumber == cols) {
					colNumber = colNumber - 1;
				}
				
				if (colNumber+1 == cols) { 
					$('.next').fadeOut('fast');
				}
		
				var ulPosition = -(ulWidth * colNumber);
		
				$(gSliderUl_el).animate({ left: ulPosition }, 500);
			}
			
			function showPrevPhotos() {	
				$('.next').fadeIn('fast');
				colNumber = colNumber - 1;
				if (colNumber < 0) {
					colNumber = colNumber + 1;
				}
				
				if (colNumber == 0) {
						$('.prev').fadeOut('fast');
					}
					
				var ulPosition = -(ulWidth * colNumber);

				$(gSliderUl_el).animate({ left: ulPosition }, 500);
			}

			$('.next', this).click(function() {
				showNextPhotos();
			})
			
			$('.prev', this).click(function() {
				showPrevPhotos();
			})
		});
	}
	
	if ($(".dossierSlide").exists()) { gSlider(); }



	
	// Menu Drop-Down:

			$(".menu_head").click(function() {
				$(this).parent().next(".menu_body").slideToggle(300);
				return false;
			});
			



	
	// Wykladowcy - more
	
		if ($(".wykladowcy").exists()) {
			$(".wykladowcy a").fancybox({
				'padding'       : 0,
				'autoScale'     : true,
				'transitionIn'		: 'none',
           		'transitionOut'		: 'none',
				'width'		: 700,
				'height'	: 400,
				'type'				:	'iframe'
			});
		}





	// Cufon
			/*
			Cufon.replace('#menu-top a', { fontFamily: 'Museo 500' });
			if ($("cite").exists()) {
				Cufon.replace('cite', { fontFamily: 'Museo 500' });
			}
			if ($("q").exists()) {
				Cufon.replace('q', { fontFamily: 'Museo 100' });
			}
			if ($("h1").exists()) {
				Cufon.replace('h1', { fontFamily: 'Museo 700' });
			}
			if ($("h2").exists()) {
				Cufon.replace('h2', { fontFamily: 'Museo 700' });
			}
			if ($("h3").exists()) {
				Cufon.replace('h3', { fontFamily: 'Museo 700' });
			}
			if ($("h4").exists()) {
				Cufon.replace('h4', { fontFamily: 'Museo 500' });
			}
			if ($("h5").exists()) {
				Cufon.replace('h5', { fontFamily: 'Museo 700' });
			}
			if ($("h6").exists()) {
				Cufon.replace('h6', { fontFamily: 'Museo 500' });
			}


			if ($(".links a").exists()) {
				Cufon.replace('.links a', { fontFamily: 'Museo 500', hover: true });
			}

				
			if ($("#center .content-contact h4").exists()) {
				Cufon.replace('#center .content-contact h4', { fontFamily: 'Museo 700' });
			}
			if ($("#media h4").exists()) {
				Cufon.replace('#media h4', { fontFamily: 'Museo 700' });
			}

			if ($("#menu-left a").exists()) {
				Cufon.replace('#menu-left a', { fontFamily: 'Museo 700' });
			}

			if ($("#partnerzy h4").exists()) {
				Cufon.replace('#partnerzy h4', { fontFamily: 'Museo 700' });
			}

*/




	// Focus border remove

			if ($("a").exists()) {
				$("a").focus(function() {
					$(this).blur();
				});
			}





	//	Gallery carousel

			if ($("#gallery-prv").exists()) {

				$('#gallery-prv').carouFredSel({
						direction	: "right",
						auto		: false,
						next 		: { button : $('.gallery .right') },
						prev 		: { button : $('.gallery .left') }
				});

			};


			if ($("#gallery-referencje").exists()) {

				$('#gallery-referencje').carouFredSel({
						direction		: "right",
						auto			: true,
						visibleItems	: 5,
						next 			: { button : $('.gallery .right') },
						prev 			: { button : $('.gallery .left') },
						auto			: { pauseDuration	: 4000 },
						scroll 			: { pauseOnHover	: true, effect: "swing" }
				});
			};




	// Carousel - recenzje

			if ($("#user_interaction").exists()) {
				$('ul#user_interaction').carouFredSel({
					prev				: "#prev",
					next				: "#next",
					auto				: {
											pauseDuration		: 5000
										},
					scroll 				: {
											items			: 1,
											effect			: "easeOutBounce",		
											pauseOnHover	: true,
											duration		: 500
										},
					items : {
						visible: 1
					}
				});
	
				$("ul#user_interaction .more").fancybox({
					width				:	'70%',
					
					type				:	'iframe',
					autoScale		:	true,
					cyclic				:	true,
					onStart: function() {
						setTimeout(function() {
							$("ul#user_interaction").trigger("pause");
						}, 2000);
					},
						onClosed : function() {
							$("ul#user_interaction").trigger("play");
					}
				});
			};





	
	// Fancybox

			if ($(".gallery").exists()) {
				$("a[rel^='group1']").fancybox({
					'titlePosition'	: 'over'
				});
				$('.arrow').click(function() {
					$("a[rel^='group1']").fancybox();
				});
			}
			
			if ($(".fancy").exists()) {
				$(".fancy").fancybox();
			}
			
			if ($(".iframe").exists()) {
				$(".iframe").fancybox({
					'width'				: '85%',
					'height'			: '85%',
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});
			}

			if ($(".fancy").exists()) {
				$(".fancy").fancybox();
			}




	// Remove last
	
			$("#foot .links a:last").css({ borderRight: '0 none' });





	// Scroll to

			
		



	// Validate

			if ($("#contact button").exists()) {
				$('button').formValidator({
						scope : '#contact',
						errorDiv : '.error'
				});
			}





	// _blank
	
			$(function() {
				$('.blank').click( function() {
					window.open(this.href);
					return false;
				});
			});




});

function scrollTo(arg) {
	$.scrollTo('0', arg)
}


