$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:4000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev

		controlNav:false, //1,2,3...
		captionOpacity:1, //Universal caption opacity


	});
});


var font_size = 0;

$(function(){

	


/*
	$('#slider').each(function() {
		$('#slider').s3Slider({
            timeOut: 3000
        });
	});
*/
    $("#btn-font-increase, #btn-font-decrease").click(function() {
        var offset = $(this).is('#btn-font-decrease') ? -1 : 1;
        font_size += offset;
        $(".nav-langs").css('right', font_size * (14));
        if (font_size > 4) {
            $("#btn-font-increase").css('visibility', 'hidden');
        } else {
            $("#btn-font-increase").css('visibility', 'visible');
        }
        if (font_size == 0) {
            $("#btn-font-decrease").css('visibility', 'hidden');
        } else {
            $("#btn-font-decrease").css('visibility', 'visible');
        }
        $("html *").each(function () {
            var currentFontSize = $(this).css('font-size');
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum + offset;
            $(this).css('font-size', newFontSize);
        })
    });

    $("a[href=/#view-on-map]").click(function () {

        if (typeof(window.map) == 'undefined') {
            window.map = $('<div style="z-index:99999999; display: none; cursor: pointer; position: absolute; padding: 7px; background: #ffffff; box-shadow: 0 0 5px #666; -moz-box-shadow: 0 0 5px #666; -webkit-box-shadow: 0 0 5px #666;" />').appendTo('body').click( function () {
                $(this).fadeOut(400); $.dimOut();
            } );
        $('<div id="map" style="width: 500; height: 500px" />').appendTo(window.map);
        }

        $map = window.map;

        $.dimIn({}, null, function () {
            window.map.click();
        });

        var props = { width: 500,
                      height: 500,
                      left: Math.ceil($(window).width() / 2) - 250,
                      top: $(document).scrollTop() + Math.ceil(($(window).height() - 500) / 2) - 20};

        props.top = props.top < 10 ? 10 : props.top;

        if ($map.css('display') == 'none') {
            $map.css(props);
        } else {
            $map.find('img').fadeOut(400);
        }

        var img = new Image();

        $map.fadeIn(400, function () {
            if (GBrowserIsCompatible()) {
            var m = new GMap2(document.getElementById("map"));
            m.setCenter(new GLatLng(54.689387,25.280024), 13);
            m.openInfoWindow(m.getCenter(), $("#map-baloon").html());
            m.addOverlay(new GMarker(m.getCenter()));
            m.setUIToDefault();
            }
        });

        return false;

    });
	
   /* $(".validate-all").submit( function () {
	   alert('asd');
	   // var $inputs = $(this).find(':input[type=text]:visible, textarea').animate( {backgroundColor: "#ffffff"}, 400);
        //return $inputs.filter('[value=]').stop().animate({backgroundColor: "#dedede"}, 500).length == 0;

    });
	*/

		
		$('#leave-comment').each(function() {
			$("#leave-comment").validate({
				rules: {
					name: {
						required: true,
						minlength: 2
					},
					user_email: {
						required: true,
						email: true
					},
					content: {
						required: true,
						minlength: 5
					}
				},
				messages: {
					name: {
						required: "",
						minlength: ""
					},
					user_email: "",
					content: {
						required: "",
						minlength: ""
					}
				}
			});
		});
		
		
		$("#form-subscription").submit(function() { 
			$('#invalid-mail').addClass('hide');
			$('#error-repeat').addClass('hide');
			$('#error-exist').addClass('hide');
			$('#success-verify').addClass('hide');
			
			$.post("/", { ajax: "true", email: "", elpastas:  $("#email-address").val(), subscrlang: $('#subscrlang').val()},
			function(data){
		   
			 if(data == 'invalid') {
			 	$('#invalid-mail').removeClass('hide');		
			 } 
			 else if(data == "error") {
			 	$('#error-repeat').removeClass('hide');
			 } 
			 else if (data == 'exists') {
				$('#error-exist').removeClass('hide');                  
			 } 
			 else {
			 	$("#success-verify").removeClass('hide').fadeIn();
			 }  
	   		});
			return false;	
		
		});
		



});

jQuery.extend({
    slide: function($container, child_element_no, callback) {
        var $slider = $container.children(":first");
        var new_offset = $slider.children(':eq('+child_element_no+')').offset().left - $container.offset().left - ($slider.offset().left - $container.offset().left);
        $slider.animate( {left: -1 * new_offset}, 600, 'easeOutQuad', callback);
        return this;
    },
    slide_page: function($container, page_no, size, callback) {
        if (typeof(size) == 'undefined') {
            size = parseInt($container.parent().css('width').match(/\d+/));
        }
        var new_offset = size * page_no;
        $container.animate( {left: -1 * new_offset}, 600, 'easeOutQuad', callback);
        return this;
    },
    imgLoad: function(src, loaded_callback) {
        var img = new Image();
        $(img).load( function () {
            loaded_callback(img);
        });
        img.src = src;
        return this;
    },
    dimIn: function (user_css, callback, on_click) {
        $dim = $("#dim");
        if ($dim.length == 0) {
            $dim = $("<div />").attr('id', 'dim').css(
                {position: 'absolute',
                  top: 0,
                  left: 0,
                  width: '100%',
                  height: $(document).height(),
                  zIndex: 99999998,
                  background: '#333',
                  opacity: .4});
            $('body').prepend($dim);
        }
        if (on_click != undefined) {
            $dim.click(on_click);
        }
        if ($dim.data('act') == true) return false;
        if (user_css != undefined) {
            $dim.css(user_css);
        }
        return $dim.data('act', true).fadeIn(400, callback);
    },
    dimOut: function (callback) {
        $dim = $("#dim").unbind('click');
        if ($dim.data('act') == true) {
            $dim.fadeOut(400, callback).data('act', false);
        }
    }
});

jQuery.fn.extend({
    center: function () {
        this.css( {position: 'absolute',
                    top: $(document).scrollTop() + (Math.ceil($(window).height()) - this.height()) / 2,
                    left: '50%',
                    marginLeft: -1 * Math.ceil(this.width() / 2)} );

        return this;
    },
	fadeOver: function (speed, callback) {
		c = this.clone();
		c.css( {position: 'absolute',
				 width: this.width(),
				 height: this.height(),
				 display: 'none',
				 zIndex: 2} );
        $tp = this.parent(); // container
		$tp.css( {width: $tp.width(),
				   height: $tp.height()} );

		c.insertBefore(this).fadeIn(speed, function () {
			c.next().remove();
			c.css( {position: 'relative', zIndex: 1} );
			if (typeof(callback) == 'function') callback();
		});
		return this;
	}
});

       
    

