﻿/*
skrypty dodatkowe
autor: http://kodhtml.pl
*/

//cień
$.fn.cien = function () {
	return this.each(function () {
		var cien = $(this);
		cien.html('<span class="cien-tekst">' + cien.html() + '</span>').css('position', 'relative');
		$('<span class="cien-tlo">' + cien.html() + '</span>').appendTo(cien);
	});
};
//ramka video
$.fn.videoramka = function () {
	return this.each(function () {
		var videoramka = $(this);
		videoramka.html('<div class="videoramka">' + videoramka.html() + '</div>').css('position', 'relative');
		$('<div class="videoramka-top"></div><div class="videoramka-bottom"></div><div class="videoramka-left"></div><div class="videoramka-right"></div>').appendTo(videoramka);
	});
};
//ramka - moduły
$.fn.okno = function () {
	return this.each(function () {
		var okno = $(this);
		okno.html('<div class="okno">' + okno.html() + '</div>').css('position', 'relative');
		$('<div class="okno-left"></div><div class="okno-right"></div><div class="okno-top"></div><div class="okno-bottom"></div>').appendTo(okno);
	});
};
//rotator pionowy - animacja
$.fn.rotator = function(){
	return this.each(function(index) {
		var $this = $(this);
		function beginRotation(){
      $this.data("timer", setInterval(function(){
        var wys_elem = $this.children().filter(":first-child").height();
        $this.animate({scrollTop: (wys_elem) + "px"}, 1000, function(){
          $this.scrollTop(0);
          $this.append($this.children().filter(":first-child"));
        });
      }, 5000));
		}
		$this.mouseover(function(){
		    clearTimeout($this.data("timer"));
		});
		$this.mouseout(function(){
		    beginRotation();
		});
		beginRotation();
	});
};
// rotator poziomy - stały
$.fn.rotator2 = function(){
	return this.each(function(element) {
		var $this = $(this).children();
    var pozycja_x=0;
    var pierwszy=$this.children();
    var szer_elem = pierwszy.width();
    pierwszy.css({
      width :(szer_elem*4)+'px'
      
    });
    $this.children().append(pierwszy.children().clone()).append(pierwszy.children().clone());
		function beginRotation(){
      $this.data("timer", setInterval(function(){
        pozycja_x = pozycja_x-1;
        pierwszy.css ("margin-left",pozycja_x+"px");
        if ((szer_elem+pozycja_x-32)<0) pozycja_x=0;
      }, 20));
		}
		$this.mouseover(function(){
		    clearTimeout($this.data("timer"));
		});
		$this.mouseout(function(){
		    beginRotation();
		});
		beginRotation();
	});
};
//walidacja formularza
function wynik(data,status) {
  (status=='success') ? alert (data) : alert ('Błąd systemowy. Przepraszamy za wynikłą sytuację. Prosimy o kontakt telefoniczny.');
};
//start
$(document).ready(function(){
  var ktory,obecny;
  $('.cien').cien();
  $('.video').videoramka();
  $('.ramka').okno();
  $('#slowa .container').rotator();
  $('#firmy').rotator2();
  $('#zapytaj').submit(function() {
    var dane = $(this).serialize();
    $.post('wyslij.php',dane,wynik);
    return false;
  });$("#kalkulator").keyup(function(event){  if(event.keyCode == 13){    $("#submit").click();  }});	$("#sendInfoS2").click(function() {                $("#info2").slideToggle("slow");                                if (show == 1) {                                        show = 0;                                } else {                                        show = 1;                                      }                                                               $.cookie('show', show, { expires: 7 });                                return false;                                       });
  $(".referencja-obraz").colorbox({
    onClosed:function(){$("#referencja_button"+ktory).click();}
  });
  $(".referencje").colorbox({
    onComplete:function(){
      obecny = $("#cboxCurrent").html();
      ktory = obecny.slice(obecny.indexOf('of')-2,obecny.indexOf('of')-1);
    },
    width:"935px", inline:true
  });

  $(".kontakt-obraz").colorbox({
    onClosed:function(){$("#kontakt_button"+ktory).click();}
  });
  $(".kontakt").colorbox({
    onComplete:function(){
      obecny = $("#cboxCurrent").html();
      ktory = obecny.slice(obecny.indexOf('of')-2,obecny.indexOf('of')-1);
    },
    width:"935px", inline:true
  });

  $("table td:last-child").addClass('ostatni');
  $("table th:last-child").addClass('ostatni');
  $("tbody tr:last-child").addClass('ostatni');
  
});



/// Marek Najar:




jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200,
		ieOffset: 50
		}, settings);
		return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.css('display','none'); //in case the user forgot
		$(window).scroll(function() {
			if(!jQuery.support.hrefNormalized) {
				el.css({
					'position': 'absolute',
					'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
				});
			}
			if($(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};
$(document).ready(function() {
	$('#top-link').topLink({
		min: 400,
		fadeSpeed: 500
	});
	//smoothscroll
	$('#top-link').click(function(e) {
		e.preventDefault();
		$.scrollTo(0,300);
	});
});
