function uprav_kosik(pocet,id,typ){
	var html = $.ajax({
			type:"POST",
			url:"/soubory/ajax/kosik.php",
			data:"id="+id+"&pocet="+pocet+"&type="+typ,
			async:false
		}).responseText;
		if(html!=''){$(".video").hide();$.fancybox(html,{'hideOnContentClick':true});}
		uprav_head();	
	}
	function uprav_head(){
		var html = $.ajax({
			type:"POST",
			url:"/soubory/ajax/kosik.php",
			data:"type=head",
			async:false
		}).responseText;
		if(html=="Váš nákupní košík je prázdný"){$("#kosik").removeAttr("href");}else{$("#kosik").attr("href","/kosik/");}
		$("#kosik").empty().append(html);
	}
	function log(event, data, formatted) {
		if(formatted.split("..")[1]!=null){
			window.location.href=formatted.split("..")[1];
		}
	}
$(document).ready(function(){
	var hlp="";
	//nastav_dostup();
	$("#hledej").autocomplete("/soubory/ajax/search.php", {
		selectFirst: false,
		delay:100,
		width:355,
		formatItem: function(data, i, n, value) {
			if((value=="Kategorie")||(value=="Značky")||(value=="Produkty")){
				return '<a class="sear_kat">'+value.split("..")[0]+'</a>';
			}else{
				return '<a class="naddpis" href="'+value.split("..")[1]+'">'+value.split("..")[0]+'</a>';
			}
		},
		formatResult: function(data, value) {
			hlp=value.split("..")[1];
			return value.split("..")[0];
		},minChars: 2
	}).result(log);
	
	uprav_head();

	$(".foto a").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
	$(".k_kat_t").click(function(){
		if($(this).html()=="Zobrazit všechny kategorie"){
			$(".all_k").slideDown();
			$(this).html("Skrýt všechny kategorie");
		}else{
			$(".all_k").slideUp();
			$(this).html("Zobrazit všechny kategorie");
		}
	});
	$(".srov_del").live("click",function(){
		var html=$.ajax({type:"POST",url:"/soubory/ajax/porovnani.php",data:"type=del&id="+$(this).attr("rel"),dataType: "json",
async:false}).responseText;
		obj = jQuery.parseJSON(html);
		$(".srr_"+$(this).attr("rel")).parent(".pol").hide();
		$(".srr_text").empty().append(obj.text);
		if(obj.pocet==0){$(".srr_nic").parent(".pol").show();}
		if(obj.pocet<2){$(".ssr").hide();}
		$(".srovnani.prod[rel='"+$(this).attr("rel")+"']").html("Přidat ke srovnání");
		$(".srovnani[rel='"+$(this).attr("rel")+"']").removeClass("akt");
		$('.srovnej').removeClass("akt").attr("title","Přidat k porovnání");
	});
	$('.srovnani').live("click",function(){ 
		if($(this).html()!="Odebrat ze srovnání"){
			html=$.ajax({type:"POST",url:"/soubory/ajax/porovnani.php",data:"type=add&id="+$(this).attr("rel"),async:false}).responseText;$.fancybox(html,{'hideOnContentClick':false});
	 		$(".srovnani.prod").html("Odebrat ze srovnání");
			$(this).addClass("akt").attr("title","Porovnat vybrané produkty");
		}else{
			html=$.ajax({type:"POST",url:"/soubory/ajax/porovnani.php",data:"type=zobraz",async:false}).responseText;$.fancybox(html,{'hideOnContentClick':false});
		}
		//$('.srovnej').qtip("destroy").qtip({style:{name:"light",'width':130},position:{corner:{target: 'topRight',tooltip: 'bottomRight'}}});
	});
	$('tr:not(.nebarvy)').live({
		mouseenter:function(){$(this).css('background-color', '#FFFF99');},
		mouseleave:function(){$(this).css('background-color', '');}
	});
	$(".vyp_koupit").live("click",function(){uprav_kosik(1,$(this).attr("rel"),"add");});
	
	var novink=0;
	var myTimeOut;
	function zmena(prisne){ok=false;if(prisne===true){old=novink;if(novink<poc_new){novink++;}else{novink=0;}ok=true;}else{if(novink!=prisne){old=novink;novink=prisne;ok=true;}else{ok=false;}}
		if(ok==true){
			$(".news.c"+novink).fadeIn("slow");
			$(".news_navig > .c"+novink).addClass("akt");
			$(".news_navig > .c"+old).removeClass("akt");
			$(".news.c"+old).fadeOut("slow");
		}
		clearTimeout(myTimeOut);
		myTimeOut=setTimeout(function(){zmena(true);}, 7000);
	};
	$('.news').live({
		mouseenter:function(){clearTimeout(myTimeOut);$(".detail.c"+novink).addClass("hover");},
		mouseleave:function(){clearTimeout(myTimeOut);myTimeOut=setTimeout(function(){zmena(true);}, 7000);$(".detail.c"+novink).removeClass("hover");}
	});
	$(".news.c0").show();$(".news_navig > .c0").addClass("akt");myTimeOut=setTimeout(function(){zmena(true);}, 7000);
	$(".news_navig > li").click(function(){zmena($(this).attr("value"));});
	//best
	
	$(".nej").click(function(){
		if($(this).hasClass("akt")==false){
			$(".nej").removeClass("akt");
			$(this).addClass("akt");
			$(".vyp").fadeOut();
			$(".vyp."+$(this).attr("name")).fadeIn();
		}	
	});
	$('.odkaz').live({
		mouseenter:function(){$(this).parent(".pol").children(".jmeno").css({"text-decoration":"underline"});},
		mouseleave:function(){$(this).parent(".pol").children(".jmeno").css({"text-decoration":"none"});}
	});
	
//Úvodní bannery
	var novink3=0;
	var myTimeOut3;
	var old3=0;
	var ok3=true;
	function zmena3(prisne3){ok3=false;
		if(prisne3===true){
			old3=novink3;
			if(novink3<poc_new3){novink3++;}else{novink3=0;}
			ok3=true;
		}else{
			if(novink3!=prisne3){old3=novink3;novink3=prisne3;ok3=true;}else{ok3=false;}
		}
		if(ok3==true){$(".banb.cb"+old3).fadeOut("slow");
			$(".banb.cb"+novink3).fadeIn("slow");
			$(".news_navig3 > .cb"+novink3).addClass("akt");
			$(".news_navig3 > .cb"+old3).removeClass("akt");
		}
		clearTimeout(myTimeOut3);
		myTimeOut3=setTimeout(function(){zmena3(true);}, 8000);
	};
	$('.banb').live({
		mouseenter:function(){clearTimeout(myTimeOut3);},
		mouseleave:function(){clearTimeout(myTimeOut3);myTimeOut3=setTimeout(function(){zmena3(true);}, 8000);}
	});
	$(".banb.cb0").show();
	$(".news_navig3 > .cb0").addClass("akt");
	myTimeOut3=setTimeout(function(){zmena3(true);}, 8000);
	$(".news_navig3 > li").click(function(){zmena3($(this).attr("value"));});



	$("#send_search").click(function(){window.location.href="/search/"+$("#hledej").val();});
	$("#hledej").click(function(){hlp="";if($(this).val()=="Vyhledat..."){$(this).val("");}});
	$("#hledej").live("keypress",function(e){if(e.keyCode=='13'){
		if(hlp===""){
		window.location.href='/search/'+$(this).val();
		}}});
	$("#hledej").blur(function(){if($(this).val()==""){$(this).val("Vyhledat...");}});
	$('.reload_kos').qtip({style:{name:"blue",'width':80},position:{corner:{target: 'topleft',tooltip: 'bottomLeft'}}});
	$('.delet').qtip({style:{name:"red",'width':120,'border-width':'1px'},position:{corner:{target: 'topRight',tooltip: 'bottomRight'}}});
	$(".reload_kos").click(function(){
		if((parseFloat($(".in_"+$(this).attr("rel")).val()) == parseInt($(".in_"+$(this).attr("rel")).val())) && !isNaN($(".in_"+$(this).attr("rel")).val())){
			if($(".in_"+$(this).attr("rel")).val()==0){uprav_kosik($(".in_"+$(this).attr("rel")).val(),$(this).attr("rel"),"del");window.location.reload();}
			uprav_kosik($(".in_"+$(this).attr("rel")).val(),$(this).attr("rel"),"zmen");
			window.location.reload();
		}else{
			$.fancybox("Musíte zadat celé kladné číslo.",{'hideOnContentClick':true});
		}
	});		
	$('.delet').click(function(){
		uprav_kosik(0,$(this).attr("rel"),"del");
		window.location.reload();
	});
	/*STEP 2*/
	$('.poloz').children("img").qtip({style:{name:"blue",'width':140},position:{corner:{target: 'topRight',tooltip: 'bottomRight'}}});
	$('.poloz').live({
		mouseenter:function(){$(this).css('background-color', '#FFFF99');$(this).children("img").show();},
		mouseleave:function(){$(this).css('background-color', '#FFFFFF');$(this).children("img").hide();
		if($(this).children(".adr").hasClass("chyba")){$(this).children("img").show();}
		}
	});
	$('.kos_blok').live({
		mouseenter:function(){$(this).css('background-color', '#FFFF99');},
		mouseleave:function(){$(this).css('background-color', '#FFFFFF');}
	});
	function validace(id,rel){
		switch (rel){
		case 'nofree':
			if($("#"+id).val()==''){$("#"+id).addClass("chyba");$("#"+id).parent(".poloz").children("img").show();d=1;}else{d=0;$("#"+id).removeClass("chyba");$("#"+id).parent(".poloz").children("img").hide();}break;
		case 'psc':
			if(!/^\d{5}$/.test($("#"+id).val())){$("#"+id).addClass("chyba");$("#"+id).parent(".poloz").children("img").show();d=1;}else{d=0;$("#"+id).removeClass("chyba");$("#"+id).parent(".poloz").children("img").hide();}break;
			
		case 'email':
			if(!/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test($("#"+id).val())){$("#"+id).addClass("chyba");$("#"+id).parent(".poloz").children("img").show();d=1;}else{d=0;$("#"+id).removeClass("chyba");$("#"+id).parent(".poloz").children("img").hide();}break;
			
		case 'telefon':
			if(!/^[+]?[0-9]{9,12}$/.test($("#"+id).val())){$("#"+id).addClass("chyba");$("#"+id).parent(".poloz").children("img").show();d=1;}else{d=0;$("#"+id).removeClass("chyba");$("#"+id).parent(".poloz").children("img").hide();}break;
			
		case 'ico':
			if((!/^\d{8}$/.test($("#"+id).val()))&&($("#"+id).val()!='')){$("#"+id).addClass("chyba");$("#"+id).parent(".poloz").children("img").show();d=1;}else{d=0;$("#"+id).removeClass("chyba");$("#"+id).parent(".poloz").children("img").hide();}break;
			
		}
		return d;
	}
	$('input').blur(function(){if($(this).attr("rel")!=null){validace($(this).attr("id"),$(this).attr("rel"));}});

	$('.doda').click(function(){$('.pole.hide').toggle(400);});
	$('.step3').click(function(){d=0;p=0;step2=false;
		$("#faktur input").each(function(){step2=true;
			if($(this).attr("rel")!=null){
				d=d+validace($(this).attr("id"),$(this).attr("rel"));	
			}
		});
		$(".pole.hide input").each(function(){if($(this).val()!=''){p=p+1;}});
		if(p>0){
			$(".pole.hide input").each(function(){
				if($(this).attr("rel")!=null){
					d=d+validace($(this).attr("id"),$(this).attr("rel"));	
				}
			});
		}else{
			$(".pole.hide input").each(function(){
				$(this).removeClass("chyba");
				$(this).parent(".poloz").children("img").hide();
			});
		}
		if((d==0)&&(step2)){
			var html = $.ajax({
				type:"POST",
				url:"/soubory/ajax/kosik.php",
				data:"platba="+$(".platba:checked").val()+"&jmeno="+$("#jmeno").val()+"&firma="+$("#firma").val()+"&ulice="+$("#ulice").val()+"&mesto="+$("#mesto").val()+"&psc="+$("#psc").val()+"&email="+$("#email").val()+"&telefon="+$("#telefon").val()+"&ico="+$("#ico").val()+"&dic="+$("#dic").val()+"&cislo="+$("#cislo").val()+"&djmeno="+$("#djmeno").val()+"&dfirma="+$("#dfirma").val()+"&dulice="+$("#dulice").val()+"&dmesto="+$("#dmesto").val()+"&dpsc="+$("#dpsc").val()+"&dtelefon="+$("#dtelefon").val()+"&poznamka="+$("#poznamka").val()+"&type=kontakty",
				async:false
			}).responseText;
			if(html=='ok'){window.location.href='/kosik/rekapitulace/';}
		}else{if(!step2){window.location.href='/kosik/adresy-platba/';}}
	});
	
	$("#kon_odeslat").click(function(){
				var ret='<div class="fancy"><p class="h2">Odeslání zprávy</p><hr />';
				var b="";
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				if($("#jmeno").val()==''){ret=ret+"<div class='pol'>Musíte vyplnit jméno.</div>";$("#jmeno").css({"background":"#FFD5D5"});b="jmeno";}else{$("#jmeno").css({"background":"#F2F2F2"});}	
				if($("#email").val()==''){ret=ret+"<div class='pol'>Musíte vyplnit email.</div>";$("#email").css({"background":"#FFD5D5"});if(b==""){b="email";}}else{	
				if(reg.test($("#email").val()) == false){ret=ret+"<div class='pol'>Email musí být ve správném formátu.</div>";$("#email").css({"background":"#FFD5D5"});if(b==""){b="email";}}else{$("#email").css({"background":"#F2F2F2"});}}
				if($("#predmet").val()==''){ret=ret+"<div class='pol'>Musíte vyplnit text.</div>";$("#predmet").css({"background":"#FFD5D5"});if(b==""){b="predmet";}}else{$("#predmet").css({"background":"#F2F2F2"});}
				if($("#text").val()==''){ret=ret+"<div class='pol'>Musíte vyplnit text.</div>";$("#text").css({"background":"#FFD5D5"});if(b==""){b="text";}}else{$("#text").css({"background":"#F2F2F2"});}
				ret=ret+'</div>';
				if(b!=""){$.fancybox(ret,{'hideOnContentClick':true,'onClosed':function(){$("#"+b).focus();}});}else{
					var html = $.ajax({
						type:"POST",
						url:"/soubory/ajax/kontakty.php",
						data:"jmeno="+$("#jmeno").val()+"&email="+$("#email").val()+"&text="+$("#text").val()+"&predmet="+$("#predmet").val()+"&telefon="+$("#telefon").val(),
						async:false
					}).responseText;
					$.fancybox(html,{'hideOnContentClick':true});$("#jmeno").val("");$("#email").val("");$("#text").val("");$("#predmet").val("");$("#telefon").val("");
				}
			});
			



});

function chunk_split(body,chunklen,end){chunklen=parseInt(chunklen,10)||76;end=end || '\r\n';if(chunklen<1){return false;}return body.match(new RegExp(".{0," + chunklen + "}", "g")).join(end);}
function trim(str){str=str.replace(/^\s+/,'');for(var i=str.length-1;i>=0;i--){if(/\S/.test(str.charAt(i))){str=str.substring(0,i+1);break;}}return str;}
function strrev(string){string = string+'';var grapheme_extend = /(.)([\uDC00-\uDFFF\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065E\u0670\u06D6-\u06DC\u06DE-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0901-\u0903\u093C\u093E-\u094D\u0951-\u0954\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C01-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C82\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D02\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F90-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B6-\u17D3\u17DD\u180B-\u180D\u18A9\u1920-\u192B\u1930-\u193B\u19B0-\u19C0\u19C8\u19C9\u1A17-\u1A1B\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAA\u1C24-\u1C37\u1DC0-\u1DE6\u1DFE\u1DFF\u20D0-\u20F0\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA67C\uA67D\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C4\uA926-\uA92D\uA947-\uA953\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uFB1E\uFE00-\uFE0F\uFE20-\uFE26]+)/g;return string.replace(grapheme_extend, '$2$1').split('').reverse().join('');}

function preved_cenu(string){return strrev(trim(chunk_split(strrev(string),3," ")));}

 /*
 * jQuery UI selectmenu
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI
 */

(function($){$.widget("ui.selectmenu",{
	getter: "value",
	version: "1.8",
	eventPrefix: "selectmenu",
	options: {
		transferClasses: true,
		style: 'dropdown',
		positionOptions: {
			my: "left top",
			at: "left bottom",
			offset: null
		},
		width: null, 
		menuWidth: null, 
		handleWidth: 26,
		maxHeight: null,
		icons: null, 
		format: null,
		bgImage: function() {},
		wrapperElement: ""
	},	
	
	_create: function() {
		var self = this, o = this.options;
		
		// set a default id value
		var selectmenuId = this.element.attr('id') || 'ui-selectmenu-' +  Math.random().toString(16).slice(2, 10);
				
		//quick array of button and menu id's
		this.ids = [selectmenuId + '-' + 'button', selectmenuId + '-' + 'menu'];
				
		//define safe mouseup for future toggling
		this._safemouseup = true;
		
		//create menu button wrapper
		this.newelement = $('<a class="'+ this.widgetBaseClass +' ui-widget ui-state-default ui-corner-all" id="'+this.ids[0]+'" role="button" href="#" tabindex="0" aria-haspopup="true" aria-owns="'+this.ids[1]+'"></a>')
			.insertAfter(this.element);
		this.newelement.wrap(o.wrapperElement);
		
		//transfer tabindex
		var tabindex = this.element.attr('tabindex');
		if (tabindex){ this.newelement.attr('tabindex', tabindex); }
		
		//save reference to select in data for ease in calling methods
		this.newelement.data('selectelement', this.element);
		
		//menu icon
		this.selectmenuIcon = $('<span class="'+ this.widgetBaseClass +'-icon ui-icon"></span>')
			.prependTo(this.newelement);
			
		//append status span to button
		this.newelement.prepend('<span class="'+self.widgetBaseClass+'-status" />');
			
		//make associated form label trigger focus
		$('label[for='+this.element.attr('id')+']')
			.attr('for', this.ids[0])
			.bind('click', function(){
				self.newelement[0].focus();
				return false;
			});	
			
		//click toggle for menu visibility
		this.newelement
			.bind('mousedown', function(event){
				self._toggle(event, true);
				// make sure a click won't open/close instantly
				if (o.style == "popup"){
					self._safemouseup = false;
					setTimeout(function(){self._safemouseup = true;}, 300);
				}	
				return false;
			})
			.bind('click',function(){
				return false;
			})
			.keydown(function(event){
				var ret = false;
				switch (event.keyCode) {
					case $.ui.keyCode.ENTER:
						ret = true;
						break;
					case $.ui.keyCode.SPACE:
						self._toggle(event);	
						break;
					case $.ui.keyCode.UP:
						if (event.altKey) {
							self.open(event);
						} else {
							self._moveSelection(-1);
						}
						break;
					case $.ui.keyCode.DOWN:
						if (event.altKey) {
							self.open(event);
						} else {
							self._moveSelection(1);
						}
						break;
					case $.ui.keyCode.LEFT:
						self._moveSelection(-1);
						break;
					case $.ui.keyCode.RIGHT:
						self._moveSelection(1);
						break;
					case $.ui.keyCode.TAB:
						ret = true;
						break;
					default:
						ret = true;
						self._typeAhead(event.keyCode, 'mouseup');
						break;	
				}
				return ret;
			})
			.bind('mouseover focus', function(){ 
				if (!o.disabled) $(this).addClass(self.widgetBaseClass+'-focus ui-state-hover'); 
			})
			.bind('mouseout blur', function(){  
				if (!o.disabled) $(this).removeClass(self.widgetBaseClass+'-focus ui-state-hover'); 
			});
		
		//document click closes menu
		$(document).mousedown(function(event){
			self.close(event);
		});

		//change event on original selectmenu
		this.element
			.click(function(){ self._refreshValue(); })
            // newelement can be null under unclear circumstances in IE8 
			.focus(function () { if (this.newelement) { this.newelement[0].focus(); } });
		
		//original selectmenu width
		var selectWidth = this.element.width();		
		//set menu button width
		this.newelement.width( (o.width) ? o.width : selectWidth);
				
		//hide original selectmenu element
		this.element.hide();		
				
		//create menu portion, append to body
		this.list = $('<ul class="' + self.widgetBaseClass + '-menu ui-widget ui-widget-content" aria-hidden="true" role="listbox" aria-labelledby="'+this.ids[0]+'" id="'+this.ids[1]+'"></ul>').appendTo('body');				
		this.list.wrap(o.wrapperElement);				
				
		//transfer menu click to menu button
		this.list
			.keydown(function(event){
				var ret = false;
				switch (event.keyCode) {
					case $.ui.keyCode.UP:
						if (event.altKey) {
							self.close(event, true);
						} else {
							self._moveFocus(-1);
						}
						break;
					case $.ui.keyCode.DOWN:
						if (event.altKey) {
							self.close(event, true);
						} else {
							self._moveFocus(1);
						}
						break;	
					case $.ui.keyCode.LEFT:
						self._moveFocus(-1);
						break;
					case $.ui.keyCode.RIGHT:
						self._moveFocus(1);
						break;	
					case $.ui.keyCode.HOME:
						self._moveFocus(':first');
						break;		
					case $.ui.keyCode.PAGE_UP:
						self._scrollPage('up');
						break;	
					case $.ui.keyCode.PAGE_DOWN:
						self._scrollPage('down');
						break;
					case $.ui.keyCode.END:
						self._moveFocus(':last');
						break;		
					case $.ui.keyCode.ENTER:
					case $.ui.keyCode.SPACE:
						self.close(event,true);
						$(event.target).parents('li:eq(0)').trigger('mouseup');
						break;		
					case $.ui.keyCode.TAB:
						ret = true;
						self.close(event,true);
						break;	
					case $.ui.keyCode.ESCAPE:
						self.close(event,true);
						break;
					default:
						ret = true;
						break;	
				}
				return ret;
			});			
		
		// needed when window is resized
		$(window).resize(
			$.proxy(self._refreshPosition, this)
		);
	},
	_init: function() {
		var self = this, o = this.options;
		
		//serialize selectmenu element options	
		var selectOptionData = [];
		this.element
			.find('option')
			.each(function(){
				selectOptionData.push({
					value: $(this).attr('value'),
					text: self._formatText($(this).text()),
					selected: $(this).attr('selected'),
					classes: $(this).attr('class'),
					parentOptGroup: $(this).parent('optgroup').attr('label'),
					bgImage: o.bgImage.call($(this))
				});
			});		
				
		//active state class is only used in popup style
		var activeClass = (self.options.style == "popup") ? " ui-state-active" : "";
		
		// empty list so we can refresh the selectmenu via selectmenu()
		this.list.html("");
		
		//write li's
		for (var i = 0; i < selectOptionData.length; i++) {
			var thisLi = $('<li role="presentation"><a href="#" tabindex="-1" role="option" aria-selected="false">'+ selectOptionData[i].text +'</a></li>')
				.data('index',i)
				.addClass(selectOptionData[i].classes)
				.data('optionClasses', selectOptionData[i].classes|| '')
				.mouseup(function(event){
						if (self._safemouseup){
							var changed = $(this).data('index') != self._selectedIndex();
							self.index($(this).data('index'));
							self.select(event);
							if (changed){ self.change(event); }
							self.close(event,true);
						}
					return false;
				})
				.click(function(){
					return false;
				})
				.bind('mouseover focus', function(){ 
					self._selectedOptionLi().addClass(activeClass); 
					self._focusedOptionLi().removeClass(self.widgetBaseClass+'-item-focus ui-state-hover'); 
					$(this).removeClass('ui-state-active').addClass(self.widgetBaseClass + '-item-focus ui-state-hover'); 
				})
				.bind('mouseout blur', function(){ 
					if ($(this).is( self._selectedOptionLi().selector )){ $(this).addClass(activeClass); }
					$(this).removeClass(self.widgetBaseClass + '-item-focus ui-state-hover'); 
				});
				
			//optgroup or not...
			if (selectOptionData[i].parentOptGroup){
				// whitespace in the optgroupname must be replaced, otherwise the li of existing optgroups are never found
				var optGroupName = self.widgetBaseClass + '-group-' + selectOptionData[i].parentOptGroup.replace(/[^a-zA-Z0-9]/g, "");
				if(this.list.find('li.' + optGroupName).size()){
					this.list.find('li.' + optGroupName + ':last ul').append(thisLi);
				} else {
					$('<li role="presentation" class="'+self.widgetBaseClass+'-group '+optGroupName+'"><span class="'+self.widgetBaseClass+'-group-label">'+selectOptionData[i].parentOptGroup+'</span><ul></ul></li>')
						.appendTo(this.list)
						.find('ul')
						.append(thisLi);
				}
			} else {
				thisLi.appendTo(this.list);
			}
			
			//this allows for using the scrollbar in an overflowed list
			this.list.bind('mousedown mouseup', function(){ return false; });
			
			//append icon if option is specified
			if (o.icons){
				for (var j in o.icons){
					if (thisLi.is(o.icons[j].find)){
						thisLi
							.data('optionClasses', selectOptionData[i].classes + ' ' + self.widgetBaseClass + '-hasIcon')
							.addClass(self.widgetBaseClass + '-hasIcon');
						var iconClass = o.icons[j].icon || "";						
						thisLi
							.find('a:eq(0)')
							.prepend('<span class="'+self.widgetBaseClass+'-item-icon ui-icon ' +iconClass + '"></span>');
						if (selectOptionData[i].bgImage) {
							thisLi.find('span').css('background-image', selectOptionData[i].bgImage);
						}
					}
				}
			}
		}	
				
		// we need to set and unset the CSS classes for dropdown and popup style
		var isDropDown = (o.style == 'dropdown') ? true : false;
		this.newelement
			.toggleClass(self.widgetBaseClass+"-dropdown", isDropDown)
			.toggleClass(self.widgetBaseClass+"-popup", !isDropDown);
		this.list
			.toggleClass(self.widgetBaseClass+"-menu-dropdown ui-corner-bottom", isDropDown)
			.toggleClass(self.widgetBaseClass+"-menu-popup ui-corner-all", !isDropDown)
		// add corners to top and bottom menu items
		.find('li:first')
			.toggleClass("ui-corner-top", !isDropDown)
		.end().find('li:last')
			.addClass("ui-corner-bottom");
		this.selectmenuIcon
			.toggleClass('ui-icon-triangle-1-s', isDropDown)
			.toggleClass('ui-icon-triangle-2-n-s', !isDropDown);
					
		//transfer classes to selectmenu and list
		if (o.transferClasses){
			var transferClasses = this.element.attr('class') || ''; 
			this.newelement.add(this.list).addClass(transferClasses);
		}
		
		//original selectmenu width
		var selectWidth = this.element.width();
		
		//set menu width to either menuWidth option value, width option value, or select width 
		if (o.style == 'dropdown') { 
			this.list.width( (o.menuWidth) ? o.menuWidth : ((o.width) ? o.width : selectWidth)); 
		} else { 
			this.list.width( (o.menuWidth) ? o.menuWidth : ((o.width) ? o.width - o.handleWidth : selectWidth - o.handleWidth)); 
		}	
		
		// calculate default max height
		if (o.maxHeight) {
			//set max height from option 
			 if (o.maxHeight < this.list.height()){ this.list.height(o.maxHeight); }
		} else {
			if (!o.format && ($(window).height() / 3) < this.list.height()) {
				o.maxHeight = $(window).height() / 3;
				this.list.height(o.maxHeight);
			}
		}
		//save reference to actionable li's (not group label li's)
		this._optionLis = this.list.find('li:not(.'+ self.widgetBaseClass +'-group)');
						
		//transfer disabled state
		if (this.element.attr('disabled') == true){ this.disable(); }
		
		//update value
		this.index(this._selectedIndex());		
		
		// needed when selectmenu is placed at the very bottom / top of the page
        window.setTimeout(function() {
            self._refreshPosition();
        }, 200);
	},
	destroy: function() {
		this.element.removeData(this.widgetName)
			.removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
			.removeAttr('aria-disabled')
			.unbind("click");
	
		//unbind click on label, reset its for attr
		$('label[for='+this.newelement.attr('id')+']')
			.attr('for',this.element.attr('id'))
			.unbind('click');
		this.newelement.remove();
		// FIXME option.wrapper needs
		this.list.remove();
		this.element.show();	
		
		// call widget destroy function
		$.Widget.prototype.destroy.apply(this, arguments);
	},
	_typeAhead: function(code, eventType){
		var self = this;
		//define self._prevChar if needed
		if (!self._prevChar){ self._prevChar = ['',0]; }
		var C = String.fromCharCode(code);
		c = C.toLowerCase();
		var focusFound = false;
		function focusOpt(elem, ind){
			focusFound = true;
			$(elem).trigger(eventType);
			self._prevChar[1] = ind;
		}
		this.list.find('li a').each(function(i){	
			if(!focusFound){
				var thisText = $(this).text();
				if( thisText.indexOf(C) == 0 || thisText.indexOf(c) == 0){
						if(self._prevChar[0] == C){
							if(self._prevChar[1] < i){ focusOpt(this,i); }	
						}
						else{ focusOpt(this,i); }	
				}
			}
		});
		this._prevChar[0] = C;
	},
	// returns some usefull information, called by callbacks only
	_uiHash: function(){
		var index = this.index();
		return {
			index: index,
			option: $("option", this.element).get(index),
			value: this.element[0].value
		};
	},
	open: function(event){
		var self = this;
		var disabledStatus = this.newelement.attr("aria-disabled");
		if(disabledStatus != 'true'){
			this._refreshPosition();
			this._closeOthers(event);
			this.newelement
				.addClass('ui-state-active');
			if (self.options.wrapperElement) {
				this.list.parent().appendTo('body');
			} else {
				this.list.appendTo('body');
			}
			this.list.addClass(self.widgetBaseClass + '-open')
				.attr('aria-hidden', false)
				.find('li:not(.'+ self.widgetBaseClass +'-group):eq('+ this._selectedIndex() +') a')[0].focus();	
			if (this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-all').addClass('ui-corner-top'); }	
			this._refreshPosition();
			this._trigger("open", event, this._uiHash());
		}
	},
	close: function(event, retainFocus){
		if(this.newelement.is('.ui-state-active')){
			this.newelement
				.removeClass('ui-state-active');
			this.list
				.attr('aria-hidden', true)
				.removeClass(this.widgetBaseClass+'-open');
			if (this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-top').addClass('ui-corner-all'); }
			if (retainFocus){this.newelement.focus();}	
			this._trigger("close", event, this._uiHash());
		}
	},
	change: function(event) {
		this.element.trigger('change');
		this._trigger("change", event, this._uiHash());
	},
	select: function(event) {
		this._trigger("select", event, this._uiHash());
	},
	_closeOthers: function(event){
		$('.'+ this.widgetBaseClass +'.ui-state-active').not(this.newelement).each(function(){
			$(this).data('selectelement').selectmenu('close',event);
		});
		$('.'+ this.widgetBaseClass +'.ui-state-hover').trigger('mouseout');
	},
	_toggle: function(event,retainFocus){
		if(this.list.is('.'+ this.widgetBaseClass +'-open')){ this.close(event,retainFocus); }
		else { this.open(event); }
	},
	_formatText: function(text){
		return this.options.format ? this.options.format(text) : text;
	},
	_selectedIndex: function(){
		return this.element[0].selectedIndex;
	},
	_selectedOptionLi: function(){
		return this._optionLis.eq(this._selectedIndex());
	},
	_focusedOptionLi: function(){
		return this.list.find('.'+ this.widgetBaseClass +'-item-focus');
	},
	_moveSelection: function(amt){
		var currIndex = parseInt(this._selectedOptionLi().data('index'), 10);
		var newIndex = currIndex + amt;
		return this._optionLis.eq(newIndex).trigger('mouseup');
	},
	_moveFocus: function(amt){
		if(!isNaN(amt)){
			var currIndex = parseInt(this._focusedOptionLi().data('index') || 0, 10);
			var newIndex = currIndex + amt;
		}
		else { var newIndex = parseInt(this._optionLis.filter(amt).data('index'), 10); }
		
		if(newIndex < 0){ newIndex = 0; }
		if(newIndex > this._optionLis.size()-1){
			newIndex =  this._optionLis.size()-1;
		}
		var activeID = this.widgetBaseClass + '-item-' + Math.round(Math.random() * 1000);
		
		this._focusedOptionLi().find('a:eq(0)').attr('id','');
		this._optionLis.eq(newIndex).find('a:eq(0)').attr('id',activeID).focus();
		this.list.attr('aria-activedescendant', activeID);
	},
	_scrollPage: function(direction){
		var numPerPage = Math.floor(this.list.outerHeight() / this.list.find('li:first').outerHeight());
		numPerPage = (direction == 'up') ? -numPerPage : numPerPage;
		this._moveFocus(numPerPage);
	},
	_setOption: function(key, value) {
		this.options[key] = value;
		if (key == 'disabled') {
			this.close();
			this.element
				.add(this.newelement)
				.add(this.list)
					[value ? 'addClass' : 'removeClass'](
						this.widgetBaseClass + '-disabled' + ' ' +
						this.namespace + '-state-disabled')
					.attr("aria-disabled", value);
		}
	},
	index: function(newValue) {
		if (arguments.length) {
			this.element[0].selectedIndex = newValue;
			this._refreshValue();
		} else {
			return this._selectedIndex();
		}
	},
	value: function(newValue) {
		if (arguments.length) {
			// FIXME test for number is a kind of legacy support, could be removed at any time (Dez. 2010)
			// see this post for more info: https://github.com/fnagel/jquery-ui/issues#issue/33
			if (typeof newValue == "number") {
					this.index(newValue);
			} else if (typeof newValue == "string") {
				this.element[0].value = newValue;
				this._refreshValue();
			}
		} else {
			return this.element[0].value;
		}
	},
	_refreshValue: function() {
		var activeClass = (this.options.style == "popup") ? " ui-state-active" : "";
		var activeID = this.widgetBaseClass + '-item-' + Math.round(Math.random() * 1000);
		//deselect previous
		this.list
			.find('.'+ this.widgetBaseClass +'-item-selected')
			.removeClass(this.widgetBaseClass + "-item-selected" + activeClass)
			.find('a')
			.attr('aria-selected', 'false')
			.attr('id', '');
		//select new
		this._selectedOptionLi()
			.addClass(this.widgetBaseClass + "-item-selected" + activeClass)
			.find('a')
			.attr('aria-selected', 'true')
			.attr('id', activeID);
			
		//toggle any class brought in from option
		var currentOptionClasses = this.newelement.data('optionClasses') ? this.newelement.data('optionClasses') : "";
		var newOptionClasses = this._selectedOptionLi().data('optionClasses') ? this._selectedOptionLi().data('optionClasses') : "";
		this.newelement
			.removeClass(currentOptionClasses)
			.data('optionClasses', newOptionClasses)
			.addClass( newOptionClasses )
			.find('.'+this.widgetBaseClass+'-status')
			.html( 
				this._selectedOptionLi()
					.find('a:eq(0)')
					.html() 
			);
			
		this.list.attr('aria-activedescendant', activeID);
	},
	_refreshPosition: function(){	
		var o = this.options;				
		// if its a native pop-up we need to calculate the position of the selected li
		if (o.style == "popup" && !o.positionOptions.offset) {
			var selected = this._selectedOptionLi();
			var _offset = "0 -" + (selected.outerHeight() + selected.offset().top - this.list.offset().top);
		}
		this.list
			.css({
				zIndex: 2000
			})
			.position({
				// set options for position plugin
				of: o.positionOptions.of || this.newelement,
				my: o.positionOptions.my,
				at: o.positionOptions.at,
				offset: o.positionOptions.offset || _offset
			});
	}
});
})(jQuery);

(function(d){function g(a){var b=a||window.event,i=[].slice.call(arguments,1),c=0,h=0,e=0;a=d.event.fix(b);a.type="mousewheel";if(a.wheelDelta)c=a.wheelDelta/120;if(a.detail)c=-a.detail/3;e=c;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){e=0;h=-1*c}if(b.wheelDeltaY!==undefined)e=b.wheelDeltaY/120;if(b.wheelDeltaX!==undefined)h=-1*b.wheelDeltaX/120;i.unshift(a,c,h,e);return d.event.handle.apply(this,i)}var f=["DOMMouseScroll","mousewheel"];d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=
f.length;a;)this.addEventListener(f[--a],g,false);else this.onmousewheel=g},teardown:function(){if(this.removeEventListener)for(var a=f.length;a;)this.removeEventListener(f[--a],g,false);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);

;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">Chyba<br />Velice se omlouváme.</p>');
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){$(".video").show();u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);
