$(document).ready(function(){
	if(typeof reload_sae != 'function') {
		// pokud neni pripojen main.js, ktery vola reload sae, musim si ho zavolat sam
		reload_sae_pretty_photo('');
	}
});

function reload_sae_pretty_photo(element) {
	var ext_filter_fn=function(index) {
		return ($(this).attr('href').toLowerCase().match(/\.[jpeg|jpg|gif|bmp|png]+$/));
	}
	
	/*
		hledani vsech a.ifr a.fthumb uvnitr #center .ff_page
		- cele je to tak slozite, protoze element, ve kterem se se hleda uz muze byt v #center (musi se prochazet rodice)
	*/
	var search=(element) ? $(element).parents().get() : [];
	search[search.length]=$(element).get(0);
	if(search!='' && $(search).filter('#center').length!=0) { // element je uvnitr centeru
		if($(search).filter('.ff_page').length!=0) { // element je uvnitr ff_page
			$("a.ifr",element).filter(ext_filter_fn).attr('rel','prettyPhoto[center_ff_pages]');
			$("a.fthumb",element).filter(ext_filter_fn).attr('rel','prettyPhoto[center_ff_pages]');
		} else {
			$(".ff_page a.ifr",element).filter(ext_filter_fn).attr('rel','prettyPhoto[center_ff_pages]');
			$(".ff_page a.fthumb",element).filter(ext_filter_fn).attr('rel','prettyPhoto[center_ff_pages]');
		}
	} else {
		$("#center .ff_page a.ifr",element).filter(ext_filter_fn).attr('rel','prettyPhoto[center_ff_pages]');
		$("#center .ff_page a.fthumb",element).filter(ext_filter_fn).attr('rel','prettyPhoto[center_ff_pages]');
	}
	
	
	$(".filemanager",element).each(function(){
		$("a.fthumb",this).filter(ext_filter_fn).attr('rel','prettyPhoto['+this.id+']');
	});
	
	// vsechny, co jeste nemaj rel, sup s nema
	//# - v tuhle chvili odstaveno, dela to PP i v FM WEBU
	//#$("a.ifr:not([rel]),a.fthumb:not([rel]),",element).attr('rel','prettyPhoto');
	
	$("a[rel^='prettyPhoto']",element).prettyPhoto({
			theme: 'facebook',
			markup: '<div class="pp_pic_holder"> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details clearfix"> \
											<a class="pp_close" href="#">Close</a> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
											<p class="pp_description"></p> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div> \
					<div class="ppt"></div>',
	});
}
