/* Otevírá nové okno */
function popup_window(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150');
}

/** Konvertuje řetězec na formu vhodnou pro cool url */
function make_cool_url(input_name) {
  var inchar =  "áäčďéěíĺľňóô öŕřšťúůüýž";
  var outchar = "aacdeeillnoo orrstuuuyz";
  input_name = input_name.toLowerCase();
  var output_name = '';
  for (var i=0; i < input_name.length; i++) {
    output_name += inchar.indexOf(input_name.charAt(i)) != -1 ? outchar.charAt(inchar.indexOf(input_name.charAt(i)))  : input_name.charAt(i);
  }
  output_name = output_name.replace(/[^a-z0-9_]+/g, '-').replace(/^-|-$/g, '');
  return output_name;
}
    
/* Funkce pro hladké scrollování */
function smooth_scroll(url_suffix) {
  $(document).ready(function() {
    $('#place h2').each(function() {
      var thisText = $(this).text();
      var url = make_cool_url(thisText);
      var anchorLink = '<a id="' + url + '"></a>';
      var anchorText = '<img src="templates/classic/images/asipka.gif" class="asipka" /><a href="'+url_suffix+'/#'+url+'" title="Přejít na '+thisText+'">'+thisText+'</a><br />';
      $(this).before(anchorLink);
      $('div#anchors').append(anchorText);
    });
  });
  
  $(document).ready(function() {
    $('a[href*=#]').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var $target = $(this.hash);
        $target = $target.length && $target || $('[id=' + this.hash.slice(1) +']');
        if ($target.length) {
          var targetOffset = $target.offset().top;
          $('html,body').animate({scrollTop: targetOffset}, 1000);
          return false;
        }
      }
    });
  });
}
/*
 * Tooltip script
 * written by Alen Grakalic (http://cssglobe.com)
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */

this.tooltip = function(){
	/* CONFIG */
		xOffset = -10;
		yOffset = 20;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$("a.tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});

/*
 * Image preview script
 * written by Alen Grakalic (http://cssglobe.com) 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */
this.imagePreview = function(){
	/* CONFIG */

		ixOffset = 330;
		iyOffset = 10;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";
		this.cap = $(this).children("img").attr("alt");
		var c = (this.cap != "") ? "<br/>" + this.cap : "";
		$("body").append("<p id='preview'><img src='"+ this.t +"' alt='Image preview' />"+ c +"</p>");
		$("#preview")
			.css("top",(e.pageY - ixOffset) + "px")
			.css("left",(e.pageX + iyOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#preview").remove();
    });
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - ixOffset) + "px")
			.css("left",(e.pageX + iyOffset) + "px");
	});
};
$(document).ready(function(){
	imagePreview();
});


/* Mini nahled */
this.miniPreview = function(){
	/* CONFIG */

		mxOffset = 330;
    myOffset = 10;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$("span.mini_preview").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='preview'><img src='"+ this.t +"' alt='Image preview' /></p>");
		$("#preview")
			.css("top",(e.pageY - mxOffset) + "px")
			.css("left",(e.pageX + myOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#preview").remove();
    });
	$("span.mini_preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - mxOffset) + "px")
			.css("left",(e.pageX + myOffset) + "px");
	});
};
$(document).ready(function(){
	miniPreview();
});
