$(document).ready(function() {
  $('.slideshow').before('<div id="nav" class="nav">').cycle({
    fx:     'scrollRight',
    speed:  'fast',
    timeout: 10000,
    pager:  '#nav'
	});

  $('#oferta #galeria div.img').cycle({
    fx:     'scrollRight',
    speed:  'fast',
    prev:   '#oferta #galeria .prev',
    next:   '#oferta #galeria .next',
    timeout: 0
	});	

  $('#main #oferta_block .slide').jcarousel({
    scroll: 1,
    auto: 3,
    wrap: 'both',
    initCallback: function(carousel) {
      $('#main #oferta_block .prev').bind('click', function() {
        carousel.prev();
        return false;
      });
      $('#main #oferta_block .next').bind('click', function() {
        carousel.next();
        return false;
      });
    },
    buttonNextHTML: null,
    buttonPrevHTML: null
  });
  
  $('#galeria a').lightBox();
  
});
	
	$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'fold',
		slices:15,
		animSpeed:500,
		pauseTime:6000,
		startSlide:0,
		directionNav:true,
		directionNavHide:false,
		controlNav:false,
		controlNavThumbs:false,
		pauseOnHover:true,
		manualAdvance:false,
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){}
	});

                            
  var focus = function(el) { if(this.value == $(this).attr('placeholder')) { this.value = ''; } }
  var blur  = function(el) { if(this.value == '') { this.value = $(this).attr('placeholder'); } }
                            
  $('#kontakt form input, #kontakt form textarea').focus(focus).blur(blur).each(blur);
  
  if ($('#mapa').length > 0 && typeof GBrowserIsCompatible != 'undefined' && GBrowserIsCompatible()) {
    map = new GMap2($('#mapa')[0]);
    map.setCenter(new GLatLng(54.54750802387292, 16.921536326408386), 10);
    map.setUIToDefault();
    var info='<div style="background-color: #fff; width: 200px; font-size: 11px; FONT-FAMILY: Verdana, Tahoma, Arial, Sans-Serif;"><B>Aerosol Service sp. z o.o.</B><hr>Charnowo 36<BR>76-270 Ustka<BR>POLAND <hr><B>GPS</B> N: 54&deg; 32&#39; 51&#34; &nbsp;E: 16&deg; 55&#39; 17&#34; </div>';
         var point = new GLatLng(54.5475, 16.921388888889);
         var marker = new GMarker(point);
         GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(info);
         });
         map.addOverlay(marker);
         marker.openInfoWindowHtml(info); 
    map.hideControls();
    GEvent.addListener(map, "mouseover", function(){map.showControls();});
    GEvent.addListener(map, "mouseout", function(){map.hideControls();}); 
  }
	else	{
		map = {};
		map.addOverlay = map.clearOverlays = map.setCenter = map.setUIToDefault = function() {};
	}

});

function sendForm(){
	$.post("mail.php", {
	  name: $('#name').attr("value"), 
    phone: $('#phone').attr("value"),
	  email: $('#email').attr("value"),
	  content: $('#content1').val()
	},
	function(response){
	  if(response == 1) $("#soli").text('wiadomosc została wysłana');
		else $("#soli").text('wystapił błąd, spróbuj ponownie');
	});
}
