﻿ 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 {
	$(function() {
		$.fn.nyroModal.settings.processHandler = function(settings) {
			var from = settings.from;
			if (!settings.type && from && from.href) {
				/*alert(
					'type should be image: '+settings.type + '\n'
					+ "need to determine if image manually");*/
				var arr = from.href.split('?');
				//if carrying extra stuff
				if(arr.length>1){
					var newArr=arr[0].split('.');
					var newType=settings.type;
					//alert('extension is: ' + newArr[newArr.length-1]);
					switch(newArr[newArr.length-1].toUpperCase()){
						case 'IMG':
						case 'JPG':
						case 'JPEG':
						case 'PNG':
						case 'GIF':
						case 'ASPX':
							newType='image';
							break;
						default:
							newType=settings.type;
					}
					//alert("new type is " + newType);
					$.nyroModalSettings({
						type: newType
					});
				}
			}
		};
		
	});
	
} catch (err){


}

$(document).ready(function(){
	// FOTOGALERIE
	$(".nyro").nyroModal();
	$("#programList .nyro, #visit .nyro").nyroModal({height:500,width:700});
	
	
	// VALIDATOR
	$("#sendArticle form").ndFormValidator();
	$("#form form").ndFormValidator();

	// NOVE OKNO
	$('a[class*=nw]').click( function() {
		window.open(this.href);
		return false;
	});	


	/* FORMULARE - pokud je vepsany text */
	var puvodni_hodnota = '';
	$("input:text").focus(function(){
		if(!$(this).hasClass('changed')) {
			puvodni_hodnota = $(this).attr("value");
			$(this).attr("value","");
		}
	});
	$("input:text").blur(function(){
		if(!$(this).hasClass('changed')) {
			$(this).attr("value",puvodni_hodnota);
		}		
	});
	$("input:text").keydown(function() {
		$(this).addClass('changed');
	});
	
	/* ZOBRAZOVANI FORMULARE PRO ODESLANI CLANKU */
	$("#btnMail").click(function(){
		$("#sendArticle").slideToggle("slow");
		return false;
	});
	$("#btnCloseForm").click(function(){
		$("#sendArticle").slideUp("slow");
		return false;
	});		
	
	/* ANKETA  */
	$('.inquiry a').click(function(){
		
		var idAnketa = $(this).attr('class').substring($(this).attr('class').indexOf('|')+1);
		//console.log(idAnketa);
		
		var COOKIE_NAME = window.location.hostname+"_anketa_"+idAnketa;
		var options = { path: '/', expires: 10 };
		
		if($.cookie(COOKIE_NAME))
		{
			alert("Váš hlas již byl započítán!");
		} else {
			$.cookie(COOKIE_NAME, 'mcInquiry', options); 
			
			$.post(".", {InternalEventState:"PollClick",InternalEventValue:$(this).attr('class')});
			alert("Děkujeme za Váš názor!");
			location.reload(true);
		}
		
		return false;
	}); 
	
	$("#favArts .innerBox, #visit .innerBox, #soutez .innerBox").each(function(){
		$(this).height($('#favArts .innerBox').height());
	});

});

