var errorstr = '';

///////////////////////////////////////////////////////////////////////////////
$(document).ready(function(){
	if(window.AntiSpam_mailto) AntiSpam_mailto();
	$('input[type=text]:not(.typetext)').addClass('typetext');
	$('input[type=password]:not(.typetext)').addClass('typetext');
	$('input[type=checkbox]:not(.typecheckbox)').addClass('typecheckbox');
	$('input[type=radio]:not(.typeradio)').addClass('typeradio');
	$('input[type=file]:not(.typefile)').addClass('typefile');
	$('input[type=submit]:not(.typesubmit)').addClass('typesubmit');
	$('input[type=reset]:not(.typesubmit)').addClass('typesubmit');
	if($().TextAreaResizer) $('textarea.resizable:not(.processed)').TextAreaResizer();
	if(window.initOverLabels) setTimeout(initOverLabels, 50);
	if(window.cssAlphaFixIE) cssAlphaFixIE();

	$('FIELDSET.collapsible').each(function(){
		var fieldset = $(this);
		if($(fieldset).is('.collapsed')) $(".fieldset-wrapper", $(fieldset)).hide();
		$("LEGEND > A", $(this)).click(function(){
			if($(fieldset).is('.collapsed')){
				var content = $(".fieldset-wrapper", $(fieldset));
				$(fieldset).removeClass('collapsed');
				content.hide();
				content.slideDown({duration: 'fast', easing: 'linear'});
				}
			else{
				$(".fieldset-wrapper", $(fieldset)).slideUp('fast', function(){
					$(this.parentNode).addClass('collapsed');
					});
				}
			});
		});

	if($().fancybox) $('a.fancybox').fancybox({
		'centerOnScroll': true,
		'hideOnContentClick': true,
		'overlayColor':'#000',
		'overlayOpacity':0.6,
		'speedIn': 300,
		'speedOut': 200,
		'titlePosition':'over',
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'onComplete':function(currentArray, currentIndex, currentOpts){
			pager = $('<div id="fancybox-pageinfo">'+(currentIndex+1) + ' / ' + currentArray.length+'</div>').appendTo($("#fancybox-inner"));
			}
		});

	if(window.customOnLoad_doc) customOnLoad_doc();
	if(window.errorstr) setTimeout('alert(errorstr);', 100);
	});

///////////////////////////////////////////////////////////////////////////////
function AntiSpam_mailto(){
	$("span[class='email']").each(function(){
		var mailtoVal = $(this).html().replace(' kukac ', '@').replace(' pont ', '.');
		var titleVal = $(this).attr('title').replace(' kukac ', '@').replace(' pont ', '.');
		if(!titleVal) titleVal = mailtoVal;
		var s = mailtoVal.match(/subject=([^&]*)/);
		if(s) mailtoVal = mailtoVal.replace(/(subject=)([^&]*)/, '$1'+escape(s[1]));
		$(this).replaceWith('<a href="mailto:'+mailtoVal+'" class="email">'+titleVal+'</a>')
		});
	}

///////////////////////////////////////////////////////////////////////////////
function cssAlphaFixIE(){
	if(navigator.userAgent.indexOf('MSIE')<0 || navigator.userAgent.indexOf('Windows')<0) return;
	var i, j, pos, cssDir, style, filename, sizingMethod;
	for(i=0; i<document.styleSheets.length; i++){
		pos = document.styleSheets[i].href.lastIndexOf('/');
		cssDir = (pos!=-1) ?document.styleSheets[i].href.substring(0, pos+1) :'';
		for(j=0; j<document.styleSheets[i].rules.length; j++){
			style = document.styleSheets[i].rules[j].style;
			if(!style.backgroundImage || style.backgroundImage=='' || style.backgroundImage.toLowerCase()=='none') continue;
			if(style.backgroundImage.toLowerCase().indexOf('.alpha.png')!=-1){
				filename = style.backgroundImage.substring(4, style.backgroundImage.length-1);
				if(filename.indexOf('http://')!=0 && filename.indexOf('/')!=0) filename = cssDir + filename;
				if(filename.indexOf('http://')!=0) continue;
				sizingMethod = (style.backgroundRepeat=='repeat' || style.backgroundRepeat=='repeat-x' || style.backgroundRepeat=='repeat-y') ?'scale' :'crop';
				style.background = 'transparent';
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + filename + "', sizingMethod='"+sizingMethod+"');";
				}
			}
		}
	}

