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($().lightbox) $('a[rel*=lightbox]').lightbox({
		fileLoadingImage : 'res/jquery/lightbox/loading.gif',
		fileBottomNavCloseImage : 'res/jquery/lightbox/close.gif',
		overlayOpacity : 0.8,
		borderSize : 10,
		displayTitle: true,
		strings : {
			prevLinkTitle: 'Előző kép',
			nextLinkTitle: 'Következő kép',
			prevLinkText:  '&laquo; Előző',
			nextLinkText:  'Következő &raquo;',
			closeTitle: 'Bezár',
			image: 'Kép ',
			of: ' / '
			},
		fitToScreen: true// resize images if they are bigger than window
		});

	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;
	for(i=0; i<document.styleSheets.length; i++){
		var pos = document.styleSheets[i].href.lastIndexOf('/');
		var cssDir = (pos!=-1) ?document.styleSheets[i].href.substring(0, pos+1) :'';
		for(j=0; j<document.styleSheets[i].rules.length; j++){
			var style = document.styleSheets[i].rules[j].style;
			if(style.backgroundImage.toLowerCase().indexOf('.alpha.png')!=-1){
				var 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;
				style.background = 'transparent';
				sizingMethod = (style.backgroundRepeat=='repeat' || style.backgroundRepeat=='repeat-x' || style.backgroundRepeat=='repeat-y') ?'scale' :'crop';
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + filename + "', sizingMethod='"+sizingMethod+"');";
				}
			}
		}
	}

