this.screenshotPreview = function(){
	/* CONFIG */

		xOffset = 10;
		yOffset = 30;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#screenshot").remove();
    });
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};




(function(){

    var special = $.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);

    special.scrollstart = {
        setup: function() {

            var timer,
                handler =  function(evt) {

                    var _self = this,
                        _args = arguments;

                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        $.event.handle.apply(_self, _args);
                    }

                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);

                };

            $(this).bind('scroll', handler).data(uid1, handler);

        },
        teardown: function(){
            $(this).unbind( 'scroll', $(this).data(uid1) );
        }
    };

    special.scrollstop = {
        latency: 300,
        setup: function() {

            var timer,
                    handler = function(evt) {

                    var _self = this,
                        _args = arguments;

                    if (timer) {
                        clearTimeout(timer);
                    }

                    timer = setTimeout( function(){

                        timer = null;
                        evt.type = 'scrollstop';
                        $.event.handle.apply(_self, _args);

                    }, special.scrollstop.latency);

                };

            $(this).bind('scroll', handler).data(uid2, handler);

        },
        teardown: function() {
            $(this).unbind( 'scroll', $(this).data(uid2) );
        }
    };

})();






$(document).ready(function(){

        screenshotPreview();


	$(function() {
            var $elem = $('#content');

            $('.nav_up').fadeIn('slow');
            $('.nav_down').fadeIn('slow');

            $(window).bind('scrollstart', function(){
                $('.nav_up,.nav_down').stop().animate({'opacity':'0.2'});
            });
            $(window).bind('scrollstop', function(){
                $('.nav_up,.nav_down').stop().animate({'opacity':'1'});
            });

            $('.nav_down').click(
                function (e) {
                    $('html, body').animate({scrollTop: $elem.height()}, 800);
            });
            $('.nav_up').click(
                function (e) {
                    $('html, body').animate({scrollTop: '0px'}, 800);
            });
        });



        $("#kontaktForm").validate({
                rules: {
                    jmeno: {
                        required: true
                    },
                    prijmeni: {
                        required: true
                    },
                    adresa: {
                        required: true
                    },
                    telefon: {
                        required: true
                    },
                    email: {
                        required: true,
                        email: true
                    }
                },
                messages: {
                    jmeno: "vyplňte jméno",
                    prijmeni: "vyplňte příjmení",
                    adresa: "vyplňte adresu",
                    telefon: "vyplňte telefon",
                    email: "vyplňte email"
                }
     });

        $("a[rel='example4']").colorbox({height:"90%"});
        
         	//validate formulare
          $("#formular").validate({
              rules: {
                  jmeno: {
                      required: true
                  },
                  telefon: {
                      required: true
                  },
                  email: {
                      required: true,
                      email: true
                  },
                  realizace: {
                      required: true
                  }
              },
              messages: {
                  jmeno: "vyplňte jméno",
                  telefon: "vyplňte telefon",
                  email: "vyplňte email",
                  realizace: "vyplňte místo realizace"
              }
          });
             
          $("#dotaz").validate({
              rules: {
                  jmeno: {
                      required: true
                  },
                  email: {
                      required: true,
                      email: true
                  },
                  nadpis: {
                      required: true
                  },
                  dotaz: {
                      required: true
                  }
              },
              messages: {
                  jmeno: "vyplňte jméno",
                  email: "vyplňte email",
                  nadpis: "vyplňte nadpis",
                  dotaz: "vyplňte dotaz"
              }
          });
          
          $("#kontakt").validate({
              rules: {
                  jmeno: {
                      required: true
                  },
                  email: {
                      required: true,
                      email: true
                  },
                  zprava: {
                      required: true
                  }
              },
              messages: {
                  jmeno: "vyplňte jméno",
                  email: "vyplňte email",
                  zprava: "vyplňte zprávu"
              }
          });

          //Hide (Collapse) the toggle containers on load
	$(".toggle_content").hide();

	//Switch the "Open" and "Close" state per click
	$("h3.toggle").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$("h3.toggle").click(function(){
		$(this).next(".toggle_content").slideToggle();
	});
});
