$(document).ready(function(){

	// Slider with quick nav on the main page
	$('#slajdr').show();
	$('#slajdr').stop().animate({'marginLeft':'-880px','opacity':'.5'},1500);
	$('#slajdr').hover(
	function () {
		$(this).stop().animate({'marginLeft':'0','opacity':'.9'},200);
	},
	function () {
		$(this).stop().animate({'marginLeft':'-880px','opacity':'.5'},1500);
	}
	);

	// Fancybox
	$(".foto a,.vedouci a.fancybox").attr("rel","galerie").fancybox({
		'overlayColor'	: '#000',
		'overlayOpacity': 0.2,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'	: 'over',
		'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &ndash; ' + title : '') + '</span>';
		}
	});
	$(".boxik").fancybox({
		'width'				: '90%',
		'height'			: '75%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	/* PDF in Fancybox */
/*	$("a[href$=pdf]").attr("href", function() {	return this.href + "#zoom=100" }).fancybox({
		'type'			: 'iframe',
		'margin'		: 0,
		'width'			: 980,
		'height'		: '80%',
		'autoScale'		: true,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'titlePosition'	: 'inside'
	});*/

	// Hide images before scrolling page
	$("div.foto img").not("div#text-kniha img").lazyload({ effect: "fadeIn", placeholder : "/design/placeholder.png" });

	// Antispam
	$("a.antispam").each(function(){
		var email = $(this).text();
		$(this).attr({ 
		  href: "mailto:" + email
		});
		var title = $(this).attr("title");
		if (title != '') {
			$(this).text(title);
		} 
	});

	// jQuery URLinternal plugin
	// Test if a URL is internal
	var url = "http://roskopov.open-art.cz/";
	if ( $.isUrlInternal( url ) ) { }
	// Open external links in new window

	$("#obal a:urlExternal").attr("target","_blank").attr("href", function() {
		return this.href + "#referrer=roskopov.open-art.cz"
	});
	// http://benalman.com/projects/jquery-urlinternal-plugin/

	// Smooth scrolling
	function filterPath(string) {
	return string
	.replace(/^\//,'')
	.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	.replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	var scrollElem = scrollableElement('html', 'body');
	
	$('a[href*=#]').each(function() {
	var thisPath = filterPath(this.pathname) || locationPath;
	if (  locationPath == thisPath
	&& (location.hostname == this.hostname || !this.hostname)
	&& this.hash.replace(/#/,'') ) {
	  var $target = $(this.hash), target = this.hash;
	  if (target) {
		var targetOffset = $target.offset().top;
		$(this).click(function(event) {
		  event.preventDefault();
		  $(scrollElem).animate({scrollTop: targetOffset}, 900, function() {
			location.hash = target;
		  });
		});
	  }
	}
	});
	// Use the first element that is "scrollable"
	function scrollableElement(els) {
	for (var i = 0, argLength = arguments.length; i <argLength; i++) {
	  var el = arguments[i],
		  $scrollElement = $(el);
	  if ($scrollElement.scrollTop()> 0) {
		return el;
	  } else {
		$scrollElement.scrollTop(1);
		var isScrollable = $scrollElement.scrollTop()> 0;
		$scrollElement.scrollTop(0);
		if (isScrollable) {
		  return el;
		}
	  }
	}
	return [];
	}
	// http://css-tricks.com/snippets/jquery/smooth-scrolling/

	// Scroll up
	// hide #nahoru first
	$("#nahoru").hide();
	// fade in #nahoru
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#nahoru').fadeIn();
			} else {
				$('#nahoru').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#nahoru a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});

});

/*
 * urlInternal - v1.0 - 10/7/2009
 * http://benalman.com/projects/jquery-urlinternal-plugin/
 * 
 * Copyright (c) 2009 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var g,i=!0,r=!1,m=window.location,h=Array.prototype.slice,b=m.href.match(/^((https?:\/\/.*?\/)?[^#]*)#?.*$/),u=b[1]+"#",t=b[2],e,l,f,q,c,j,x="elemUrlAttr",k="href",y="src",p="urlInternal",d="urlExternal",n="urlFragment",a,s={};function w(A){var z=h.call(arguments,1);return function(){return A.apply(this,z.concat(h.call(arguments)))}}$.isUrlInternal=q=function(z){if(!z||j(z)){return g}if(a.test(z)){return i}if(/^(?:https?:)?\/\//i.test(z)){return r}if(/^[a-z\d.-]+:/i.test(z)){return g}return i};$.isUrlExternal=c=function(z){var A=q(z);return typeof A==="boolean"?!A:A};$.isUrlFragment=j=function(z){var A=(z||"").match(/^([^#]?)([^#]*#).*$/);return !!A&&(A[2]==="#"||z.indexOf(u)===0||(A[1]==="/"?t+A[2]===u:!/^https?:\/\//i.test(z)&&$('<a href="'+z+'"/>')[0].href.indexOf(u)===0))};function v(A,z){return this.filter(":"+A+(z?"("+z+")":""))}$.fn[p]=w(v,p);$.fn[d]=w(v,d);$.fn[n]=w(v,n);function o(D,C,B,A){var z=A[3]||e()[(C.nodeName||"").toLowerCase()]||"";return z?!!D(C.getAttribute(z)):r}$.expr[":"][p]=w(o,q);$.expr[":"][d]=w(o,c);$.expr[":"][n]=w(o,j);$[x]||($[x]=function(z){return $.extend(s,z)})({a:k,base:k,iframe:y,img:y,input:y,form:"action",link:k,script:y});e=$[x];$.urlInternalHost=l=function(B){B=B?"(?:(?:"+Array.prototype.join.call(arguments,"|")+")\\.)?":"";var A=new RegExp("^"+B+"(.*)","i"),z="^(?:"+m.protocol+")?//"+m.hostname.replace(A,B+"$1").replace(/\\?\./g,"\\.")+(m.port?":"+m.port:"")+"/";return f(z)};$.urlInternalRegExp=f=function(z){if(z){a=typeof z==="string"?new RegExp(z,"i"):z}return a};l("www")})(jQuery);
// Ask Ben Alman for using this script in yours commercial website & donate!, please
