

 
 
function flash(text)
{
	$("span.flash").text(text).show().delay(5000).fadeOut(2000);
}

jQuery.extend({
	nette: {
		updateSnippet: function (id, html) {
			$("#" + id).html(html);
			
		},

		success: function (payload) {
			// redirect
			if (payload.redirect) {
				window.location.href = payload.redirect;
				return;
			}
			// snippets
			if (payload.snippets) {
				
				for (var i in payload.snippets) {
					jQuery.nette.updateSnippet(i, payload.snippets[i]);
				}

				
				for (var i = 0; i < document.forms.length; i++) Nette.initForm(document.forms[i]);
				
				
				if (typeof Rychlo != 'undefined') $("img").load(function(){
					Rychlo();
				}); 
				InitPage();
				
				
				
			}
		},
		
		// create animated spinner
		createSpinner: function()
		{
			
			return this.spinner = $('<div></div>').attr('id', 'ajax-spinner').ajaxStart(function() {
				$(this).addClass('active');
				$("html").addClass('busy');

			}).ajaxStop(function() {
				$(this).removeClass('active');
				$("html").removeClass('busy');

			}).appendTo('body');
		},
	
		spinnerType: function(type)
		{
			$("#ajax-spinner").removeClass();		
			$("#ajax-spinner").addClass(type);		
		}
	
		
	}
});

jQuery.fn.center = function () {
    //this.css("position","absolute");
    this.css("top", Math.max((($(window).height() - this.outerHeight()) / 2),  20) + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

function InitPage()
{
	$('div.dialog').draggable(
		{
			handle: "h2.handle"
		}
	).center();
	
	$('.tip').tipTip({ 
		maxWidth: 300, 
		edgeOffset: 10, 
		delay: 50
	});
	


	$("div.flash").delay(5000).slideUp();
	
	if (Modernizr.mq('only all and (min-width: 768px)')){
	
		$(".gallery").colorbox({rel:'gallery'});
		
	}
	else{
		
		$("a.gallery").live('click', function(e){
			
			var href = $(this).attr('href');
			var im = $("div.fullImage img");
			im.attr("src", href).load(function(){
				if (im.width() > im.height()){
					im.css("height", "100%");
				}
				else{
					im.css("width", "100%");
				}
			});
			
			/*
			*/
			$("div.fullImage").fadeIn();
			e.preventDefault();
			
		});
		
		$("div.fullImage").live('click', function(e){
			
			$(this).fadeOut();
			
			e.preventDefault();
			
		});
		
		setTimeout(function(){
		    window.scrollTo(0, 1);
		}, 1000);		
		
		
	}
	
	
}

$(document).ready( function() {



	// closable

	$(".closable .close").live('click', function(){
		//$(this).closest('.closable');
		$(this).closest('.closable').fadeOut(500);
		return false;
	});	
	
	// confirmator
	
	$('a[data-nette-confirm], button[data-nette-confirm], input[data-nette-confirm]').live('click', function (e) {
		 var el = $(this);
		 if (!confirm(el.attr('data-nette-confirm'))) {
			 e.preventDefault();
			 e.stopImmediatePropagation();
			 return false;
		 }

		 ulozeno = true;

	 });	

	// shower
	
	$('a[data-open]').live('click', function(event){
		
		$target = $('#' + $(this).attr('data-open'));
		$target.slideToggle();
        if ($(this).hasClass('up'))
        {
            $(this).removeClass('up');
            $(this).addClass('down');
        }
        else
        {
            $(this).removeClass('down');
            $(this).addClass('up');
        }
        
        $('body').click(function(){
        	$target.hide();
        });
        
		event.preventDefault();
	});	


	$("a.ajax").live('click', function (event) {
		event.preventDefault();
		$.getJSON(this.href, jQuery.nette.success);
		
		if (typeof _gaq != "undefined") _gaq.push(['_trackEvent', 'clicks', 'click', this.href]);
		
	});


	$("form.ajax").live('submit', function (event) {
		$(this).ajaxSubmit();
		event.preventDefault();
		if (typeof _gaq != "undefined") _gaq.push(['_trackEvent', 'forms', 'submit', this.action]);
		
	});

	$("form.ajax :submit").live('click', function (event) {
		$(this).ajaxSubmit();
		event.preventDefault();
		if (typeof _gaq != "undefined") _gaq.push(['_trackEvent', 'forms', 'submit', this.action]);
		
	});


	jQuery.nette.createSpinner();
	jQuery.nette.spinnerType('default');

	InitPage();

});



