 var pngfixOff = true;
 var ajaxOff = !window.XMLHttpRequest || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i));
 var cookie_options = { path: '/', expires: 0 };
 
 $(function() {
	$.datepicker.setDefaults($.datepicker.regional['cs']);
	afterload('body');
	$(window).bind('resize', function() { $('body').css("display","none"); $('body').css("display","block"); if(!pngfixOff) DD_belatedPNG.fix('.png_bg, img, *'); });
	if(!ajaxOff) { 
		if(location.hash.replace('#','')!='') loadIt(location.hash.replace('#',''),'ajaxSlide submenu main');
	}
});

function loadIt(url,css) {
	tmpcss=css.split(" ");
	if(url!="_none") { $('#menu a').removeClass('selected'); $('#menu a[href*='+url+']').addClass('selected'); }
	i=1; while(tmpcss[i-1]!='ajaxSlide'&&i<tmpcss.length) i=i+1; 
	for(;i<tmpcss.length;i++) {
		if($('#'+tmpcss[i]+' > .content').length==1) 
			 temp='#'+tmpcss[i]+' > .content'; 
		else temp='#'+tmpcss[i];
		$(temp).html('<table class="preload"><tr><td><img src="/img/preload.gif" alt="preloader" class="preloader"/><p>... probíhá načítání ...</p></td></tr></table>').load('/null.php?trg='+tmpcss[i]+'&get='+url,{},function () { afterload('#'+$(this).parent().attr('id'));  }); 			
		}
//	if($('body').scrollTop()>270) $('html, body').scrollTop(0);
}

function oldBrowser() {
	if((navigator.appName=="Microsoft Internet Explorer") && (parseFloat(navigator.appVersion)<5)) return true;
	else return false;
}


function afterload(prefix) {
 	$(prefix+' .imgREPLACE').each(function (i) { if($(this).attr('class')!='') {
 		imgname=$(this).attr('class').split(" ")[1];
 		img=imgname.split("*");
 		if(img.length==1) {	$(this).html('<img src="img/'+img[0]+'.png" alt="'+$(this).html()+'"/>'); }
 		if(img.length==3) {	$(this).html('<img src="img/'+img[0]+'.png" style="width:'+img[1]+'px;height:'+img[2]+'px" alt="'+$(this).html()+'"/>'); }
 	}});
 	$(prefix+' a.ajaxSlide').each(function (i) { 
	 	if(!ajaxOff) {
 			$(this).attr('href','#'+$(this).attr('href').replace('#','').replace('http://www.czechmusic.org','')).click(function() { 
 					$(this).attr('onclick'); 
 					loadIt($(this).attr('href').replace('#',''),$(this).attr('class')); 
 			}); 
	 	} else {
		 	$(this).click(function() { return true;	}); 
	 	}	 	
 	});
 	$(prefix+' select.setcookie').each(function (i) { $(this).bind('change', function() {
 		 	$.cookie($(this).attr('id'),$(this).val(),cookie_options);
 		 	loadIt('_none','ajaxSlide main');
	});	});
 	if(!pngfixOff) DD_belatedPNG.fix(prefix+' .png_bg,'+prefix+' img,'+prefix+' *');
	$(prefix+' a.lightbox').lightBox({fixedNavigation:true});
    $("#tabs").tabs();
	$('input.datepicker').datepicker({showOn: 'button', buttonImage: '/img/form-kalendar.gif', buttonImageOnly: true});
}

function myalert(text) {
	if($('#alert').length==0) { $('body').append('<div id="alert">testujeme:)</div>'); }
	var $alert = $('#alert');
	$alert.html(text); 
	if(text.substr(text.length-1,1)=='!') $alert.addClass('error');
	else { var alerttimer = window.setTimeout(function () {
					$alert.trigger('click');
				}, 3000); }
	$alert.animate({height: $alert.css('line-height') || '50px'}, 200)
			.click(function () {
				window.clearTimeout(alerttimer);
				$alert.animate({height: '0'}, 200);
			});
}

