jQuery(document).ready(function(){
jQuery(".vimeo_test2").click(function() {
		jQuery.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 600,
			'height'		: 395,
			'href'			: this.href = this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1') + '&autoplay=1',
			'type'			: 'swf',
			'swf'       : {'wmode':'transparent','allowfullscreen':'true'}
			});
			return false;
});
});	


var slideshow_pager_timeout;
var slideshowOffset = 0;

jQuery(document).ready(function(){
	fontsInit();
	jQuery('.entry').jScrollPane({scrollbarWidth:21, scrollbarMargin:10, dragMaxHeight: 51, dragMinHeight: 51, showArrows: false });
	jQuery('.entry img').parents('a').addClass('fancybox').attr('rel','entry');
	jQuery('blockquote img').parents('a').addClass('fancybox').attr('rel','blockquote');
	//jQuery('#slideshow a img').parents('a').addClass('fancybox');
	
	jQuery('.totop').click(function () {
		scroll(0,0);
		return false;
	});
	
	jQuery('.simpleimage a img').hoverIntent(imgOver,imgOut);
	
	fancyboxInit();
	
	try {
		var folioCnt = jQuery('#portfolio .portfolio').size();
		if ( folioCnt > 1 ) {
			jQuery('#portfolio').after('<a href="" title="Poprzedni" id="portfolio_prev">Poprzedni</a><a href="" title="Następny" id="portfolio_next">Następny</a>').cycle({ 
				fx:     'scrollHorz', 
				speed:  800, 
				timeout: 0, 
				prev: '#portfolio_prev',
				next: '#portfolio_next',
				before: function(idx, slide) {
					jQuery('#portfolio_prev,#portfolio_next').show();
					if (jQuery(slide).index() == 0) {
						jQuery('#portfolio_prev').hide();
					} else if (jQuery(slide).index() == (folioCnt-1)) {
						jQuery('#portfolio_next').hide();
					} 
				},
				cleartypeNoBg: true
			});
		}
		jQuery('#portfolio .more a').animate({opacity:'0.5'},0);
		jQuery('#portfolio .more a').mouseover(function () {
			jQuery(this).animate({opacity:'0.7'},300);
		});
		jQuery('#portfolio .more a').mouseout(function () {
			jQuery(this).animate({opacity:'0.5'},300);
		});
		jQuery('#portfolio .more').mouseenter(function () {
			jQuery(this).find('a').fadeIn(600);
		});
		jQuery('#portfolio .more').mouseleave(function () {
			jQuery(this).find('a').fadeOut(600);
		});
	} catch(err) {}
	
	try {		
		jQuery('#slideshow').after('<ul id="slideshow_pager"></ul><ul id="slideshow_pager_hide" class="hide"></ul><span title="Poprzedni" id="slideshow_prev"></span><span title="Następny" id="slideshow_next"></span>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			pager:  '#slideshow_pager',
			pagerAnchorBuilder: function(idx, slide) {
				return '<li rel="'+jQuery(slide).index()+'"><a href="#" title=""><span class="title">'+jQuery(slide).attr('title')+'</span><img src="'+jQuery(slide).find('.thumb').attr('src')+'" class="thumb" /><img src="'+jQuery(slide).find('.thumb_active').attr('src')+'" class="thumb_active" /></a></li>'; 
			},
			after: function(idx, slide) {
				slideOutCall();
				jQuery('.slideshow').removeAttr('css').css({'position':'absolute','z-index':'1'});
				jQuery(slide).css({'z-index':'9'}).show();
				jQuery(slide).find('iframe').css({'z-index':'9','position':'absolute','top':'0','left':'0'}).show();
				if ( /safari/.test( navigator.userAgent.toLowerCase() ) ) {
					jQuery(slide).html(jQuery(slide).html());
				} 			
			},
			cleartypeNoBg: true
		});
		jQuery('#slideshow .slideshow').find('.thumb, .thumb_active').remove();
		slideshowCnt = parseInt(jQuery('#slideshow_pager li').size()-1);
		if (slideshowCnt < 0) {
			jQuery('#slideshow_pager').append('<li rel="'+jQuery('#slideshow .slideshow').index()+'"><a><span class="title">'+jQuery('#slideshow .slideshow').attr('title')+'</span><img src="'+jQuery('#slideshow .slideshow').find('.thumb').attr('src')+'" class="thumb" /><img src="'+jQuery('#slideshow .slideshow').find('.thumb_active').attr('src')+'" class="thumb_active" /></a></li>');
		}		
		jQuery('#slideshow_pager li').each(function () {
			idx = jQuery(this).attr('rel');
			idx = jQuery(this).attr('rel');
			jQuery(this).css({'left':parseInt(188*idx)});
			if (idx > 4 ) {
				jQuery('#slideshow_pager_hide').append(jQuery(this));
			}
		});
		hoverInit();
		jQuery('#slideshow_pager a').find('.title').animate({ height: 'hide' }, 0);
		jQuery('#slideshow_pager_hide').hide();
		jQuery('#slideshow_prev').hide();
		var slideshowPrev = 0;
		var slideshowNext = 4;
		if (slideshowCnt <= slideshowNext) { jQuery('#slideshow_next').hide(); }
		
		jQuery('#slideshow_prev').click(function () {
			if ( slideshowPrev > 0) {
				jQuery('#slideshow_next').show();
				slideshowNextMove = jQuery('#slideshow_pager li[rel="'+(slideshowNext)+'"]');
				slideshowNext = slideshowNext-1;
				slideshowPrev = slideshowPrev-1;
				slideshowOffset = 6*(slideshowPrev);
				jQuery('#slideshow_pager').append(jQuery('#slideshow_pager_hide li[rel="'+(slideshowPrev)+'"]'));
				jQuery('#slideshow_pager').animate({ marginLeft: (-188)*(slideshowPrev)+'px' }, 200);
				setTimeout("jQuery('#slideshow_pager_hide').append(slideshowNextMove);",201);
				hoverInit();
				slideOutCall();
				if ( slideshowPrev == 0) {
					jQuery(this).hide();
				}
			} 
			//jQuery('#footer').html('slideshowCnt: '+slideshowCnt+', slideshowNext:'+slideshowNext+', slideshowPrev:'+slideshowPrev);
			return false;
		});
		
		jQuery('#slideshow_next').click(function () {
			if ( slideshowNext < slideshowCnt) {
				jQuery('#slideshow_prev').show();
				slideshowPrevMove = jQuery('#slideshow_pager li[rel="'+(slideshowPrev)+'"]');
				slideshowNext = slideshowNext+1;
				slideshowPrev = slideshowPrev+1;
				slideshowOffset = 6*(slideshowPrev);
				jQuery('#slideshow_pager').append(jQuery('#slideshow_pager_hide li[rel="'+(slideshowNext)+'"]'));
				jQuery('#slideshow_pager').animate({ marginLeft: (-188)*(slideshowPrev)+'px' }, 200);
				setTimeout("jQuery('#slideshow_pager_hide').append(slideshowPrevMove);",201);
				hoverInit();
				slideOutCall();
				if ( slideshowNext == slideshowCnt) {
					jQuery(this).hide();
				}
			} 
			//jQuery('#footer').html('slideshowCnt: '+slideshowCnt+', slideshowNext:'+slideshowNext+', slideshowPrev:'+slideshowPrev);
			return false;
		});
	} catch(err) {}	
	
	try {	
		var counter = parseInt(-1);
		jQuery('#page_slider').after('<div id="page_slider_nav_fake"></div><!-- close #page_slider_nav_fake -->').cycle({ 
			fx:     'scrollVert', 
			speed:  800, 
			timeout: 0, 
			pager:  '#page_slider_nav_fake',
			pagerAnchorBuilder: function(idx, slide) {
				counter = counter +1;
				return '<a href="" id="slider_nav_'+counter+'"></a>'; 
			},
			cleartypeNoBg: true,
			after: function(idx, slide) {
				jQuery(slide).find('.entry').jScrollPane({scrollbarWidth:21, scrollbarMargin:10, dragMaxHeight: 51, dragMinHeight: 51, showArrows: false });
				fontsInit();
			}
		});
		jQuery('#news_list_paged').after('<div id="news_list_paged_wrap"><div id="news_list_paged_center"><a href="prev" id="news_list_prev" /><div id="news_list_nav" /><a href="next" id="news_list_next" /></div></div>').cycle({ 
			fx:     'fade', 
			speed:  600, 
			timeout: 0, 
			prev:  '#news_list_prev', 
			next:  '#news_list_next', 
			pager: '#news_list_nav',
			cleartypeNoBg: true
		});
		if (jQuery('#news_list_paged .news_list_page').size() <= 1) jQuery('#news_list_prev, #news_list_next, #news_list_nav').remove(); 
		jQuery('.slider_nav').first().addClass('activeSlide');
		jQuery('.slider_nav').click(function () {
			jQuery('.news_list_page .activeSlide').removeClass('activeSlide');
			jQuery(this).addClass('activeSlide');
			jQuery(jQuery(this).attr('rel')).click();
			return false;
		});
	} catch(err) {}	 
	
	
	try {	
		jQuery('#content_single').before('<div id="content_single_nav"><ul /></div>')
		// jQuery('#content_single .entry').each(function () {
			// blockquote = jQuery(this).find('blockquote');
			// jQuery(this).parents('#content_single').before(blockquote);
			// jQuery(this).find('blockquote').remove();
		// });
		if (jQuery('#content_single .entry').size() <= 1) {
			jQuery('#content_single .entry').each(function () {
				src = 'wp-content/uploads/ikona.png';
				jQuery(this).find('img').each(function () {
					if (jQuery(this).attr('title').indexOf('ikona') >= 0) {
						src = jQuery(this).attr('src');
						jQuery(this).remove();
					}
				});
				jQuery('#content_single_nav ul').append('<li><span class="activeSlide"><img src="'+src+'" alt="" /></span></li>');
				jQuery(this).find('.entry').jScrollPane({scrollbarWidth:21, scrollbarMargin:10, dragMaxHeight: 51, dragMinHeight: 51, showArrows: false });
				jQuery(this).find('img').each(function () {
					jQuery(this).parents('a').addClass('fancybox').attr('rel','entry-'+jQuery(idx).index());
				});
				fontsInit();
				fancyboxInit();
			});
		} else {
			jQuery('#content_single').cycle({ 
				fx:     'fade', 
				speed:  800, 
				timeout: 0, 
				pager:  '#content_single_nav ul',
				pagerAnchorBuilder: function(idx, slide) {
					src = 'wp-content/uploads/ikona.png';
					jQuery(slide).find('img').each(function () {
						if (jQuery(this).attr('title').indexOf('ikona') >= 0) {
							src = jQuery(this).attr('src');
							jQuery(this).remove();
						}
					});
					return '<li><a href=""><img src="'+src+'" alt="" /></a></li>'; 
				},
				cleartypeNoBg: true,
				after: function(idx, slide) {
					jQuery(slide).find('.entry').jScrollPane({scrollbarWidth:21, scrollbarMargin:10, dragMaxHeight: 51, dragMinHeight: 51, showArrows: false });
					jQuery(slide).find('img').each(function () {
						jQuery(this).parents('a').addClass('fancybox').attr('rel','entry-'+jQuery(idx).index());
					});
					fontsInit();
					fancyboxInit();
				}
			});
		}
	} catch(err) {}	 

	try {	
		jQuery('#page_slider_tn').cycle({ 
			fx:     'scrollHorz', 
			speed:  800, 
			timeout: 0, 
			pager:  '#page_slider_tn_nav',
			pagerAnchorBuilder: function(idx, slide) {
				return '<a href="">'+jQuery(slide).attr('title')+'</a>'; 
			},
			cleartypeNoBg: true,
			after: function(idx, slide) {
				jQuery(slide).find('.entry').jScrollPane({scrollbarWidth:21, scrollbarMargin:10, dragMaxHeight: 51, dragMinHeight: 51, showArrows: false });
				fontsInit();
			}
		});
	} catch(err) {}	 
	
	
	jQuery('label.hide').hide().each(function () {
		jQuery(this).next('input[type="text"], input[type="password"], textarea, select').val(jQuery(this).html());
		jQuery(this).next('input[type="text"], input[type="password"], textarea, select').attr('rel',jQuery(this).html());
		jQuery(this).hide();
	});
	jQuery('input[type="text"], input[type="password"], textarea').focus(function () {
		if (jQuery(this).val()==jQuery(this).attr('rel')) jQuery(this).val('');
		jQuery(this).removeClass('invalid');
		jQuery(this).addClass('focus');
		jQuery(this).parents('form').find('.error').hide();
	});
	jQuery('input[type="text"], input[type="password"], textarea').blur(function () {
		if (jQuery(this).val()=='') jQuery(this).val(jQuery(this).attr('rel'));
		jQuery(this).removeClass('focus');
	});
	
	jQuery('#commentform #name, #commentform #surename').keyup(function () {
		jQuery('#commentform #author').val(jQuery('#commentform #name').val()+' '+jQuery('#commentform #surename').val());
	});
	jQuery('#commentform').submit(function () {
		jQuery('.wpcf7-not-valid-tip').remove();
		valid = true;
		emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		jQuery('#commentform .text').each(function () {
			if (jQuery(this).val()=='' || (jQuery(this).attr('id')=='email' && !emailFilter.test(jQuery(this).val()))) {
				valid = false;
				jQuery(this).after('<span class="wpcf7-not-valid-tip hide">Proszę wypełnić wszystkie pola</span>')
				jQuery(this).next('.wpcf7-not-valid-tip').animate({height:'show'},200);
				jQuery('.wpcf7-not-valid-tip').mouseover(function () {
					jQuery(this).animate({height:'hide'},200);
					setTimeout("jQuery(this).remove()",201);
				});
				jQuery(this).mouseover(function () {
					jQuery(this).next('.wpcf7-not-valid-tip').animate({height:'hide'},200);
					setTimeout("jQuery(this).next('.wpcf7-not-valid-tip').remove()",201);
				});
			}
		});
		if (valid) {
			jQuery('.wpcf7-response-output').remove()
			jQuery('#commentform').append('<div class="wpcf7-response-output wpcf7-mail-sent-ok hide">Pytanie zostało przekazane do moderacji. Potwierdź je klikając w link wysłany mailem na adres podany w formularzu.</div>');
			jQuery('.wpcf7-response-output').animate({height:'show'},200);
			setTimeout("jQuery('.wpcf7-response-output').hide(200)",5000);
			setTimeout("jQuery('.wpcf7-response-output').remove()",5201	);
			return true;
		} else {
			jQuery('#commentform').append('<div class="wpcf7-response-output wpcf7-validation-errors wpcf7-mail-sent-ng hide">Wystąpił błąd. Sprawdź poprawność pól i wyślij ponownie.</div>');
			jQuery('.wpcf7-response-output').animate({height:'show'},200);
			return false;
		}
		return valid;
	});
});


jQuery(window).load(function(){
	fontsInit();
});
		
function itemShow(name, effect, duration, timeout) {
	setTimeout("jQuery('"+name+"').animate({"+effect+": 'show'}, "+duration+");",timeout);
}
function imgOver(){ 
	jQuery(this).animate({ marginTop: (-1)*17+'px' }, 200);
}
function imgOut(){ 
	jQuery(this).animate({ marginTop: 0 }, 200);
}
function slideOver(){
	clearTimeout(slideshow_pager_timeout);
	jQuery('#slideshow_pager a.current').removeClass('current');
	jQuery(this).addClass('current');
	idx = jQuery(this).parents('li').attr('rel');
	
	jQuery('#slideshow_pager a').each(function () {
		currIdx = jQuery('#slideshow_pager a.current').parents('li').attr('rel');
		idx = jQuery(this).parents('li').attr('rel');
		wdx = parseInt(182*jQuery(this).parents('li').attr('rel'))+slideshowOffset;
		if ( currIdx < idx ) { wdx = wdx + 30;	} 
		
		if (jQuery(this).hasClass('current')) {
			jQuery(this).parents('li').css({'z-index':2}).animate({ width: '212px', height: '106px', left: wdx}, 200);
			jQuery(this).animate({ width: '212px', height: '106px' }, 200);
			jQuery(this).find('.thumb_active').css({'z-index':2}).animate({ opacity: 'show' }, 400);
			jQuery(this).find('.thumb').css({'z-index':1}).animate({ width: '212px', height: '106px' },200);
			current = jQuery(this);
			setTimeout("current.find('.title').animate({ height: 'show'}, 200);",200);
		} else {
			jQuery(this).parents('li').css({'z-index':1}).animate({ width: '182px', height: '92px', left: wdx}, 200);
			jQuery(this).animate({ width: '182px', height: '92px' }, 200);
			jQuery(this).find('.thumb_active').css({'z-index':1}).animate({ opacity: 'hide' }, 200);
			jQuery(this).find('.thumb').css({'z-index':2}).animate({ width: '182px', height: '92px' }, 200);
			jQuery(this).find('.title').animate({ height: 'hide' }, 0);
		}
	});	
}

function slideOut(){ 
	jQuery(this).find('.title').animate({ height: 'hide' }, 0);
	slideshow_pager_timeout = setTimeout("slideOutCall()",10);
}
function slideOutCall(){ 
	jQuery('#slideshow_pager a.current').removeClass('current');
	jQuery('#slideshow_pager a').each(function () {
		wdx = parseInt(188*jQuery(this).parents('li').attr('rel'));
		jQuery(this).parents('li').css({'z-index':1}).animate({ width: '188px', height: '92px', left: wdx}, 200);
		jQuery(this).animate({ width: '188px', height: '92px' }, 200);
		jQuery(this).find('.thumb_active').css({'z-index':1}).animate({ opacity: 'hide' }, 200);
		jQuery(this).find('.thumb').css({'z-index':2}).animate({ width: '188px', height: '92px' }, 200);
		jQuery(this).find('.title').animate({ height: 'hide' }, 0);
	});
}

function fontsInit(){ 
	try {
		Cufon.replace('h1,h2,#slideshow_pager .title, .slider_nav strong, .entry p, .entry li, .entry td, .entry th, .entry h2, .entry h3, .entry h4, .entry h5, .entry h6', { fontFamily: 'DinPro' });
		Cufon.replace('#menu a, #page_slider_tn_nav a, .navigation a, .lead', { fontFamily: 'DinPro', hover: true });
	} catch(err) {}
}

function hoverInit(){ 
	jQuery('#slideshow_pager a').hoverIntent(slideOver,slideOut,{sensitivity: 1,timeout: 100});
}

function fancyboxInit(){ 
	jQuery('.fancybox').fancybox({
		'scrolling': 'no', 
		'titleShow': false, 
		'overlayOpacity':'.6',
		'overlayColor':'#000'//, 'onComplete': 
	});
}

