/*jslint white: true, browser: true, sub: true, onevar: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */
/*global window, log, $, jQuery */

(function ($) {
    $.fn.kudrassproject = function (options) {
    
        var $imagelist_m = $('#imagelist_m');
        
        $imagelist_m
            .find('a')
            .jqzoom({
                'zoomWidth': 440,
                'zoomHeight': 440,
                'xOffset': 20,
                'title': false,
                'showEffect': 'fadein',
                'fadeinSpeed': 500,
                'fadeoutSpeed': 500
            })
            .end()
            .css('height', '440px');
                
        function build_html () {
            var $ul = $('<ul id="imagelist_s"></ul>');
            $imagelist_m.find('li').each(function (idx) {
                var $li = $('<li><img src="' + $(this).data('small_img_src') + '" alt="" /></li>');
                if (!idx) {
                    $li.addClass('current').css('opacity', 1);
                } else {
                    $li.css('opacity', 0.8);
                }
                $li
                    .click(function () {
                        $imagelist_m.fadeOut(250, function () {
                            $imagelist_m
                                .find('li:eq(0)').css('marginTop', -(idx * 440) + 'px')
                                .end()
                                .fadeIn(250);
                        });
                        
                    })
                    .hover(
                        function () {
                            if (!$(this).hasClass('current')) {
                                $(this).css('opacity', 1);
                            }
                        },
                        function () {
                            if (!$(this).hasClass('current')) {
                                $(this).css('opacity', 0.8);
                            }
                        })
                    .find('img')
                    .fakeBorder();
                $ul.append($li);
            });
            return $ul;
        }
        
        $(this).append(build_html());
        $(this).find('.nav').appendTo('#website');
    };

    $.fn.fakeBorder = function () {
        var that = this;
        if(!is_old_ie) {
            $(window).load(function () {
                return $(that).each(function () {
                    var b = document.createElement('b');
                    $(b).
                        addClass('fakeBorder').
                        css({
                            'width': ($(this).width() -2) + 'px',
                            'height': ($(this).height() - 2) + 'px',
                            'opacity': 0.4
                        });
                    $(this).before(b);
                });
            });
        }
    };
    
}(jQuery));

