var csdict = {"your_email":"váš@email","search":"prohledat DOKweb","idf_address":"Školská 12,Praha 1","idf_address_long":"<strong>Institut Dokumentárního Filmu</strong><br /><br />Školská 12<br />110 00 Praha 1<br /><br />Telefon: +420 224 214 858<br />Fax: +420 224 214 858<br />Email: idf@dokweb.net,<br />Web: www.dokweb.net<br /><br />IČO: 26 54 98 67<br />DIČ: CZ26 54 98 67<br /><br /><br />","fulltext":"fulltext","fill_valid_email":"Prosí, vložte validní e-mail","fill_valid_url":"Prosím vložte validní url (http:\/\/www.adresa.cz)","same_as":"Stejné jako"};

var _gaq = _gaq || [];

$(document).ready(function() {

    function initPage(){
	    $.doTimeout(5000, function(){
			// do something in 1 second
			$('#ticker li:first').fadeOut("slow",function(){
				$(this).remove();
				$('#ticker ul').cycle({
				    fx:    'fade',
				    speed:  200,
					timeout:  2000
				 });
			});
		});

		$(".tabs a:last").addClass("last");

		$("#idfmainMenu1").prepend("<strong>Development</strong>");
		$("#idfmainMenu2").prepend("<strong>Production</strong>");
		$("#idfmainMenu3").prepend("<strong>Postproduction</strong>");
		$("#idfmainMenu4").prepend("<strong>Distribution</strong>");

		/*nadpisy - podtrzeni*/
	    $(".articleDetail h1,#producerscalendardetail .article h2,.listItem h3 a, .person h3 a").wrapInner("<span class='underline'>");

		$(".home #idf-sub, .home #dokweb-sub,.dok #idf-sub,.idf #dokweb-sub,.dbItem .contacts").hide();

		var years;
		if ($(".filters").size() > 0) {
			years = 0;
            if ($("#years").size()) { years = 80; }
			w = (Math.round($("#aside").width() - years) / $(".filters").not("#years").size());
			$(".filters").not("#years").each(function(i){
				id=i;
	            if ($("#years").size()) id=i+1;
				$(this).wrapInner("<div class='filtersInner' />").width(w+6).css("left",w*i-6+years).attr("id","filter"+(id+1));
			});
		}

		// organize filters
		$('#ctype,#cstyle').appendTo($("#filter2 .filtersInner"));
		$('#country').prependTo($("#filter2 .filtersInner"));
		$('#calRegistration,#dbRegistration').appendTo($("#filter2 .filtersInner"));
	    $(".idf #country").prependTo($("#filter3 .filtersInner"));
		$('#docRegistration').appendTo($("#filter1 .filtersInner"));

		$(".filters a[href='http://www.eastsilver.net/stream/']").parent("li").addClass("menuDatabases");

	    $(".filters a:contains('Kontakt')").parent("li").each(function(){
		    $(this).addClass("menuDatabases");
		    $(this).appendTo($(this).parents("ul"));
	    });
	    $(".filters a:contains('Contact')").parent("li").each(function(){
		    $(this).addClass("menuDatabases");
		    $(this).appendTo($(this).parents("ul"));
	    });

		$('.menuDatabases:first').addClass("firstmenuDatabases");
	    $('#entryfee .firstmenuDatabases').removeClass("firstmenuDatabases").removeClass("menuDatabases");
	    $('#entryfee .menuDatabases:first').addClass("firstmenuDatabases");

		// restyle filters
		$(".filters select").selectBox({menuTransition:"slide",menuSpeed:"fast"});

		$('.cs input#search_searchterm').attr("title",csdict['search']);
		$('.cs input#newsletterform_email').attr("title",csdict['your_email']);
		$('input#fulltext,input#pfulltex,input#dfulltext,input#vfulltext').attr("title",csdict['fulltext']);
		$("input#search_searchterm,input#newsletterform_email,input#fulltext,input#pfulltex,input#dfulltext,input#vfulltext").labelify({ labelledClass: "labelHighlight" });
		$("#director,#producer,#cut,#camera,#coproducer").labelify({ labelledClass: "labelHighlight" });

		$(".articleDetail .tab").hide();
		$(".articleDetail .tab:first").show();
		$(".articleDetail .tabs a:first").addClass("active");
		$(".team .text, .team .itemContact").hide();
		$(".videoLink,.videoPlaceholder").append("<span></span>");

		if ($('div#contactMap').length) {
			if(GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById('contactMap'));
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				geocoder = new GClientGeocoder();
				if (geocoder) {
					geocoder.getLatLng(
						csdict['idf_address'],
						function(point) {
							if (point) {
								map.setCenter(point, 15);
								var marker = new GMarker(point);
								map.addOverlay(marker);
								marker.openInfoWindowHtml(csdict['idf_address_long']);
							}
						}
					);
				}
			}
		}
		stretch();
	};

/*
	$("#header a,#bar a,#aside a").live("click",function(){
		url = $(this).attr("href") + " #content";
		$('#ajax').load(url,function(){
			initPage();
		});
		return false;
	});
*/

	$("#idftext .about li p").hide();
	$("#idftext .about li h2").live("click",function(){
		$(this).parent("li").toggleClass("visible").children().toggle();
		$(this).show();
		stretch();
		return false;
	});


	$("a[href=#contactBubble],a[href=#aboutBubble],a[href=#advertBubble]").live("click",function(){
		$(".bubble").hide();
		id = $(this).attr("href");
		$(id).fadeIn("fast");
		return false;
	});

	$(".closeBubble").live("click",function(){
		$(this).closest(".bubble").fadeOut("fast");
		return false;
	});

	$(".cs .team .fullcard").live("click",function(){
		if ($(this).hasClass("on")) {
			$(this).text("Celý profil");
		} else {
			$(this).text("Skrýt detail");
		}
		$(this).toggleClass("on");
		$(this).next(".text").toggle();
		$(this).nextAll(".itemContact").toggle();
		stretch();
		return false;
	});

	$(".en .team .fullcard").live("click",function(){
		if ($(this).hasClass("on")) {
			$(this).text("View full card");
		} else {
			$(this).text("Close card");
		}
		$(this).toggleClass("on");
		$(this).next(".text").toggle();
		$(this).nextAll(".itemContact").toggle();
		stretch();
		return false;
	});

	$(".articleDetail .tabs a").live("click",function(){
		$(".articleDetail .tab").hide();
		$(".articleDetail .tabs a").removeClass("active");
		id = $(this).attr("href");
		$(this).addClass("active");
		$(id).fadeIn("normal",function(){
			stretch();
		});
		return false;
	});

	$("#idf-sub .select span").live("click",function(){
		$(this).nextAll("ul").slideToggle("fast");
	});

	// toggle fullscreen video on background
	$("a.fullscreen, .videoLink, .videoPlaceholder").live("click",function(){

		$.cookie('lastMovie',"", {path: '/' });

		if ($(this).hasClass("videoLink")) {
			vid = $(this).attr("href");
			img = $(this).children("img").attr("src").replace("top","big");

			title = $(this).attr("title");
			link = location.href;

			$.cookie('lastMovie',link, {path: '/' });

			$("#movietitle strong").text(title);
			$("#movietitle a").attr("href",link)

			player = jwplayer("movie");
			player.load({ file: vid, image: img });
		}

		if ($(this).hasClass("videoPlaceholder")) {
			vid = $(this).children("a").attr("href");
			img = $(this).css("background-image").replace("ins","big");
			img = img.replace('url("','');
			img = img.replace('")','');

			title = $(this).prev("h3").children("a").children("span").text();
			link = $(this).prev("h3").children("a").attr("href");

			$.cookie('lastMovie',link, {path: '/' });

			$("#movietitle strong").text(title);
			$("#movietitle a").attr("href",link)

			player = jwplayer("movie");
			player.load({ file: vid, image: img });
		}

		if ($("#header").hasClass("isfullscreen")) {
			$("#movieholder").die();
			$.doTimeout("hideheaderloop"); //cancel loop timeout
		} else {
			player = jwplayer("movie");
			if (player.getState() != "PLAYING") {
				player.play();
			}

			$.doTimeout("hideheaderloop",3000, function(){
		        $("#movietimeline").hide();
				$("#header-in").slideUp();
			});

	        $("#movieholder").live("mousemove",function(){
		        $.doTimeout("hideheaderloop"); //cancel loop timeout
				$("#movietimeline").show();
	            $("#header-in").stop(true,true).slideDown(300,function(){
		            $.doTimeout("hideheaderloop",3000, function(){
                        $("#movietimeline").hide();
                        $("#header-in").slideUp();
                    });
	            });
			});

			/*
				$("#header").live("mouseout",function(){
				    $.doTimeout("hideheaderloop",3000, function(){
				        $("#movietimeline").hide();
						$("#header-in").stop(true,true).slideUp();
				  });
				});
			*/
		}


		if ($("#header").hasClass("isfullscreen")) {
			h = $(window).height() - $("#header").height() - $("#footer").height() - 3;
			$("#ajax").animate({height:h},500);
		} else {
			$("#ajax").animate({height:'0'},500);
		}


		$("#footer").toggle();
		$("#header").toggleClass("isfullscreen");

		return false;
	});

	// show detail on plus icon click
	$(".dbItem .more").live("click",function(){
		$(this).closest(".dbItem").children(".contacts").slideToggle("fast");
	});

	// hoverable geomap
	$("#geomap area").live("mouseover",function(){
		id = $(this).attr("id");
		$("#geoimg img").attr("class",id);
	});

	// blocks on mouse over
	$(".newsItem").live("mouseover",function(){$(this).children(".text").addClass("hover");});
	$(".newsItem").live("mouseout",function(){$(this).children(".text").removeClass("hover");});
	$(".newsItem").live("click",function(){link = $(this).children("a").attr("href");location.href = link;});
	$(".listItem").live("mouseover",function(){$(this).addClass("listItemHover");});
	$(".listItem").live("mouseout",function(){$(this).removeClass("listItemHover");});
	$(".hpEvent").live("mouseover",function(){$(this).addClass("hpEventHover");});
	$(".hpEvent").live("mouseout",function(){$(this).removeClass("hpEventHover");});
	$(".person").live("mouseover",function(){$(this).addClass("personHover");});
	$(".person").live("mouseout",function(){$(this).removeClass("personHover");});

	// show/hide idf and dokweb submenu
	$('.dok #idf,.home #idf').live('mouseover', function() {
		if (!$(this).data('init')) {
			$(this).data('init', true);
			$(this).hoverIntent({
				over:function(){
					$("#dokweb-sub").hide();
					$("#idf-sub").show();
				},
				out:function() {
					$("#idf-sub").hide()
					$(".dok #dokweb-sub").show()
				},
				interval:10
			});
			$(this).trigger('mouseover');
		}
	});

	$('.idf #dokweb,.home #dokweb').live('mouseover', function() {
		if (!$(this).data('init')) {
			$(this).data('init', true);
			$(this).hoverIntent({
				over:function(){
					$("#idf-sub").hide();
					$("#dokweb-sub").show();
				},
				out:function() {
					$("#dokweb-sub").hide()
					$(".idf #idf-sub").show()
				},
				interval:10
			});
			$(this).trigger('mouseover');
		}
	});

    // submit forms on selectbox change
	$("select.authors").live("change",function(){
		location.href = ($(this).val());
	});

	$(".filtersInfo .submitButton").live("click",function(){
		id = $(this).attr("href");
		$(id).submit();
		return false;
	});

	$('a.print').live("click",function(event){
		event.preventDefault();
		window.print();
	});

	$("a[href=#cse-search-box]").live("click",function(){
		$("#cse-search-box").toggle();
		return false;
	});

	if ($("#idfcalendarlist").size()) {
		$("html,body").css("height","auto");
		$("html,body").css("overflow","auto");
	}

// stretching main content
	function stretch() {
		$("#ajax").css("height","auto");
		var h = $(window).height() - $("#header").height() - $("#bar").height() - $("#footer").height() - 3*3;

		if ($("#home").size()) {
			$("#home").height(h).jScrollPane({verticalDragMinHeight: 200,verticalDragMaxHeight: 200});
		} else {
			$("#tags").height(h);
			dokbar = $("#dokweb-sub-inner").height() + 7;
			idfbar =  $("#idf-sub-inner").height() + 7;

			$(".dok #aside").css("top",dokbar);
			$(".idf #aside").css("top",idfbar);

			$(".dok #aside").height(h-dokbar)
			$(".idf #aside").height(h-idfbar)

			$(".dok .filters").height(h-dokbar).jScrollPane({verticalDragMinHeight: 200,verticalDragMaxHeight: 200});
			$(".idf .filters").height(h-idfbar).jScrollPane({verticalDragMinHeight: 200,verticalDragMaxHeight: 200});

			var h2 = h + $("#bar").height() + 3;
			$("#section").height(h2).jScrollPane({verticalDragMinHeight: 200,verticalDragMaxHeight: 200});
		}
		$("html").addClass("jsok");

		$('#section img').bind("load",function() {
			$("#section").height(h2).jScrollPane({verticalDragMinHeight: 200,verticalDragMaxHeight: 200});
		});
	}

// main jwplayer
	videoAbs = $("#vidAbs").text();
	videoImg = $("#vidImg").text();

	player = jwplayer("movie");
	player.setup({
		volume:0,
		autostart: false,
		controlbar: "none",
        file: videoAbs,
        height: "100%",
        stretching: "fill",
        width: "100%",
		wmode:"transparent",
		image:videoImg,
 		modes: [
			{ type: "html5" },
			{ type: "flash", src: baseUrl + "jwplayer/player.swf" }
		]
    });


	$("#movieplay").click(function(){
		player.play();
		return false;
	})
	$("#moviestop").click(function(){
		player.stop();
		return false;
	})
	$("#moviepause").click(function(){
		player.pause();
		return false;
	})

	var timelinewidth =$("#movietimeline").width() - $("#moviescrobbler").width();

	player.onTime(function() {
		var total = player.getDuration();
		var pos = player.getPosition();
		$("#movietotal").text(formatTime(total));
		$("#moviepos").text(formatTime(pos));
		var x = Math.round(pos / total * timelinewidth);
		$("#moviescrobbler").css("left",x);
	});

	player.onComplete(function() {
		$.doTimeout("hideheaderloop"); //cancel loop timeout
		$("#movietimeline").show();
        $("#header-in").show();
		$("#header").removeClass("isfullscreen");
		$("#footer").show();

		$("#ajax").css("height",0);
		h = $(window).height() - $("#header").height() - $("#footer").height() - 3;
		$("#ajax").animate({height:h},500);

		stretch();
		/*
		link = $.cookie('lastMovie');
		if (link != "") {
			location.href = link;
		}
		*/
	});

	$( "#moviescrobbler" ).draggable({
		containment: "#movietimeline",
		start: function(event,ui) {player.stop();},
		stop:function(event,ui) {
			seek = Math.floor(ui.position.left / timelinewidth * player.getDuration());
			player.seek(seek);
		}
	});

	if ($("#index").size()) {
		if ($.cookie('playOnEnter') != 1) {
			player.play();
			$.cookie('playOnEnter',1, {path: '/' });
		}
	}

	var volumewidth = $("#movievolume").width();
	var volumeheight = $("#movievolume").height() - $("#movievolumeslider").height();

	player.onReady(function(){
		x = player.getVolume()/100*volumewidth;
		y = Math.round(x / volumewidth * volumeheight);
		$("#movievolumeslider").css("left",x).css("bottom",y);
	});

	$("#movieholder").live("click",function(){
		player.setVolume(80);
		x = player.getVolume()/100*volumewidth;
		y = Math.round(x / volumewidth * volumeheight);
		$("#movievolumeslider").css("left",x).css("bottom",y);
		player.play();
		return false;
	});

	$("#movievolumeslider").draggable({
		axis:"x",
		containment: "#movievolume",
		start: function(event,ui) {},
		drag: function(event,ui) {
			y = Math.round(ui.position.left / volumewidth * volumeheight);
			$("#movievolumeslider").css("bottom",y);
			volume = Math.floor(ui.position.left / volumewidth * 100);
			player.setVolume(volume);
		}
	});

	$(window).unload(function() {
		jwplayer("movie").stop();
	});

	initPage();
	$(window).resize(function(){
		stretch();
	});

// industry map
	if($('div#industryMapMark').length) {
		var flashvars = {xmlinput: baseUrl+lan+'/flashxml/?type=map'};
		var params = {menu: 'false',allowscriptaccess: 'none',wmode: 'transparent'};
		var attributes = { id: 'industryMap', name: 'industryMap'};
		swfobject.embedSWF(baseUrl+'swf/map.swf', 'industryMapMark', 554, 554, "9.0.0", baseUrl+'swf/expressInstall.swf', flashvars, params, attributes);
	}

	var goLink = $('a#goLink');
	if(!goLink.length) {$('#industryMap').after('<a href="#" id="goLink">&nbsp;</a>');$('a#goLink').css('display', 'none');	goLink = $('a#goLink');}
	mapGo = function(country){
		if(country == undefined)country = '';
		parts = location.href.split('?');
		var uurl = parts[0].replace('#', '');
		document.location.href = uurl+'?country='+country;
	};


//kalendar producenta
	var calLinks = $('div.calendar div.item a');
	if(calLinks.length) {
		calLinks.unbind('mouseenter');
		calLinks.bind('mouseenter', function(){
			var cl = $(this).attr('class');
			$('a.'+cl).css('background-color', '#cacaff');
		});

		calLinks.unbind('mouseleave');
		calLinks.bind('mouseleave', function(){
			var cl = $(this).attr('class');
			$('a.'+cl).css('background-color', '#e6e6e6');
		});
	}

	if($('div.deadlineDay').length) {
		$('div.deadlineDay').each(function(){
			$(this).get(0).initalHeight = $(this).height();
			if($(this).hasClass('openItem')) {
				$(this).parents('div.item').css('background-color', '#e6e6e6');

				var h = $(this).get(0).initalHeight;
				$(this).height(h);
				$(this).parents('div.item').css('padding-bottom', h);
			} else {
				$(this).height(0);
			}
		});

		var calItems = $('div.calendar div.item');

		calItems.unbind('mouseenter');
		calItems.bind('mouseenter', function(){
				$(this).css('background-color', '#e6e6e6');
		});

		calItems.unbind('mouseleave');
		calItems.bind('mouseleave', function(){
			if($(this).find('.openItem').length == 0) {
				$(this).css('background-color', 'transparent');
			}
		});

		calItems.unbind('click');
		calItems.bind('click', function(){
			if($(this).find('div.deadlineDay').length) {

				var tdline = $(this).find('div.deadlineDay');
				if(tdline.height() == 0) {
					$('div.deadlineDay').removeClass('openItem');
					$('div.calendar div.item').css('background-color', 'transparent');

					$('div.deadlineDay').height(0);
					$('div.calendar div.item').css('padding-bottom', 0);

					tdline.addClass('openItem');
					$(this).css('background-color', '#e6e6e6');

					var h = tdline.get(0).initalHeight;
					tdline.height(h);
					$(this).css('padding-bottom', h);
				} else {
					$(this).removeClass('openItem');
					$(this).css('padding-bottom', 0);
					$(this).find('div.deadlineDay').height(0);
				}
    			}
		});

		$('div.deadlineDay').css('visibility', 'visible');
	} else {
		if(calLinks.length) {
			calLinks.bind('mouseenter', function(){
				$.showToolTip($(this).html());
			});

			calLinks.bind('mouseleave', function(){
				$.hideToolTip();
			});
		}
	}

	$("a[href$='jpg'], a[href$='png'], a[href$='gif'], a[href$='bmp']").nyroModal();
	$("a[href$='JPG'], a[href$='PNG'], a[href$='GIF'], a[href$='BMP']").nyroModal();
	$(".nyroModal").nyroModal();


	//idf kalendar
	var idfCal = $('div#idfCalendar');

	if(idfCal.length) {
		var iWid = parseInt(idfCal.find('div.month').eq(0).innerWidth()) - 16;

		$('#idfCalendar').append('<div class="rule" id="fromRule">&nbsp;</div>');
		$('#idfCalendar').append('<div class="rule" id="toRule">&nbsp;</div>');

		var fromRule = $('#fromRule');
		var toRule = $('#toRule');

		fromRule.hide();
		toRule.hide();

		idfCal.find('ul.events li').each(function(){
			var tags = $(this).find('ul.articleTags');
			var tMar = parseInt($(this).find('h4').eq(0).css('padding-left'));

			if(tags.length) {
				$(this).append(tags.clone().addClass('list'));

				var list = $(this).find('ul.articleTags.list');
				var listW = parseInt(list.width());
				var mar = tMar;

				if(mar + listW >= iWid) {
					mar = iWid - listW;
				}

				list.css('margin-left', mar+'px');
			}

			var detail = $(this).find('span.detail');

			if(detail.length) {
				var detailW = parseInt(detail.width());
				var mar = tMar;

				if(mar + detailW >= iWid) {
					mar = iWid - detailW;
				}

				detail.css('margin-left', mar+'px');
			}
		});

		idfCal.find('ul.events li').mouseenter(function(){
			if($(this).find('span.detail').css('display') == 'none') {
				$(this).find('ul.articleTags.list').css('display', 'block');
			}

			var fromDay = parseInt($(this).find('span.dayInfo.from').html());
			var toDay = parseInt($(this).find('span.dayInfo.to').html());

			var fromDayIcon = $(this).parents('div.month').find('ul.days li.'+fromDay);
			var toDayIcon = $(this).parents('div.month').find('ul.days li.'+toDay);

			fromDayIcon.addClass('highlight');
			toDayIcon.addClass('highlight');

			fPos = fromDayIcon.position();
			tPos = toDayIcon.position();
			lPos = $(this).position();

			if(fPos != undefined && tPos != undefined && lPos != undefined) {
				var h = lPos.top - fPos.top + 6;

				fromRule.css({
					'top': fPos.top + 8,
					'left': fPos.left,
					'height': h
				}).show();

				toRule.css({
					'top': tPos.top + 8,
					'left': tPos.left + 19,
					'height': h
				}).show();
			}

			$(this).find('span.title').eq(0).css({
				'background-color': '#000000',
				'color': '#ffffff'
			});
		}).mouseleave(function(){
			$(this).find('ul.articleTags.list').css('display', 'none');
			$(this).find('span.title').eq(0).css({
				'background-color': 'transparent',
				'color': '#000000'
			});

			fromRule.hide();
			toRule.hide();

			$(this).parents('div.month').find('ul.days li').removeClass('highlight');
			$(this).find('span.detail').removeClass('showed');
		}).click(function(event){
			event.preventDefault();
			$(this).find('ul.articleTags.list').css('display', 'none');

			var detail = $(this).find('span.detail');
			detail.addClass('showed');
			$('span.detail:not(.showed)').css('display', 'none');

			if(detail.css('display') == 'block') {
				detail.css('display', 'none');
				detail.removeClass('showed');
			} else {
				detail.css('display', 'block');
			}
		});

		idfCal.find('a').click(function(event){
			event.stopPropagation();
		});
	}

	//autocomplete profici
	var acFilters   = $('input.profAC');
	if(acFilters.length) {
		var gid = $('input#groupId').val();
		acFilters.each(function(){
			if($(this).val() == '')$(this).val($(this).attr('title'));
			$(this).autocomplete(baseUrl+lan+'/ajax/', {
				minChars: 3,
				extraParams: {
					varName: $(this).attr('name'),
					type: 'personAutocomplete',
					groupId: gid
				}
			});
		});

		acFilters.unbind('mouseenter');
		acFilters.mouseenter(function(event){
			event.preventDefault();
			$.showToolTip($(this).attr('title'));
		});

		acFilters.unbind('mouseleave');
		acFilters.mouseleave(function(){
			$.hideToolTip();
		});

		acFilters.unbind('focus');
		acFilters.focus(function(){
			if($(this).val() == $(this).attr('title'))$(this).val('');
		});

		acFilters.unbind('blur');
		acFilters.blur(function(){
			if($(this).val() == '')$(this).val($(this).attr('title'));
		});
	}

	/*entry forms*/
	//entryform
	var entryForm = $('div.entryForm').eq(0);

	if(entryForm.length) {
		//sablony a js validace
		entryForm.find('input.formatyear').mask('9999');
		entryForm.find('input.formatdate').mask('99.99.9999');
		entryForm.find('input.formatmonth').mask('99.9999');

		entryForm.find('input.formatphone').keyup(function(){
			var regExp = new RegExp('[^/+0-9]', 'g');
			var val = $(this).val();
			$(this).val(val.replace(regExp, ''));
		});

		entryForm.find('input.formatnumber').keyup(function(){
			var regExp = new RegExp('[^0-9]', 'g');
			var val = $(this).val();
			$(this).val(val.replace(regExp, ''));
		});

		entryForm.find('input.formatemail').blur(function(){
			var regExp = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			var val = $(this).val();
			if(val.search(regExp) == -1) {
				$(this).val('');
				alert(csdict['fill_valid_email']);
			}
		});

		entryForm.find('input.formatwww').focus(function(){
			if($(this).val() == '')$(this).val('http://');
		})

		entryForm.find('input.formatwww').blur(function(){
			var regExp = new RegExp();
			regExp.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
			var val = $(this).val();
			if(val.search(regExp) == -1) {
				$(this).val('');
				alert(csdict['fill_valid_url']);
			}
		});

		var groups = entryForm.find('div.group');
		var persons = [];
		var personId = 0;

		groups.each(function(){
			var instances = $(this).find('div.instance');
			if(
				$('div.entryForm.preview').length == 0
				&& (($(this).hasClass('multi') && instances.length > 1) || $(this).attr('id') == 'groupsubmiter')
			) {
				//schovavani uz vyplnenejch polozek
				var forms = instances.find('div.instanceForm');
				forms.hide();
				forms.eq(forms.length - 1).show();

				//same as
				for(var x = 0; x < instances.length - 1; ++x) {
					var instanceInputs = instances.eq(x).find('input[type=text]');

					persons[personId] = {
							'name': instanceInputs.eq(0).val()+' '+instanceInputs.eq(1).val(),
							'instance': instances.eq(x),
							'group': $(this).attr('id')
					}

					++personId;
				}
			}
		});

		//schovavani uz vyplnenejch polozek
		$('div.instance a.visCon').click(function(event){
			event.preventDefault();
			$(this).parents('div.instance').find('div.instanceForm').toggle();
		});

		var eles = $('div.entryForm div.required input, div.entryForm div.required textarea, div.entryForm div.required select');

		eles.each(function(){
			var val = $(this).val();
			if(val != '' && val != 0 && val != null) {
				$(this).css('background-color', '#ffffff');
				$(this).find('option').css('background-color', '#ffffff');
			}
		});

		//same as
		if(persons.length && $('div.entryForm.preview').length == 0) {
			groups.each(function(){
				if(($(this).hasClass('multi')) || $(this).attr('id') == 'groupsubmiter') {
					var instances = $(this).find('div.instance');
					var instance = instances.eq(instances.length - 1);
					var h3 = instance.find('h3');
					var content = '';
					var group = $(this);
					$.each(persons, function(key, data) {
						if(data['group'] != group.attr('id')) {
							content += '<a href="#" id="sameAs'+key+'">'+data.name+'</a>';
						}
					});

					if(content != '') {
						content = '<div class="sameAs"><h4>'+csdict['same_as']+'</h4>'+content+'</div>';

						if(h3.length) {
							h3.after(content);
							lastSameAs = h3;
						} else {
							instance.prepend(content);
							lastSameAs = instance;
						}
					}
				}
			});

			var visCon = $('a.visCon:last');

			if(visCon) {
				entryForm.scrollTop(visCon.offset().top - 250);
			}

			$('div.sameAs a').click(function(event){
				event.preventDefault();
				var id = $(this).attr('id').replace('sameAs', '');
				var formElements = $(this).parents('div.instance').eq(0).find('input, select, textarea');
				var refElements = persons[id].instance.find('input, select, textarea');

				//alert(persons[id].name);

				formElements.each(function(){
					var formElement = $(this);
					refElements.each(function(){
						feName = formElement.attr('id').split('_');
						refName = $(this).attr('id').split('_');
						if(feName[1] == refName[1]) {
							formElement.val($(this).val());
						}
					});
				});
			});
		}

		//optgroups
		var ogs = entryForm.find('select:has(optgroup)');
		if(ogs.length) {
			var blankOpt = '<option value="0">- - -</option>';

			ogs.each(function(){
				var groups = {};
				var selHtml = '<option value="0">- - -</option>';

				$(this).find('optgroup').each(function(){
					var groupLabel = $(this).attr('label');

					groups[groupLabel] = $(this).html();
					selHtml += '<option value="'+groupLabel+'">'+groupLabel+'</option>';
				});

				$(this).data('groups', groups).html(selHtml);
				$(this).data('compact', true);
			}).change(function(){
				if($(this).data('compact') == true) {
					var groups = $(this).data('groups');
					$(this).data('compact', false);
					$(this).html(blankOpt+groups[$(this).val()]);
				}
			});
		}
	}

	$("a").easyTooltip();

}); // doc ready end

function formatTime(time) {
	time = Math.round(time);

	var hours = Math.floor(time / 3600);
	time = time - (hours * 3600);
	hours = hours.toString();
	if(hours.length == 1)hours = '0'+hours;

	var minutes = Math.floor(time / 60);
	time = time - (minutes * 60);
	minutes = minutes.toString();
	if(minutes.length == 1)minutes = '0'+minutes;

	var seconds = time;
	seconds = seconds.toString();
	if(seconds.length == 1)seconds = '0'+seconds;

	return hours+':'+minutes+':'+seconds;
}


