jQuery(document).ready(function(){
  
  function createBackground() {
    var topWidth = jQuery("html").width() - jQuery("#header-bg-right").offset().left;
    var bottomWidth = jQuery("html").width() - jQuery("#footer-bg-right").offset().left;
    jQuery("#header-bg-right").css("width", topWidth + "px");
    jQuery("#header-bg-right").css("right", "-" + topWidth + "px");
    jQuery("#footer-bg-right").css("width", bottomWidth + "px");
    jQuery("#footer-bg-right").css("right", "-" + (bottomWidth) + "px");
    // jeste zlobi v IE6 a IE8 - zapocitava sirku scrollbaru ... :-/
  }

  jQuery(window).resize(function(){
    createBackground();
  })
  
  createBackground();
  
  jQuery('a.lightbox').livequery(function() {
	  jQuery(this).lightBox();
  });
  jQuery('#detailImageView').livequery('click', function() {
	  jQuery('a.lightbox').click();
  });
  
  // zajaxovani formularu (staci pridat class="ajax" a formular se odesle pres ajax)
  $(function () {
  	// odeslání na formulářích
	jQuery("form.ajax").livequery("submit", function () {
		jQuery(this).ajaxSubmit();
  		return false;
  	});
	jQuery(".ajax .paginator a").livequery("click", function () {
		jQuery.get(this.href);
	  	return false;
	});
	jQuery("a.ajax").livequery("click", function () {
		jQuery.get(this.href);
	  	return false;
	});
	jQuery(".ajax select.ajax").livequery("change", function () {
		jQuery(this.form).ajaxSubmit();
	  	return false;
	});
	// pro Nette formulare 
	jQuery("form.ajaxAppForm :submit").livequery(function () {
        this.oldonclick = this.onclick;
        this.onclick = null;
        jQuery(this).click(function() {
                if (jQuery.isFunction(this.oldonclick) && !this.oldonclick())
                        return false;
                jQuery(this).ajaxSubmit();
                return false;
        });
	}, function () {});
	
  });
  
  //ajax spinner
  jQuery(function () {
	  jQuery('<div id="ajax-spinner"><span></span></div>').hide().ajaxStart(function () {
		  jQuery(this).show();
  	}).ajaxStop(function () {
  		jQuery(this).hide();
  	}).appendTo("body");
  });
  
  jQuery('#ajax-spinner').css('opacity','0.60');
  
  jQuery("div.flash").livequery(function () {
	var el = $(this);
	setTimeout(function () {
		el.animate({"opacity": 0}, 2000);
		el.slideUp();
	}, 15000);
  });
  $("div.flash").livequery("click", function() {
	  jQuery(this).hide();
  });
  
  // katalog vstupni - efekty
  jQuery('#catalogImage1').css("opacity","0");
  jQuery('#catalogImage2').css("opacity","0");
  jQuery('#catalogImage3').css("opacity","0");
  jQuery('#catalogImage4').css("opacity","0");
  jQuery('#catalogImage5').css("opacity","0");
  jQuery('#catalogImage6').css("opacity","0");
  jQuery('#catalogImage7').css("opacity","0");
  jQuery('#catalogBlock1,#linkSeries1').hover(function() {
    jQuery('#catalogImage1').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock1 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage1').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock1 .hoverLight').css("display","none");
  });
  jQuery('#catalogBlock2,#linkSeries2').hover(function() {
    jQuery('#catalogImage2').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock2 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage2').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock2 .hoverLight').css("display","none");
  });
  jQuery('#catalogBlock3,#linkSeries3').hover(function() {
    jQuery('#catalogImage3').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock3 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage3').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock3 .hoverLight').css("display","none");
  });
  jQuery('#catalogBlock8,#linkSeries4').hover(function() {
    jQuery('#catalogImage4').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock8 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage4').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock8 .hoverLight').css("display","none");
  });
  jQuery('#catalogBlock7,#linkSeries5').hover(function() {
    jQuery('#catalogImage5').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock7 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage5').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock7 .hoverLight').css("display","none");
  });
  jQuery('#catalogBlock5,#linkSeries6').hover(function() {
    jQuery('#catalogImage6').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock5 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage6').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock5 .hoverLight').css("display","none");
  });
  jQuery('#catalogBlock4,#linkSeries7').hover(function() {
    jQuery('#catalogImage7').animate({opacity:'1'},{queue:false,duration:400});
    jQuery('#catalogBlock4 .hoverLight').css("display","inline");
  }, function() {
    jQuery('#catalogImage7').animate({opacity:'0'},{queue:false,duration:400});
    jQuery('#catalogBlock4 .hoverLight').css("display","none");
  });
  
  // popup window
  jQuery(function(){
	  jQuery(".popupForm").popupwindow();
  });
  
  jQuery('#imgFade').innerfade({
	animationtype: 'fade',
	speed: 1000,
	timeout: 4000,
	type: 'sequence',
	containerheight: '200px'
  });
  
  jQuery('#imgFadeGrada').innerfade({
	  animationtype: 'fade',
	  speed: 1000,
	  timeout: 4000,
	  type: 'sequence',
	  containerheight: '200px'
  });

});
