/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
  $(".przycisk").click(function(){
		var przycisk =$(this);
		var box = przycisk.parent().parent('.box');
		box.find(".box_tresc").toggle('slide');
		przycisk.toggleClass('open');
                var nazwa=przycisk.attr("class");
                var id=przycisk.attr("id");
                
                if(nazwa=='przycisk'){
                   $.cookie(id, 1);
                }
                else {
                   $.cookie(id, null);
                }
                
                
  });

/*menu bo sie sypa?o pod ie */

    $('.menu_blok li').hover(
      function () {
        $(this).addClass("active");
      },
      function () {
        $(this).removeClass("active");
      }
    );
    $('.menu_blok li.parent').hover(
      function () {
        $(this).addClass("activep");
      },
      function () {
        $(this).removeClass("activep");
      }
    );

 /* formularz kontaktowy*/
	$('#wyslijKontakt').click(function(){
		$('#tekst').text(' ');

		var dane = {
			'imie': $('#imie').val(),
			'email': $('#email').val(),
			'tel': $('#tel').val(),
			'tresc': $('#tresc').val()
		};

		$.post("kontakt.php", dane, function(data) {
			$('#kontakt .tresc, #kontakt .komunikat, #kontakt .email, #kontakt .tel, #kontakt .imie, .ok').hide();
			$('#tresc, #imie, #email, #tel').css({
				'color': '#033D01'
			});

			if(!data.ok) {
				for(x in data.bledy) {
					$('#' + x).css({
						'color': 'red'
					});
					$('#kontakt .' + x).text(data.bledy[x]);
					$('#kontakt .' + x).show();

				}
			} else {

				$('.ok').text('Vielen Dank, Ihre Nachricht wurde erfolgreich versendet.');
				$('.ok').show();

				$('#imie').val('Name');
				$('#email').val('mail@mail.eu');
				$('#tel').val('123123');
				$('#tresc').val('Inhalt');

                                

				data.ok=0;


			}
		}, 'json');

		return false;
	});



/*polec znajomemu */
        $('#wyslijPolec').click(function(){
		$('#tekst').text(' ');

		var dane = {
			'nimie': $('#nimie').val(),
			'nemail': $('#nemail').val(),
                        'oimie': $('#oimie').val(),
			'oemail': $('#oemail').val(),
			'tresc': $('#tresc').val()
		};

		$.post("pwyslij.php", dane, function(data) {
			$('#kontakt .tresc, #kontakt .komunikat, #kontakt .nemail, #kontakt .nimie, #kontakt .oemail, #kontakt .oimie, .ok').hide();
			$('#tresc, #nimie, #nemail, #oimie, #oemail').css({
				'color': '#033D01'
			});

			if(!data.ok) {
				for(x in data.bledy) {
					$('#' + x).css({
						'color': 'red'
					});
					$('#kontakt .' + x).text(data.bledy[x]);
					$('#kontakt .' + x).show();

				}
			} else {

				$('.ok').text('Vielen Dank, Ihre Nachricht wurde erfolgreich versendet.');
				$('.ok').show();

				$('#nimie').val('Name');
				$('#nemail').val('mail@mail.eu');
                                $('#oimie').val('Name');
				$('#oemail').val('mail@mail.eu');
				$('#tresc').val('Inhalt');



				data.ok=0;


			}
		}, 'json');

		return false;
            });



     /*spo?eczno?ci*/
/*facebook*/
/*     window.fbAsyncInit = function() {
        FB.init({
            appId: '174769429209309',
            status: true,
            cookie: true,
            xfbml: true
        });
      };
      (function() {
        var e = document.createElement('script');
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/de_DE/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
 */


});


$(function() {
	function format(poz) {
		return   "<img width='35' height='35' src='images/" + poz.img + "' alt='' />"+poz.name+"";
	}
	$("#szukaj").autocomplete('autocomplete.php', {
		//multiple: true,
                selectFirst:false,
                width: 600,
		dataType: "json",
		parse: function(data) {
			return $.map(data, function(row) {
				return {
					data: row,
					value:row.name,
					result:''+row.name+''
				}
			});
		},
		formatItem: function(item) {
			return format(item);
		}
          
	}).result(function(e, item) {
            window.location = item.url;
	
        });


       

});
