
$(".bramka").live("click", function(){
  var object = $("#checkpoint");
  $("html").animate({
    scrollTop: object.position().top + object.height() - $(window).height() / 2
  }, 700, "swing", function(){
    bg = object.css("background-color");
    color = object.css("color");
    object.animate({
      "background-color": "#f00",
      "color": bg
    }).animate({
      "background-color": bg,
      "color": color
    });
  });
});

$(".kontakt").live("click", function(){
  var object = $("#contactPark");
  $("html").animate({
    scrollTop: object.position().top + (object.height()/2) - $(window).height() / 2
  }, 700, "swing", function(){
    $("input[type=text]", object).animate({
      "border-color": "#f00"
    }).animate({
      "border-color": "#d6d6d6"
    });
  });
});

function getAskForm(url, subject, content, offer_id){
//  container = $('<div id="askForm-container"/>');
//  container.css("opacity", 0.9);
//  askForm = $('<div id="askForm"><span id="askForm-close"></span></div>');
  askForm = $('<div id="askForm"></div>');
  
  $.ajax({
    type: "post",
    dataType: "json",
    url: url,
//    data: $form.serialize(),
    data: {
      "subject": subject,
      "content": content,
      "offer_id": offer_id
    },
    success: function(data, textStatus, XMLHttpRequest){
      askForm.append(data.value);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown){
      alert("Wystąpił nieoczekiwany błąd! Spróbuj ponownie.");
    },
    beforeSend: function(XMLHttpRequest){
      $.fancybox.showActivity();
    },
    complete: function(XMLHttpRequest, textStatus){
      $.fancybox.hideActivity();
    }
  });
//  askForm.css({
//    top : "50%",
//    "margin-top": askForm.height() / 2 * -1
//  });
//  container.append(askForm);

//  return container;
  return askForm;
}
//$("#askForm-close").live("click", function(){
//  $("#askForm-container").fadeOut("normal", function(){
//    $(this).remove();
//  });
//});
$(function(){
  $("a.fancy").fancybox();

  $("div.searchform input[type=text]").tbHinter({
    text: "wpisz szukany tekst"
  });
  var availablePrices = [
    "100 000",
    "150 000",
    "200 000",
    "250 000",
    "300 000",
    "350 000",
    "400 000",
    "500 000",
    "600 000",
    "700 000",
    "800 000",
    "900 000",
    "1 000 000 ",
    "1 250 000",
    "1 500 000"
  ];
  $("#price_min").autocomplete({
    source: availablePrices,
    minLength: 0,
    delay: 0
  });
  $("#price_max").autocomplete({
    source: availablePrices.reverse(),
    minLength: 0,
    delay: 0
  });

  var availableAreas = [
    "20",
    "25",
    "30",
    "35",
    "40",
    "45",
    "50",
    "60",
    "65",
    "70",
    "75",
    "80",
    "90",
    "100",
    "110",
    "120",
    "130",
    "140",
    "150",
    "175",
    "200"
  ];
  $("#area_min").autocomplete({
    source: availableAreas,
    minLength: 0,
    delay: 0
  });
  $("#area_max").autocomplete({
    source: availableAreas.reverse(),
    minLength: 0,
    delay: 0
  });

  $("#price_min, #price_max, #area_min, #area_max").click(function(){
    $(this).autocomplete("search", "");
  });

//  $("#price_min, #price_max, #area_min, #area_max").each(function(){
//    $(this).autocomplete("search", "");
//  });
});

jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({
	travelocity: 0.07
	}, settings);		
	return this.each(function(){
			var $strip = jQuery(this);
			$strip.addClass("newsticker")
			var stripWidth = 1;
			$('#wrapper').css('width', 'auto');
			$('.zglaszanie_oferty_content').css('width', 'auto');
			$strip.find("li").each(function(i){
			//var mult = parseInt(jQuery(this, i).height()/30);
			stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar and Fabien Volpi
			//console.log(jQuery(this, i).outerWidth(true));
			});
			$('#wrapper').css('width', '980px');
			$('.zglaszanie_oferty_content').css('width', '960px');
			//console.log(stripWidth);
			var $mask = $strip.wrap("<div class='mask'></div>");
			var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
			var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
			$strip.width(stripWidth);			
			var totalTravel = stripWidth+containerWidth;
			var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
			function scrollnews(spazio, tempo){
			$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
			}
			scrollnews(totalTravel, defTiming);				
			$strip.hover(function(){
			jQuery(this).stop();
			},
			function(){
			var offset = jQuery(this).offset();
			var residualSpace = offset.left + stripWidth;
			var residualTime = residualSpace/settings.travelocity;
			scrollnews(residualSpace, residualTime);
			});			
	});	
};

$(function(){
    $("ul.error2").liScroll();
}); 


