jQuery.fn.slides = function()
{
    function startSlide()
    {
        var img = imgs.eq(n);

        title.text(img.attr("alt"));
        propLink.attr("href", img.parent().attr("href"));
        img.parent().css('z-index', '5');
        img.animate({opacity:1.0}, {queue:false, duration:500}).
            animate({width:"105%", height:"105%"}, 5000, function(){n = (n < l) ? n + 1 : 0; startSlide()}).
            animate({opacity:0}, 500, function(){img.parent().css('z-index', '0'); img.css({width:selfWidth, height:selfHeight, top:0, left:0})});
    }

    $j('a#slide-prev').click
    (
        function(event)
        {
            var curImg = imgs.eq(n);
            curImg.stop();
            curImg.animate({opacity:0}, 500);
            curImg.parent().css('z-index', '0');

            n = n ? n - 1 : l;

            var prevImg = imgs.eq(n);
            prevImg.animate({opacity:1}, 500);
            prevImg.parent().css('z-index', '5');
            title.text(prevImg.attr("alt"));
            propLink.attr("href", prevImg.parent().attr("href"));

            event.preventDefault();
        }
    )

    $j('a#slide-next').click
    (
        function(event)
        {
            var curImg = imgs.eq(n);
            curImg.stop();
            curImg.animate({opacity:0},500);
            curImg.parent().css('z-index', '0');

            n = (n < l) ? n + 1 : 0;

            var nextImg = imgs.eq(n);
            nextImg.animate({opacity:1},500);
            nextImg.parent().css('z-index', '5');
            title.text(nextImg.attr("alt"));
            propLink.attr("href", nextImg.parent().attr("href"));

            event.preventDefault();
        }
    )

	var self = this,
        selfWidth = this.width(),
        selfHeight = this.height(),

        imgs = self.find('img'),
        l = imgs.length - 1,

        links = self.find('> a'),
        title = self.find('p#title'),

        propLink = self.find('a#prop-link');

    imgs.css({opacity:0});
    links.addClass('slidelink');

    /*var c = 0;
    for (var i = 0; i < imgs.length; i++)
    {
        imgs.eq(i).addClass('pos' + c);
        c = (c < 3) ? c + 1 : 0;
    }*/

    var n = 0;
    startSlide();
}

$j(function()
{
    $j('#vslideshow').slides();
});