function mySetCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function myGetCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * 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 */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("img.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.src +"' alt='Náhľad obrázku' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


this.tooltipInit = function(){
        //alert('whatever');
        $('.tooltipLink').bstip({
              color:"bswrap",
              type:"menu",
              tack:100,
              hook:'bottom-mid',
              sticky:"none",
              opacity:1,
              xnudge: 0,
              ynudge: 0
        });
}

// starting the script on page load
$(document).ready(function(){
  
  $(".smsinzercia").tooltip({ position: "top center", opacity: 1});
  
  $(".counter-number").each( function(i) {
  $(this).attr('id','num'+i);
  });
  function loadinput() {
  var newval = $("#numgo").val();
  loadticker(newval);
  }
  function loadticker(ticnum) {
  var fticnum = add_commas(ticnum);
  var numheight=24;
  addticker(fticnum);
  if (ticnum && ticnum != 0) {
  
  var s = String(fticnum);
  
  for (i=s.length;i>=0; i--) {
  var onum=s.charAt(i);
  $("#num"+i).attr('value',onum);
  }
  
  $(".counter-number").each( function() {
  var nval=$(this).attr("value");
  if (!isNaN(nval)) {
  var nheight = Number(nval)*numheight*-1;
  $(this).animate({ top: nheight+'px'}, 1500 );
  }
  if (nval==','){
  $(this).animate({ top: '-240px'}, 1500 );
  }
  });
  }
  }
  function addticker(newnum) {
  var digitcnt = $(".counter-number").size();
  var nnum = String(newnum).length;
  var digitdiff = Number(nnum - Number(digitcnt));
  if (digitdiff <0) {
  var ltdig = (Number(nnum)-1);
  $(".counter-number:gt(" + ltdig + ")").remove();
  }
  
  for(i=1;i<=digitdiff;i++) {
  $(".counter-wrap").append('<div class="counter-number" id="num' + (Number(digitcnt+i-1)) + '">&nbsp;</div>');
  }
  }
  function add_commas(nStr) {
  /*nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
  x1 = x1.replace(rgx, '$1' + ',' + '$2');
  }
  return x1 + x2;*/
  return nStr;
  }

	imagePreview();
        tooltipInit();
	$("div.scrollable").scrollable();
	lastBlock = $("#a1");
    maxHeight = 145;
    minHeight = 35;	

    $("#prepinac ul li a").hover(
      function(){
        $(lastBlock).animate({height: minHeight+"px"}, { queue:false, duration:400 });
		$(this).animate({height: maxHeight+"px"}, { queue:false, duration:400});
		lastBlock = this;
      }
    );

    function updateUserCount() {
        $.get('./pocetinzeratov.php', loadticker);
    }

    updateUserCount();
    setInterval(updateUserCount, 15000);
    
    $('.caption').hover(function(){
					$(".cover", this).stop().animate({top:'95px'},{queue:false,duration:140});
				}, function() {
					$(".cover", this).stop().animate({top:'115px'},{queue:false,duration:140});
				});

  var left    = 0,
  top     = 0,
	sizes   = { retina: { width:100, height:100 },
	            webpage:{ width:288, height:216 } },
	            webpage = $('#velka_fotografia'),
              offset  = { left: webpage.offset().left, top: webpage.offset().top },
	            retina  = $('#lupa');
	 
  webpage.mousemove(function(e){
	 
	  left = (e.pageX-offset.left);
	  top = (e.pageY-offset.top);
	 
     if(retina.is(':not(:animated):hidden')){
	     webpage.trigger('mouseenter');
	   }
	 
	   if(left<0 || top<0 || left > sizes.webpage.width ||
	     top > sizes.webpage.height)
	     {
	            /*  If we are out of the bondaries of the
	                webpage screenshot, hide the retina div */
	 
	            if(!retina.is(':animated')){
	                webpage.trigger('mouseleave');
	            }
            return false;
	        }
	 
	        /*  Moving the retina div with the mouse
	            (and scrolling the background) */
	 
	        retina.css({
	            left                : left - sizes.retina.width/2,
	            top                 : top - sizes.retina.height/2,
	            backgroundPosition  : '-'+(1.95*(left))+'px -'+(1.76*(top))+'px'
	        });
	 
	    }).mouseleave(function(){
	        retina.stop(true,true).fadeOut('fast');
	    }).mouseenter(function(){
	        retina.stop(true,true).fadeIn('fast');
	    });

});


