
var canHover = true;

function GenerateCustomFckGallery(files_array)
{
		var result="";
		result+="<div class='gallery-env'>";		
		
		for (var a=0;a<files_array.length;a++){
			result+="<a class='nyro' href=\""+files_array[a].path+"\" rel=\"lightbox[gallery]\"><img alt=\"\" src=\""+files_array[a].thumb+"\" /></a>";
		}
		
		result+="<div class='cleaner'></div></div>";
		return result;
}

try {
		
	// LOAD	
	$(window).load(function () {
		/* grayscale */
		/*
	 	$('#footer-env .list img').each(function(){
			grayscale($(this));
		});
		*/

		// --------------------------
		// FACEBOOK pluginy
		// upravit!!!!
		var cultureInfo = $('html').attr('lang').replace('-','_');

		$("#fbLike").html('<iframe src="http://www.facebook.com/plugins/like.php?locale='+cultureInfo+'&amp;href='+document.location+'&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=40" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:40px;" allowTransparency="true">Facebook</iframe>');
		
		$(".CZ #fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FSKRIVANEK-Ceska-republika%2F178027796325&amp;width=292&amp;colorscheme=light&amp;connections=10&amp;stream=true&amp;header=true&amp;height=587" scrolling="no" frameborder="0" allowTransparency="true">Skrivanek</iframe>');
		$(".PL #fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2FSkrivanekPolska&amp;width=292&amp;colorscheme=light&amp;show_faces=true&amp;stream=true&amp;header=true&amp;height=427" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:427px;" allowTransparency="true">Skrivanek</iframe>');
		//$(".LV #fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2Fpages%2Fmanage%2F%23%21%2Fpages%2FSkrivanek-Latvia-Starp-mani-un-Tevi-ir-valoda%2F83799239628&amp;width=292&amp;colorscheme=light&amp;show_faces=true&amp;stream=true&amp;header=true&amp;height=427" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:427px;" allowTransparency="true"></iframe>');
		$(".lang12 #fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2Fpages%2Fmanage%2F%23%21%2Fpages%2FSkrivanek-Latvia-Starp-mani-un-Tevi-ir-valoda%2F83799239628&amp;width=292&amp;colorscheme=light&amp;show_faces=true&amp;stream=true&amp;header=true&amp;height=427" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:427px;" allowTransparency="true"></iframe>');
		$(".SI #fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FSKRIVANEK-prevajanje-tolma%C4%8Denje-jezikovna-%C5%A1ola%2F76178507073&amp;width=292&amp;colorscheme=light&amp;show_faces=true&amp;stream=true&amp;header=true&amp;height=427" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:427px;" allowTransparency="true"></iframe>');
		$(".SK #fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FSKRIVANEK-Slovensko%2F319922785386&amp;width=292&amp;colorscheme=light&amp;show_faces=false&amp;stream=true&amp;header=true&amp;height=427" allowTransparency="true"></iframe>');
				
		if($("#fbLikeBox .panel iframe").length <= 0)
		{
			$("#fbLikeBox .panel").html('<iframe src="http://www.facebook.com/plugins/likebox.php?locale='+cultureInfo+'&amp;href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FSKRIVANEK-Ceska-republika%2F178027796325%23%21%2Fpages%2FSkrivanek-Group%2F180853471980&amp;width=292&amp;colorscheme=light&amp;show_faces=true&amp;stream=true&amp;header=true&amp;height=427" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:427px;" allowTransparency="true"> </iframe>');
		}

		// ----------------------------
		/* ROZRAZUJICI FORMULAR  */

		/*
		$("#testForm select").change(function(){
			console.log( $(this).val() );
		});
		$("#testForm input[type='radio']").click(function(){
			console.log( $(this).val() );
		});
		*/

		$("#provIDselect").change(function(){
			var thisProvId = $(this).find("option:selected").attr("provid");
			$("#provID").val( thisProvId );
		});

		var sentences = [
			{id:"sentence1",answers:["you will feel better if you stop smoking", "if you stop smoking you will feel better"]}
		];

		$("#testForm").submit(function(){
												
			// --------------------------
			// --- ziskavani bodovani pro jednotlive casti
			// --------------------------
			
			function getPartScore( pPartId ){
				
				var normalSelector = "#" + pPartId + " .normal select";
				var normalSelectorRadio = "#" + pPartId + " .normal input[type='radio']:checked";
				var multipleSelector = "#" + pPartId + " .multiple";
				var specialSelector = "#" + pPartId + " .special";
				var normalDoubleSelector = "#" + pPartId + " .normalDouble select";
				var tempSum = 0;
				
				// ----------------------------------------------------
				
				// normalni odpovedi
				$(normalSelector).each(function(){
					var thisVal = parseInt( $(this).val() );
					tempSum += thisVal;
				});				
				
				// normalni odpovedi za dva body
				$(normalDoubleSelector).each(function(){
					var thisVal = (parseInt( $(this).val() ));
					tempSum += (thisVal * 2);
				});				
				
				// ----------------------------------------------------
				
				// normalni odpovedi - radio
				$(normalSelectorRadio).each(function(){
					var thisVal = parseInt( $(this).val() );
					tempSum += thisVal;
				});				
				
				// ----------------------------------------------------
				
				// vicenasobne odpovedi - veta slozena z vice selectboxu
				$(multipleSelector).each(function(){				

					// nacteni vsech selektu pro danou vetu
					var thisSelect = $(this).find("select");				
					// celkovy pocet selectboxu v dane vete
					var thisSelectCount = thisSelect.length;
					// celkovy pocet spravne vyplnenych selektu v dane vete
					var thisSelectSum = 0;				

					// spocitani spravne odpovezenych slov v dane vete
					thisSelect.each(function(){
						var thisVal = parseInt( $(this).val() );
						thisSelectSum += thisVal;
					});

					// pokud jsou vsechny slova ve vete spravne tak pricti bod do celkoveho skore
					if( thisSelectSum == thisSelectCount ){ tempSum++; }				
				});				
				
				// ----------------------------------------------------
				
				$(specialSelector).each(function(){

					var thisId = $(this).attr("id");		
					var thisOptionSelected = $(this).find("option:selected");
					var thisOptionSelectedSize = thisOptionSelected.size() - 1;
					var thisSentence = "";

					// poskladani vety
					thisOptionSelected.each(function(i){					
						thisSentence = thisSentence + $(this).text();
						// pricitani mezer jen pokud se nejedna o posledni prvek
						if( i < thisOptionSelectedSize ){
							thisSentence += " ";
						}
					});

					// kontrola spravnosti vety podle pole spravnych odpovedi
					for( i=0; i< sentences.length; i++ ){

						// ulozeni udaju o aktualnim objektu
						var sentenceId = sentences[i].id;
						var sentenceAnswers = sentences[i].answers;

						// kontrola odpovedi podle ID zvolene vety
						if( sentenceId == thisId ){

							// prochazeni vsech moznych variant odpovedi
							for( j=0; j< sentenceAnswers.length; j++ ){

								// nalezena spravna odpoved
								if( sentenceAnswers[j] == thisSentence ){ 
									tempSum++;	// pricteni bodu za spravnou odpoved
									break;		// vyskoceni z for-eache
								}

							}	// for(j)
						}

					}	// for(i)

				});	// special.each				
				
				return parseInt( tempSum );
			}
			
			// --------------------------
			// --- ziskavani bodovani pro jednotlive casti
			// --------------------------			
			
			var part1Score = getPartScore("part1");
			var part2Score = getPartScore("part2");
			var part3Score = getPartScore("part3");			
			var part4Score = getPartScore("part4");			
			var part5Score = getPartScore("part5");			

			var sum = 0;
			var testFormLang = $("#testFormLang").val();
						
			sum = part1Score;
			
			if( testFormLang == "en" ){
				if( (part1Score >= 12) ){ sum += part2Score; }
			
				if( (part1Score >= 12) && 
					(part2Score >= 12) ){ sum += part3Score; }						
				
				if( (part1Score >= 12) &&
					(part2Score >= 12) &&
					(part3Score >= 14) ){ sum += part4Score; }						

				if( (part1Score >= 12) &&
					(part2Score >= 12) &&
					(part3Score >= 14) &&
					(part4Score >= 12) ){ sum += part5Score; }						
			}
			if( testFormLang == "de" ){
				if( (part1Score >= 10) ){ sum += part2Score; }
			
				if( (part1Score >= 10) && 
					(part2Score >= 10) ){ sum += part3Score; }						
				
				if( (part1Score >= 10) &&
					(part2Score >= 10) &&
					(part3Score >= 10) ){ sum += part4Score; }				
			}				
															
			var level = "";
			var levelDescr = "";
									
			if( testFormLang == "en" ){
				/*
				if( sum>=0 && sum<=7 ){ 	level="A1"; levelDescr="úplný začátečník"; }
				if( sum>=8 && sum<=22 ){ 	level="A2"; levelDescr="začátečník I"; }
				if( sum>=23 && sum<=38 ){ 	level="A2"; levelDescr="začátečník II";  }
				if( sum>=39 && sum<=50 ){ 	level="B1"; levelDescr="mírně pokročilý I"; }
				if( sum>=51 && sum<=62 ){ 	level="B1"; levelDescr="mírně pokročilý II"; }
				if( sum>=63 && sum<=75 ){ 	level="B2"; levelDescr="středně pokročilý I"; }
				if( sum>=76 && sum<=88 ){ 	level="B2"; levelDescr="středně pokročilý II"; }
				if( sum>=89 && sum<=101 ){ 	level="C1"; levelDescr="velmi pokročilý I"; }
				if( sum>=102 && sum<=114 ){ level="C1"; levelDescr="Advanced"; }
				if( sum>=115 && sum<=121 ){	level="C2"; levelDescr="Proficiency I"; }
				if( sum>=122 && sum<=127 ){	level="C2"; levelDescr="Proficiency II"; }
				*/
				
				if( sum>=0 && sum<=7 ){      level="A1"; levelDescr="úplný začátečník"; }                               
				if( sum>=8 && sum<=22 ){     level="A2"; levelDescr="začátečník I"; }                           
				if( sum>=23 && sum<=38 ){    level="A2"; levelDescr="začátečník II";  }            
				if( sum>=39 && sum<=50 ){    level="B1"; levelDescr="mírně pokročilý I"; }                  
				if( sum>=51 && sum<=62 ){    level="B1"; levelDescr="mírně pokročilý II"; }                  
				if( sum>=63 && sum<=75 ){    level="B1+"; levelDescr="mírně pokročilý + I"; }                                  
				if( sum>=76 && sum<=88 ){    level="B1+"; levelDescr="mírně pokročilý + II"; }                      
				if( sum>=89 && sum<=101 ){   level="B2"; levelDescr="středně pokročilý I"; }               
				if( sum>=102 && sum<=114 ){  level="B2"; levelDescr="středně pokročilý II"; }                       
				if( sum>=115 && sum<=121 ){  level="C1"; levelDescr="velmi pokročilý I"; }                          
				if( sum>=122 && sum<=127 ){  level="C1"; levelDescr="velmi pokročilý II"; }
				
				
			}
			if( testFormLang == "de" ){
				/*
				if( sum>=0 && sum<=7 ){ 	level="A1"; levelDescr="úplný začátečník"; }
				if( sum>=8 && sum<=12 ){ 	level="A2"; levelDescr="falešný začátečník I"; }
				if( sum>=13 && sum<=19 ){ 	level="A2"; levelDescr="falešný začátečník II";  }
				if( sum>=20 && sum<=29 ){ 	level="B1"; levelDescr="mírně pokročilí I"; }
				if( sum>=30 && sum<=40 ){ 	level="B1"; levelDescr="mírně pokročilí II"; }
				if( sum>=41 && sum<=50 ){ 	level="B2"; levelDescr="středně pokročilí I"; }
				if( sum>=51 && sum<=61 ){ 	level="B2"; levelDescr="středně pokročílí II"; }
				if( sum>=62 && sum<=70 ){ 	level="C1"; levelDescr="pokročilí I"; }
				if( sum>=71 && sum<=81 ){ 	level="C1"; levelDescr="pokročilí II"; }
				if( sum>=82 && sum<=85 ){ 	level="C2"; levelDescr="velmi pokročilí I"; }
				if( sum>=86 && sum<=89 ){ 	level="C2"; levelDescr="velmi pokročilí II"; }
				*/
				
				if( sum>=0 && sum<= 9 ){      level="A1"; levelDescr="úplný začátečník"; }         
				if( sum>=10 && sum<=19 ){     level="A2"; levelDescr="začátečník I "; }                         
				if( sum>=20 && sum<= 29 ){    level="A2"; levelDescr="začátečník II";  }                        
				if( sum>=30 && sum<= 39 ){    level="B1"; levelDescr="mírně pokročilý I"; }                    
				if( sum>=40 && sum<= 49 ){    level="B1"; levelDescr="mírně pokročilý II"; }                  
				if( sum>=50 && sum<=59 ){    level="B2"; levelDescr="středně pokročilý I"; }                 
				if( sum>=60 && sum<=69 ){    level="B2"; levelDescr="středně pokročilý II"; }                
				if( sum>=70 && sum<=79) {   level="C1"; levelDescr="velmi pokročilý I "; }                    
				if( sum>=80 && sum<= 89 ){   level="C1"; levelDescr="velmi pokročilý II"; }				
				
			}			
			
			// vypsani vysledku
			$("#testFormScore").val(sum);
			$("#testFormCast1").val(part1Score);
			$("#testFormCast2").val(part2Score);
			$("#testFormCast3").val(part3Score);			
			$("#testFormCast4").val(part4Score);			
			$("#testFormCast5").val(part5Score);			
			$("#testFormLevel").val(level);			
			$("#testFormLevelDescription").val(levelDescr);			
			
			var alertText = "";
			if( testFormLang == "en" ){
				alertText = "Cast1:" + part1Score + "\n" + "Cast2: " + part2Score + "\n" + "Cast3: " + part3Score + "\n" + "Cast4: " + part4Score + "\n" + "Cast5: " + part5Score + "\n" + "Zapocteno bodu: " + sum;
			}
			if( testFormLang == "de" ){
				alertText = "Cast1:" + part1Score + "\n" + "Cast2: " + part2Score + "\n" + "Cast3: " + part3Score + "\n" + "Cast4: " + part4Score + "\n" + "Zapocteno bodu: " + sum;
			}
			//alert( alertText );
			//return false;			
			
		});

		// ----------------------------
		/* vytovreni noveho inputu pro files  */
		$("#newFileAdd").click(function(){
		
			var fileContainerCount = $(".fileInput").length;
			var fileContainerName = "formFile_" + fileContainerCount;
			var fileContainer = $('<p class="fileInput"><input type="file" id="formFile" title="soubor" /></p>');
			fileContainer.find("input").attr("name", fileContainerName);
			$("#fileInputContainer").append( fileContainer );
			return false;
			
		});		

		// ----------------------------
		/* MAPA  */
		if($("#regionMap #mapa").length != 0)
		{
			var kraj = '';
			var vychoziMapa = $("#regionMap #mapa").attr("src");
			var mapPrefix = $("#regionMap #mapa").attr("src").replace('.gif','');
			var aktualniMapa = vychoziMapa;
	
			$('#regionMap area').mouseover(function(e){
				$('#mapa').attr('src', mapPrefix + '_' + $(this).attr('id') + '.gif');
			});
			$('#regionMap area').mouseout(function(e){
				$('#mapa').attr('src', aktualniMapa);
			});	
			
			$("#regionMap area").click(
				function(e){
					aktualniMapa = mapPrefix + '_' + $(this).attr('id') + '.gif';
					kraj = $(this).attr("title");
	
					$("#cities, #cities div").hide();
					$("#cities ."+kraj).show();
	
					if($("#cities ."+kraj).length > 0)
					{
						$("#cities").show();
						$("#cities").css("left", e.pageX - $("#regionMap").offset().left);
						$("#cities").css("top", e.pageY - $("#regionMap").offset().top);
					}
	
					return false;
				}
			);
		}
		
		// --------------------------------
		/* posunovaci menu */

		// --- slider ---
		var sliderCount = $(".menuSlider .item").length;
		var sliderWidth = $(".menuSlider .list").width();
		var handleWidth = $(".menuSlider .item").width();
		$(".menuSlider .handle").width(handleWidth);
		
		if(sliderCount == 0)
			sliderCount = 3;
		
		var wrapperWidth = sliderCount*314;		

		$(".specMenu-env .wrapper").css("width", wrapperWidth+1);				
		var ratio = (wrapperWidth-940) / (sliderWidth-handleWidth);
		
		$('.menuSlider').slider({			
			min:0,
			max: sliderWidth,
			handle: '.handle',

			stop: function(event, ui){
				canHover = true;
			},
			slide: function(event, ui){
				canHover = false;

				var tmp = ui.value - $(".menuSlider .handle").width()/2;
				if (tmp < 0) tmp = 0;
				if (tmp > sliderWidth -  $(".menuSlider .handle").width()) tmp = sliderWidth - $(".menuSlider .handle").width();
				
				$(".menuSlider .handle").css("left", tmp);
				$(".specMenu .wrapper").css("left", -1*tmp*ratio);
			}
		});
		
		$(".menuSlider .item").mouseup(function(e){
			var w1 = $(".menuSlider .handle").width();
			var w2 = $(this).width();
			
			var position = $(this).position().left-Math.abs(w1 - w2)/2;
			
			if(position < 0) position = 0;
			if(position > sliderWidth - w1) position = sliderWidth-w1;

			$('.menuSlider').slider( "value" , -position*ratio );
			
			$('.menuSlider .handle').animate({left: position}, 200);
			$('.specMenu .wrapper').animate({left: -1*position*ratio}, 200);
				
			//$("#menuSlider .handle").css("left", position );
			//$("#specMenu .wrapper").css("left", -1*position);
			//e.stopPropagation();
			
			$(".menuSlider .item").removeClass("active");
			$(this).addClass("active");

		});	

		$(".specMenu-env .btn-prev").click(function(){

			var pozice = Math.round($(".menuSlider .handle").position().left/handleWidth);
			if(pozice > 0)
			{
				$('.menuSlider .handle').animate({left: pozice*handleWidth - handleWidth}, 200);
				$('.specMenu .wrapper').animate({left: -1*(pozice*handleWidth - handleWidth)*ratio}, 200);
			}

			return false;
		}); 
		$(".specMenu-env .btn-next").click(function(){
			var pozice = Math.round($(".menuSlider .handle").position().left/handleWidth);

			if(pozice < sliderCount-1)
			{
				$('.menuSlider .handle').animate({left: pozice*handleWidth + handleWidth}, 200);
				$('.specMenu .wrapper').animate({left: -1*(pozice*handleWidth + handleWidth)*ratio}, 200);
			}

			return false;
		}); 

		
		//----------------------------
		// CAROUSEL 
		$("#reference .carousel").jcarousel({wrap:"circular",auto:2});
		$("#article .carousel").jcarousel();
		$("#category .carousel").jcarousel();
		$("#tabs .carousel").jcarousel();		

	});
	
	// READY
	$(document).ready(function() {
	
		
		$( "#dialog-message" ).dialog({
			modal: true,
			autoOpen: false,
			minWidth:350,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
				
			}
		});

	// vyber zeme na uvodni strance
	$('#countries select').change(function(){
		var lang = $(this).val();
		document.location.href = lang;
	});
		

	
		//----------------------------------
		// grayscale
		/*		
		$('#footer-env .list img').hover(
			function(){
				grayscale.reset( $(this) );
			},
			function(){
				grayscale( $(this) );
			}
		);
		*/
		
		// menu se bude za pulkou stranky otvirat na druhou stranu
		$("#menu .root").each(function(){
			if($(this).position().left > 450)
			{
				$(this).addClass('invert');
			}
		});
		
		// ---------------------------
		// aktivni prvky v rootove urovni menu		
		$("#menu li.root").hover(
			function(){
				$("li.root").removeClass("active");
				$(this).find("a:first").addClass("active");
				$(".specMenu-env").css("visibility","hidden");
			},
			function(){
				$(this).find("a:first").removeClass("active");
			}
		);
		// ---------------------------
		// rozbaleni druhe urovne
		$("#menu li").hover(
			function(){				
				$(this).find(".submenu:first").show();								
			},
			function(){
				$(this).find(".submenu:first").hide();
			}
		);		
		
		// --------------------------
		// produktove menu
		// show()
		$("#menu .services").hover(
			function() {
				$(this).addClass('active');
				var id = $(this).attr('id');

				$("#specMen"+id).css("visibility","visible");
			},
			null
		);
			

		$(".specMenu-env").hover(
			null, 		 
			function() {
				if( canHover ){
					$('#menu .services').removeClass('active');
					$(".specMenu-env").css("visibility","hidden");					
				}
			}
		);	
		
		$("#header").hover(
			function() {
				$('#menu .services').removeClass('active');
				$(".specMenu-env").css("visibility","hidden");
			}
		);
		
		$("#bottomBar #relArt").hover(
			function(){
				$(this).css("height","auto");
			},
			function(){
				$(this).css("height","88px");
			}
		);
	
		//-------------------------
		// BREADCRUMBS menu
		$('#breadcrumbs > li').hover(
			function()
			{
				$(this).find('ul').show();
			},
			function()
			{
				$(this).find('ul').hide();
			}
		);
		

		// ----------------------------
		// FANCYBOX
		$(".nyro, .nyroModal").fancybox({type:'image', centerOnScroll:true,titlePosition:"inside"});
		$(".hashBtn").fancybox({ autoScale:false, width:620 });
		
		$("#galleryDetail .image").click(function() {
			
			var $this = $(this);
			var thisIndex = $this.data("position");
			var thisTitle = $this.attr("title");
			var hiddenPicIndex = "#hiddenPicId_"+ thisIndex;
						
			$(hiddenPicIndex).trigger("click");
			return false;			
		});
		
		var playerVideo = "";
		$(".videoplayerStart").click(function(){
			playerVideo = $(this).attr("href");
			return false;
		});		
		$(".videoplayerStart").fancybox({
			'scrolling'		: 'no',
			'titleShow'		: false,
			'onStart'		: function() { $(playerVideo).show(); },
			'onClosed'		: function() { $(playerVideo).hide(); }
		});		
		
		//-----------------------------
		// FORM VALIDATOR
		//$("form").ndFormValidator();

		// --------------------------
		/// zobrazeni seo textiku 
		$("#slideControl").toggle(
			function(){
				$("#advInfo-env").slideDown();
				$(this).addClass('slide');
			}, 
			function() {
				$("#advInfo-env").slideUp();
				$(this).removeClass('slide');
				
			});
	
		// --------------------------
		/// NAHRADA EMAILU
		$("#contact .person .mail, #contact .vizitka .mail").each(function(){
			var item1 = $(this).find('.m1').text();
			var item2 = $(this).find('.m2').text();
			var mail = item1+'@'+item2;
			var label = $(this).find('.label').text();
			
			$(this).children().remove();
			$(this).prepend(label + '<a href="mailto:'+mail+'">'+item1+'</a>');
		});
		
		$("#contact .mail").each(function(){
			if($(this).find('a').length == 0)
			{
				var item1 = $(this).find('.m1').text();
				var item2 = $(this).find('.m2').text();
				var mail = item1+'@'+item2;
				
				$(this).children().remove();
				$(this).prepend('<a href="mailto:'+mail+'">'+mail+'</a>');
			}
			
		});
		
		// --------------------------
		// NOVE OKNO
		$('a[class*=nw]').click(function() {
			// otviram do noveho okna jen v pripade, ze nema tridu .nyro
			if($(this).hasClass('nyro') == false) {
				window.open(this.href);
				return false;
			}
		});	
		
		
		// --------------------------
		// FORMULARE - default text
		$("input:text, input:password, textarea").each(function(){
			var default_value = this.value;

			$(this).focus(function(){
				if(this.value == default_value) {
					this.value = '';
				}
			});
			$(this).blur(function(){
				if(this.value == '') {
					this.value = default_value;
				} else {
					$(this).addClass('changed');
				}
			});
			$(this).keydown(function(){
				$(this).addClass('changed');
			});
		});

		
		// --------------------------
		// ARTICLE - send article
		$(".hidden").hide();
		$("#artBtns .btn-sendlink").fancybox({titleShow :false});
		$("#btnCloseForm").click(function(){
			$.fancybox.close();
			return false;
		});
		
		// --------------------------
		// LANGS
		$("#langs-env ul").hover(
			function(){
				$(this).parent().css('overflow','visible');
			},
			function(){
				$(this).parent().css('overflow','hidden');
	
		});
		// na prvni polozku neklikame
		$("#langs-env li:first").click(function(){
			return false;
		})
		
		// --------------------------
		// TABs
		$("#tabs .expandable:not(:first)").parent().addClass("closed");
		$("#tabs .expandable:first").parent().addClass("opened");
		
		$("#tabs .item .title a").click(
			function(){
				var parent = $(this).parents(".item:first");
				var ex = $(parent).find(".expandable");
				
				if($(parent).hasClass("opened"))
				{
					$(ex).slideUp("fast", function(){
						$(parent).removeClass("opened");
						$(parent).addClass("closed");
					});
					
				} else {
					$(ex).slideDown("fast", function(){
						$(parent).removeClass("closed");
						$(parent).addClass("opened");
					});
					
				}
	
				return false;
			}
		);
		// --------------------------
		// dotaznik pro prekladatele
		$("a.open").click(function(){
			$(this).parent().toggleClass("skryvany");
			return false;
		});
		// --------------------------
		// FacebookBox, TwitterBox
		$("#fbLikeBox, #twitterBox").hover(
			function(){
				$(this).find(".panel").show();
			},
			function(){
				$(this).find(".panel").hide();
			}
		);
		// ----------------------------
		// Partnerska sekce
		$(".contentBox .item").hover(
			function(){
				$(".contentBox .item").removeClass("activeItem");
				$(this).addClass("activeItem");
			},
			function(){
				$(this).removeClass("activeItem");
			}
		);
		
		// --------------------------
		// panely na kliknuti
		$("#contactMenu .panelLink").click(
			function(){
				var $actItem = $(this).closest(".item");
				var actPanel = $(this).parent().find(".panel");
				
				$actItem.css("position","relative");
				
				//skryj vsechny panely, krome aktualniho
				$("#contactMenu .panel").not(actPanel).removeClass("opened");
				actPanel.toggleClass("opened");
				$(this).parent().find("input:text:first").focus();

				return false;
			});
		$("#contactMenu .panel .btn-close").click(function(){
			$(this).parents('.panel:first').removeClass("opened");
			return false;
		});
		
		$("#serviceOpenDialog").click(function(){
			
			$("#contactMenu .panel").removeClass("opened");			
			$("#cm3 .panel").toggleClass("opened").show();
			
			return false;
		});
	
		// --------------------------	
		/// LOGIN
		$("#login .link").click(
			function(){
				$(this).parent().find(".panel").toggleClass("opened");
				$(this).parent().find("input:first").focus();
				return false;
			});
		$("#login .panel .btn-close").click(function(){
			$(this).parents('.panel:first').removeClass("opened");
			return false;
		});
		
		// --------------------------	
		/// DUPLICABLE
		$("#dotaznik .duplicable").parents(".tbl-env").find(".tblFooter").append("<a href='#' class='btn-add'> </a>");
		$("a.btn-add").click(function(){
			var parent = $(this).parents(".tbl-env:first");
			var first = parent.find(".duplicable:first");
			var last = parent.find(".duplicable:last");
			
			// id
			var newOne = $(first).clone();
			newOne.find("*[id]").each(function(){
				var a = $(this).attr("id");
				$(this).attr("id",a+"_"+ (parent.find(".duplicable").length));
			});
			// name
			newOne.find("*[name]").each(function(){
				var a = $(this).attr("name");
				$(this).attr("name",a+"_"+ (parent.find(".duplicable").length));
			});

			$(newOne).insertAfter($(last));
			parent.find("tr:even").addClass("odd");
			return false;
		})

		// -------------------------
		// FORM REPLACEMENT
			formReplacement();

	
		//$("input.tel").mask("+999-999-999-999");
		//$("#pay_var").mask("999999999");
		

		// INIT hodin
		//init();


		// --------------------------------
		// INQUIRY
		$('#inquiry a').click(function(){
		
			var idAnketa = $(this).attr('class').substring($(this).attr('class').indexOf('|')+1);
			
			var COOKIE_NAME = window.location.hostname+"_anketa_"+idAnketa;
			var options = { path: '/', expires: 10 };
			
			if($.cookie(COOKIE_NAME))
			{
				alert("Sorry, you have already voted in this poll!");
			} else {
				$.cookie(COOKIE_NAME, 'mcInquiry', options); 
				
				$.post(window.location, {InternalEventState:"PollClick",InternalEventValue:$(this).attr('class')});
				alert("Thank you for your vote!");
				location.reload(true);
			}
			
			return false;
		}); 
		
		// ACOORDION -------------------------------
		
		//$("div.acc_body").each(function(){$(this).hide()});
		$("div.acc_body").hide();		
		$("div.acc_title").click(
			function(){
				var tmp = $(this).next();

				if(tmp.css("display") == "none"){ tmp.slideDown("slow"); }
				else { tmp.slideUp("slow"); }
				
			}
		);
				
		// METODICKA PORADNA, presmerovani --------------------
		$("#faqCat").change(function(){
			window.location = $(this).val();
		});		

		$("#dialogTheme").change(function(){
			var thisHref = $(this).val();			
			var parent = $(this).closest("form");
			
			parent.attr("action", thisHref);
		});

		// Twitter --------------------

		$("a.lTwitter").click(function(){
			var thisHref = $(this).attr("href"); // odkaz na stranku (pouzije se jako zdroj zkracovace)
			var thisTitle = $(this).attr("rel"); // titulek clanku postnuty na twitter
			var twitterTinyURL = "";
			var twitterMessage = thisTitle;
	
			// AJAXove zjistovani zkracene adresy
			$.ajax({ 
				type: "POST", url: "http://tinyurl.com/api-create.php", data: "url=" + thisHref, async: false,
				beforeSend: function(){},
				success: function(msg){	
					twitterTinyURL = msg;
					alert(msg);
				}
			});			
	
			// sestaveni twitter hlasky
			twitterMessage = thisTitle + " " + twitterTinyURL;						
			// sestaveni twitter URL pro pridani statusu
			window.location.href = "http://twitter.com/home?status=" + twitterMessage;
				
			return false;			
		});

	});

/// Hodiny v kontaktech
	var now;
	function init() {
		var tmp = $('#tmp').text();
		now = eval("new Date("+tmp+")");

		clock();
		var i = setInterval("clock()", 1000);
	}
			
	function clock(){
		var tik = new Date(1000);
		now.setTime(now.getTime() + tik.getTime());
		$('#contact-time').text(now.toLocaleTimeString());
		//$('#contact-date').text(now.getDate() +"."+ (now.getMonth()+1) +"."+ now.getFullYear());
		
	}
	
} catch (err){ 
	
}

