//$(document).ready(function () {
jQuery(function ($) {

	/* Let's try to add rel="prettyPhoto" to all relevant links */
	$('#content .entry .gallery dt.gallery-icon a').attr('rel','prettyPhoto[gallery]');

	/* enable PrettyPhoto */
	$("#main a[rel^='prettyPhoto']").prettyPhoto({
		theme:'dark_square'/*'light_square'*/,
		showTitle:true
	});
	
	/* add decorative <span>s to native WP galleries*/
	$('#content dt.gallery-icon a').append('<span></span>');
	// ...and to NextGen galleries on pages
	$('body.page .ngg-gallery-thumbnail > a').append('<span></span>');
	
	/* Enable qTip */
	/*$('a[title]').qtip({ 
		style: { 
			background:'#2b2e31',
			color:'#939ea8',
			name: 'dark', 
			border:{
				color:'#636a71',
				width:8,
				radius:4
			},
			'font':'italic 0.86em Candara, sans-serif',
			tip: { 
				corner: 'bottomRight',
				color: false,
				size: {
					x: 10,
					y : 10
				}
			},
			'padding':'10px 15px'
		},
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomRight'
			},
			target: 'mouse',
			adjust: { 
				mouse: true 
			},
			adjust: { 
				x: 5, 
				y: -10 
			}
   }
	});*/
	
	/* handle focus/blur on comment forms and search form */
	if ($('#respond').length) {
		$('#author').focus(function(){
			if($(this).val() == 'Twoje Imię / nick *') {
				$(this).val('');
			}
		});
		$('#author').blur(function(){
			if($(this).val() == '') {
				$(this).val('Twoje Imię / nick *');
			}
		});
		$('#email').focus(function(){
			if($(this).val() == 'Adres e-mail *') {
				$(this).val('');
			}
		});
		$('#email').blur(function(){
			if($(this).val() == '') {
				$(this).val('Adres e-mail *');
			}
		});
		$('#url').focus(function(){
			if($(this).val() == 'Twoja strona WWW') {
				$(this).val('');
			}
		});
		$('#url').blur(function(){
			if($(this).val() == '') {
				$(this).val('Twoja strona WWW');
			}
		});
	}
	
	if ($('#s').length) {
		$('#s').focus(function(){
			if($(this).val() == 'szukane wyrażenie') {
				$(this).val('');
			}
		});
		$('#s').blur(function(){
			if($(this).val() == '') {
				$(this).val('szukane wyrażenie');
			}
		});
	}

	if ($('#latest-photos-list').length) {
		$('#latest-photos-list').before('<div id="latest-photos-nav"></div>').cycle({ 
			fx: 'fade',
			//easeOut: 'easeout',
			//fx: 'uncover',
			//fx: 'scrollLeft',
			height:340,
			speed: 500, 
			timeout: 10000, 
			pause: 1,
			pager: '#latest-photos-nav',
			sync: 1
		});
	};
	
	if ($('#blog .nav').length) {
		var home_catanimon = false;
		$('#blog .nav li a').click(toggleBlogCat);
	}
	
	/*---------------------------------------------------------------------*/

	// Helper functions

	/*
		This function handles switching blog categories on Home Page
	*/
	function toggleBlogCat() {
		
		if ($(this).parent().hasClass('selected') || home_catanimon == true ) { // quit, if clicked currently visible blog category or old animation is in progress
			return false; 
		}
		
		home_catanimon = true;
		
		// START setting up 'selected' class
		$('#blog .nav ul li').removeClass('selected');
		home_newcat = $.trim($(this).parent().attr('class'));;
		
		$(this).parent().addClass('selected');
		// END setting up 'selected' class
		
		if ($.support.objectAll) { // if NOT ie7 and NOT ie8!
			
			// Fading out old LIs
			del = 0;
			$('#blog .posts .'+home_oldcat+' li').each(function(i){
				window.setTimeout(
					function(theli){
						$(theli).animate({
							opacity:0
						}, 400 );
					}
				,del,this);
				del += 100;
			});
			// Hiding old LIs after fading
			window.setTimeout(function(){
				$('#blog .posts .'+home_oldcat).css({
					'display':'none'
				})
				$('#blog .posts .'+home_oldcat+' li').css({
					'opacity':'1'
				})
			},del);
			
			newdel = del-200;
			// Starting to show new LIs...
			window.setTimeout(function(){
				$('#blog .posts .'+home_newcat+' li').css({
					'opacity':'0'
				})
				$('#blog .posts .'+home_newcat).css({
					'display':'block'
				});
				// Fading in all new LIs
				$('#blog .posts .'+home_newcat+' li').each(function(i){
					window.setTimeout(
						function(theli){
							$(theli).animate({
								opacity:1
							}, 400 );
							if (i==4) {
								home_oldcat = home_newcat;
								home_catanimon = false;
							}
						}
					,newdel,this);
					newdel += 100;
				});
			}, newdel );
			
		} else { // IF IE7 OR IE8
			$('#blog .posts .'+home_oldcat).hide();
			$('#blog .posts .'+home_newcat).show();
			home_oldcat = home_newcat;
			home_catanimon = false;	
		}
		
		return false;
	}
	
	
});

