$(function()
{
	$('.fancybox').fancybox();
	$('.geometria').fancybox({'width': 800, 'autoScale': false});
	$('#szukaj').change(gotoValue);
	$('#gdzieKupic,.gdzieKupic').fancybox( { 'width': 700, 'height': 600, 'type': 'iframe', 'autoScale': false, 'padding': 0, 'transitionOut': 'none' , 'transitionIn': 'none' } );
	$(".tiptip").tipTip({delay: 50, defaultPosition: "top"});
	if($('#slidebox')) {
    initSlidebox();
    $('#slidebox-hide').click(function(){
      setCookie('slidebox_hide[negocjacja_ceny]',true,365);
      $('#slidebox').remove();
      return false;
    });
	}
	$('input.compare').click(function(event){event.stopPropagation();})
});

function gotoValue()
{
	window.location.href = this.value;
}

function initSlidebox() {
  var scrollbox_top = jQuery('.cena:last').offset().top + 50;
  var scrollTop = scrollbox_top - $(window).height() + 100;
  var scrollbox_speed = 500;
  jQuery('#slidebox').css({
    'top': scrollbox_top+'px'
  });
  $(window).scroll(function(){
		/* when reaching the element with id "last" we want to show the slidebox. Let's get the distance from the top to the element */

		if(scrollTop < $(window).scrollTop())
			$('#slidebox').animate({'left':'0px'},scrollbox_speed);
		else 
			$('#slidebox').stop(true).animate({'left':'-200px'},scrollbox_speed/2);	
	});
	
	/* remove the slidebox when clicking the cross */
	$('#slidebox-close').bind('click',function(){
/* 	  $.cookie("slidebox_hide[negocjacja_ceny]", true, { expires: 60 }); */
		$(this).parent().remove();
		return false;
	});
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
