;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

$( function () {

    var parter_slider_pos = 0;
    var $sp = $("#slider-sponsors");
    var count = $sp.find('a,b').length;

    function animate_partner() {
        
        if (parter_slider_pos + 1 == count) {
            parter_slider_pos = 0;
        } else {
            parter_slider_pos++;
        }

        $.slide($sp, parter_slider_pos, function () {

            setTimeout(animate_partner, 2500);

        });
        
    }

    setTimeout(animate_partner, 2500);

    $("#slider-news-pages a").click( function () {

        if (!$(this).hasClass('act')) {

            $("#slider-news-pages a").removeClass('act');
            $(this).addClass('act');

            var index = $(this).prevAll().length;

            $.slide($("#slider-news"), index);

        }

        return false;

    });

    // calculator

    var $len = $("#price-length");

    if (($.browser.msie === true) && ($("#popup").length == 0)) {
        if (($.browser.version == '7.0') || ($.browser.version == '6.0')) {
            var zIndexNumber = 20000;
            $('div').each(function() {
                $(this).css('zIndex', zIndexNumber);
                zIndexNumber -= 10;
            });
        }
    }
	
    function get_price($input) {

        var values = String($input.attr('class').match(/price[0-9\-]+/)).match(/\d+/g);
        return values[$len[0].selectedIndex] * parseInt($input.val());

    }

    function calculate_price() {

        var sum = 0;

        $("#calculator .textfield").each( function () {

            sum += get_price($(this))

        });

        return sum;

    }

    function update_price() {

        var price = calculate_price();
        
        if (parseInt(price) > 2000) {
            $("#wrap-price").hide();
            $("#wrap-price-contact").show();
        } else {
            
            var dis = 0;
            if ($("#discount-select .act").length > 0) {
                dis = String($("#discount-select .act").attr('href')).match(/s?\d+/);
            }
            
            if (dis != 0) {
                
                if (dis == "s15") {
                    // only for single ticket
                    
                    var adult_price = get_price($("#adult"));
                    
                    if (adult_price != 0) {
                        
                        var single_adult_price = adult_price / $("#adult").val();
                        price = price - Math.round(single_adult_price * 0.15);          // remove 15% percent from single adult ticket
                        
                    } else {
                        
                        var youth_price = get_price($("#opt-2"));
                        
                        if (youth_price != 0) {
                            
                            var single_youth_price = youth_price / $("#opt-2").val();
                            price = price - Math.round(single_youth_price * 0.15);      // remove 15% percent from single youth ticket
                            
                        } else {
                            
                            var baby_price = get_price($("#opt-3"));
                            
                            if (baby_price != 0) {
                                
                                var single_baby_price = baby_price / $("#opt-3").val();
                                price = price - Math.round(single_baby_price * 0.15);
                                
                            }
                            
                        }
                        
                    }
                    
                } else {
                    
                    price = Math.round(price * (1 - dis / 100));
                    
                }
                
            }
            $("#wrap-price").show();
            $("#wrap-price-contact").hide();
        }
        
        $("#sum").html(price).parents('.bg-2:first').stop().animate( { backgroundColor: '#FEEED6' }, 300, function () {
            $(this).animate( { backgroundColor: '#FAA41D' }, 300);
        });

    }

    $len.change( function () {
        update_price();
    } );

    $("#calculator .textfield").bind('keydown keyup change', function () {
        update_price();
    });

    $("#discount-select a").click( function () {
        $("#discount-select a").removeClass('act');
        $(this).addClass('act');
        $("#discounts").html(String($(this).html()).substr(0, 7) + '&hellip;');
        var $p = $(this).parent();
        $p.hide();
        update_price();
        setTimeout( function () {
            $p.attr('style', '');
        }, 100);
        return false;
    });

    $("#vip-ticket").click(function () {
        update_price();
    });

    $(".plus-of, .minus-of").click( function () {

        var $v = $(this).parent().find('input');
        var diff = $(this).is('.plus-of') ? 1 : -1;
        var val = parseInt($v.val());
        if ((val == 0) && (diff == -1)) return false;
        $v.val(parseInt($v.val()) + diff);
        update_price();
        return false;

    });
    
    // END calculator

    if (($("#center-content").length > 0) && ($("#sidebar-right").length > 0)) {
        if ($("#center-content").height() < $("#sidebar-right").height()) {
            $("#center-content .cms-text").css('height', $("#sidebar-right").height() - 23);
        }
    }

    $(".top-nav li.act, .top-nav li.act + li").css('background', 'none');

    var js_actions = $("#body").attr('class').match(/js\-[a-z_]+/g);

    $.each(js_actions, function () {
        primer[this.substr(3)]();
    });

});

var primer = {

    enlarge : function () {

      $("a.enlarge").click( function () {

          popup($(this).attr('href'));
          return false;

      });


    },

    offers : function () {

        $("#wrap-offers .block-8").each( function () {

            var $t = $(this).find('.bg');
            var $p = $(this).prev().find('.bg');
            
            if ($(this).prevAll().length % 2 == 1) {
                if ($t.height() > $p.height()) {
                    $p.css('height', $t.height());
                } else {
                    $t.css('height', $p.height());
                }
            }

        });

    },

    subscription : function () {

        var $ls = $("#label-subscription");
        $ls.data('save', $ls.html());

        $("#form-subscription").submit(function () {

            $ls.html($ls.data('save')).animate( { color: "#000000" } );
            var u = String(document.location);
            u = u.substring(u.indexOf('/', 8));
            $.post(u, { ajax: true,
                        email: '',
                        elpastas: $("#email-address").val()}, function (data) {

                            if ((data == 'invalid') || (data == 'error')) {
                                $ls.html($(".msg-" + data).html()).animate({color:"#ffffff"});
                                return false;
                            }

                            if (data == 'exists') {
                                $("#subscription-status b").hide().parent().find('b.msg-exists').show();
                            }

                            $("#form-subscription").fadeOut( function () {

                                $("#subscription-status").fadeIn();

                            });

                        });

            return false;

        });

    },

    contacts : function () {
        var test = document.getElementById('google_map');
        var pos = new GLatLng(54.71654, 25.276837);
        map = new GMap2(test);
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(54.7152014, 25.2867084), 14);

        var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.image = "http://www.vandensparkas.lt/templates/img/minilogo.png";
        baseIcon.iconSize = new GSize(48, 60);
        baseIcon.shadowSize = new GSize(48, 60);
        baseIcon.iconAnchor = new GPoint(24, 30);
        baseIcon.infoWindowAnchor = new GPoint(24, 30)

        map.addOverlay(new GMarker(pos, { icon: baseIcon } ));

        GEvent.addListener(map, "dragstart", function() {
            map.closeInfoWindow();
        });

        $("#contacts-tabs a").click( function () {

            $(this).parent().find('a').removeClass('act').end().end().addClass('act');

            map.closeInfoWindow();
            map.clearOverlays();

            var logo_marker = new GMarker(pos, { icon: baseIcon } );
            map.addOverlay(logo_marker);
            GEvent.addListener(logo_marker, "click", function() {
                map.openInfoWindow(pos, bhtml);
            });
            
            if ($(this).is('.i2')) {

                //map.setCenter(new GLatLng(54.7152014, 25.2867084), 15);

                var markers = [];
                markers.push([new GLatLng(54.713082,25.276151), $("#balloon-bus-1").html()]);
                markers.push([new GLatLng(54.715127,25.286536), $("#balloon-bus-2").html()]);
                markers.push([new GLatLng(54.714792,25.286697), $("#balloon-bus-3").html()]);
                markers.push([new GLatLng(54.714984,25.287459), $("#balloon-bus-4").html()]);
                markers.push([new GLatLng(54.71517,25.287781), $("#balloon-bus-4").html()]);
                markers.push([new GLatLng(54.714987,25.277256), $("#balloon-bus-5").html()]);

                map.panTo(markers[2][0]);

                $.each(markers, function () {

                    var coords = this[0];
                    var html = this[1];

                    this[2] = new GMarker(coords);
                    
                    map.addOverlay(this[2], this[1]);
                    GEvent.addListener(this[2], "click", function() {
                        map.openInfoWindow(coords, html);
                    });

                });

            } else {

                var bhtml = $("#balloon").html();
                
                map.openInfoWindow(pos, bhtml);

            }

            return false;

        });

        $("#contacts-tabs a:first").click();

    },

    gallery : function () {

        $(".next-photo, .prev-photo", "#popup").hover( function () {
            
            $(this).stop().animate( { backgroundColor: '#fcef43' }, 400);

        }, function () {

            $(this).stop().animate( { backgroundColor: '#ffffff' }, 400);

        }).click( function () {

            var index;

            if ($(this).is('.next-photo')) {
                var $next = $("#thumbs a.act").next();
                index = $next.prevAll().length;
                if (index % 8 == 0) {
                    $("#popup .right").click();
                } else {
                    if ($next.click().next().length == 0) {
                        $(this).hide();
                    }
                }
                $(".prev-photo", "#popup").show();
            } else {
                var $prev = $("#thumbs a.act").prev();
                index = $prev.prevAll().length;
                if (index % 8 == 7) {
                    $("#popup .left").click();
                } else {
                    if ($prev.click().prev().length == 0) {
                        $(this).hide();
                    }
                }
                $(".next-photo", "#popup").show();
            }
            return false;

        });

        $("#galleries a").click( function () {

            $(".next-photo", "#popup").show();
            $(".prev-photo", "#popup").hide();

            var gid = $(this).attr('id').match(/\d+/)[0];

            (g["g_" + gid].length < 9) ? $("#popup .right").hide() : $("#popup .right").show();

            $t = $("#thumbs").find('div').html('').css('left', 0);
            $("#popup h3").html($(this).text());
            $("#act-frame").css('left', 0);
            $("#popup .left").hide();
            
            $.each(g["g_" + gid], function () {
                $t.append('<a href="#"><img src="/i.php?w=90&h=60&m=2&f=uploads/gallery/'+this+'" alt="" /></a>');
            });
            (g["g_" + gid].length > 8) ? $("#popup .right").show() : $("#popup .right").hide();

            $("#preview").hide();

            var props = {
                left: Math.ceil(($(window).width() - 820) / 2),
                top: $(document).scrollTop() + Math.ceil(($(window).height() - g["h_" + gid]) / 2)
            };

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

            $.dimIn();
            $("#popup").css(props).fadeIn();
            $("#preview").attr('src', '/uploads/gallery/' + g["g_" + gid][0])
                         .parent().height(g["h_" + gid]);
            $t.find('a:first').click();

            return false;

        });

        $("#thumbs a").live('click', function () {

            $(this).parent().find('.act').removeClass('act');
            $(this).addClass('act');

            var left = $(this).offset().left - $(this).parent().offset().left + 18;
            left += parseInt($("#thumbs > div").css('left'));
            $("#act-frame").animate( {'left': left}, 400, 'easeOutQuad');

            var url = $(this).find('img').attr('src').match(/&f=(.+)/)[1];

            if ($(this).next().length == 0)  {
                $(".next-photo", "#popup").hide();
            } else {
                $(".next-photo", "#popup").show();
            }
            if ($(this).prev().length == 0) {
                $(".prev-photo", "#popup").hide();
            } else {
                $(".prev-photo", "#popup").show();
            }

            $("#preview").fadeOut(400, function () {

                $("#loading").show();

                $.imgLoad('/' + url, function (img) {

                    $("#loading").hide();
				
                    $("#preview").css( { height: img.height,
                                         width: img.width} ).attr('src', img.src).fadeIn(400);

                });
				
			});

            return false;

        });

        var thumbs_pos = 0;

        $(".left, .right", "#popup").click( function () {

            var $t = $("#thumbs div");
            if ($t.is(":animated")) return false;

            var count = Math.ceil($t.find('a').length / 8);

            if ($(this).hasClass('right')) {

                // paskutine pozicija
                if (thumbs_pos + 1 == count - 1) {
                    $(this).hide();
                }

                $("#popup .left").show();

                thumbs_pos++;

                $.slide_page($t, thumbs_pos, 776, function () {
                    $("#thumbs a:eq(" + (thumbs_pos * 8) + ")").click();
                });

            } else {

                if (thumbs_pos == 1) {
                    $(this).hide();
                }

                $("#popup .right").show();

                thumbs_pos--;

                $.slide_page($t, thumbs_pos, 776, function () {
                    $("#thumbs a:eq(" + (thumbs_pos * 8 + 7) + ")").click();
                });

            }

            return false;

        });

        $("#btn-close").click( function () {

            $.dimOut();
            $("#popup").fadeOut(400, function () {
                $("#act-frame").css('left', 18);
                $("#preview").hide();
            });
            return false;

        });

        var alias = String(document.location);
        alias = alias.substr(alias.lastIndexOf('/') + 1);
        var photo_id = alias.match(/#(.+)$/);
        if (photo_id != null) {
            photo_id = photo_id[1];
            alias = alias.replace(/#(.+)$/, '');
            if ($("#alias-"+alias).length > 0) {
                $("#alias-"+alias).find("a:first").trigger('click');
                /*
                var $activate = $("#thumbs").find('img[src$='+photo_id+']').parent()
                thumbs_pos = (Math.ceil($activate.prevAll().length / 8)) - 1;
                setTimeout( function () {
                    $.slide_page($("#thumbs div"), thumbs_pos, 776, function () {
                        $activate.click();
                    });
                }, 400)
                */
            }
        }

    },

    gallery_slide : function () {

        var gallery_slide_pos = 0;

        $("#btn-next-photo, #btn-prev-photo").click(function (e, fakeclick) {

            var $gs = $("#gallery-slider");

            if (fakeclick == undefined) {
                clearInterval(autoslider);
            }

            if ($(this).hasClass(".fr")) {
                gallery_slide_pos++;
            } else {
                gallery_slide_pos--;
            }

            if (gallery_slide_pos > $gs.find('a').length - 1) {
                gallery_slide_pos = 0;
            }

            if (gallery_slide_pos < 0) {
                gallery_slide_pos = $gs.find('a').length - 1;
            }

            $.slide($("#gallery-slider"), gallery_slide_pos);

        });

        var autoslider = setInterval(function () {
            
            $("#btn-next-photo").trigger('click', [true]);
            
        }, 3000);

    },

    rateable : function () {

        $(".rateable:not(.rated)", "#center-content")
            .mouseover( function () {

                $(this).is('.rated') ? $(this).unbind('mousemove') : $(this).data('r', $(this).find('div').attr('class'));

            })
            .mouseout( function () {

                $(this).is('.rated') ? $(this).unbind('mousemove') : $(this).find('div').attr('class', $(this).data('r'));

            })
            .mousemove( function (e) {

                var offset = Math.ceil((e.pageX - $(this).offset().left) / 16);
                offset = offset == 0 ? 16 : offset * 16;
                $(this).find('span').css('width', offset + 'px');

            })
            .click( function () {

                var vote = parseInt($(this).find('span').css('width').match(/\d+/) / 16);
                $(this).unbind('mousemove').addClass('rated');

                $.post('/', {ajax: true,
                              vote: true,
                              page_id: $(this).attr('id').match(/\d+/)[0],
                              stars: vote} , function (data) {

                                eval(data);

                              } );

            });

    },

    fun : function () {

        $(".y-block").each( function () {

            $(this).css('height', $(this).height()).data('h', $(this).height())

        } );

        $(".y-block .expand").click( function () {

            $yb = $(this).parents(".y-block");
            $yb.find('.hidden').fadeIn();
            
            var props = { height: $yb.height() + $yb.find(".hidden").height() + 30,
                          backgroundColor: "#ffffff" };

            if ($yb.hasClass('expanded')) {
                props = { height: $yb.data('h') - 2,
                          backgroundColor: "#FCEF43"};
            }

            $yb.toggleClass('expanded').animate(props, 400, 'easeOutQuad');

            return false;

        });

    },

    validate: function () {

        $("form.validate-all").submit( function () {

            var $inputs = $(this).find(':input[type=text]:visible, textarea').animate( {backgroundColor: "#ffffff"}, 400);

            return $inputs.filter('[value=]').stop().animate({backgroundColor: "#00AEEF"}, 500).length == 0;

        });

    },

    poll: function () {

        $("#btn-vote").click( function () {

            $(this).css('visibility', 'hidden');

            var answer_id = $("#answers input:radio:checked").val();
            var $r = $("#results");

            $.post('/', {ajax: true,
                          poll: true,
                          poll_id: $(this).attr('href').match(/\d+/)[0],
                          answer: answer_id} , function (data) {

                            // balsavimas sekmingas, rodom rezultata
                            if (data != 'error') {

                                $r.find('.filler div').css('width', 0);

                                $.slide($("#wrap-poll"), 1, function () {

                                    $.each(data, function (key) {

                                       $("#" + key).animate( {width: this + '%'}, 1000, 'easeOutQuad' )
                                                   .parent().parent().find('span').html(this + '%');

                                    });

                                });

                            }

                          }, "json" );

            return false;

        });

    }

}

//- required
function popup(url) {

    if (typeof(window.popuped) == 'undefined') {
        window.popuped = $('<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).find('img').fadeOut(400).end().fadeOut(400);$.dimOut();
        } );
        $('<img style="display: none" />').appendTo(window.popuped);
    }

    $popuped = window.popuped;

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

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

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

    var img = new Image();

    $popuped.fadeIn(400);

    $(img).load( function () {

        $popuped.find('img').attr('src', img.src).end().animate(
            {
                left: Math.ceil(($(window).width() - img.width) / 2),
                top: (($(window).height() - img.height) / 2) + $(document).scrollTop(),
                height: img.height,
                width: img.width
            }, 400, function () {
                $(this).find('img').fadeIn('fast');
            }
        );


    });

    img.src = url;

}

// plugins
(function(jQuery){

	jQuery.each(['backgroundColor', 'color', 'borderColor'], function(i, attr){
		jQuery.fx.step[attr] = function(fx){
			if (fx.state == 0) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}
			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	function getRGB(color) {
		var result;
		if (color && color.constructor == Array && color.length == 3) return color;
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
            return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
	}

	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);
			if (color != '' && color != 'transparent' || jQuery.nodeName(elem, "body"))	break;
			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	}

})(jQuery);

jQuery.extend( jQuery.easing, {
    def: 'easeOutQuad',
    easeOutQuad: function (x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    }
});

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;
	}
});

