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

//- 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;

}

