(function(a){a.fn.center=function(b){var c={top:function(){return window.pageYOffset||document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop;},height:function(){return window.innerHeight||document.documentElement&&document.documentElement.clientHeight||document.body.clientHeight;}};return this.each(function(e){if(e==0){var g=a(this);var d=g.height();var f=c.top()+(c.height()/2)-(d/2);g.css({position:"absolute",marginTop:"0",top:f});}});};})(jQuery);
function Loader(d,c){var e=new Image();var a;e.onload=function(){var h=e.width;var f=e.height;if(h>f){if(h>900){f=f/(h/900);h=900;}}if(f>h){if(f>500){h=h/(f/500);f=500;}}var g=jQuery(c).find(".image");jQuery("#image_window a").attr("href",d.href);g.attr("title",d.title);var i=jQuery('<img src="'+d.src+'" />');i.attr("width",h).attr("height",f).appendTo(g);b(h,f);e.onload=function(){};};e.src=d.src;function b(i,f){var h=i/2;var g=f/6;var g=((f-333))/2;jQuery(c).animate({width:i,height:f+33,marginLeft:-h,marginTop:-g,left:"50%",opacity:1},600,function(){});}}
function Close(){jQuery("#image_overlay, #image_window .terminate").click(function(){jQuery("#image_window").fadeOut("120",function(){jQuery("#image_overlay").fadeOut("60",function(){jQuery("#image_window").remove();jQuery("#image_overlay").remove();});});return false;});}

function showAddHomeworkWindow(url, btn) {
    var win = new Window({className: "nikon",closable:false, minimizable:false, maximizable:false, width:526, height:336});
    win.setAjaxContent(url, {method:"get"}, false, true);
    win.setLocation($(btn.id).cumulativeOffset().top - 255,$(btn.id).cumulativeOffset().left);
    win.setDestroyOnClose();
    win.show();
}

function closeWindow() {
    Windows.closeAll();
}

var photographers =
{
    start : function() {
        this.gallery();
        this.player();
        jQuery('.personal_page a').attr('target', '_blank');
    },

    slider: function($self, id, first) {
        jQuery('#' + id + '-preview .foto img').remove();
        var $title = $self.attr('rel');
        var $name  = $self.attr('title');
        var elem = document.createElement('img');
        elem.src = '/template/image/beta/inspiracje/galery/' + $title;

        elem.onload = function() {
            var height = elem.height;
            var parent = '458';
            var margin = (parent > height) ? ((parent - height) / 2) : 0;
            if (first) {
                jQuery('#' + id + '-preview .foto .name').text($name);
                jQuery('#' + id + '-preview .foto').prepend(elem);
                jQuery(elem).css({marginTop: margin});
            } else {
                elem.className = 'prepend';
                jQuery('#' + id + '-preview .foto .name').text($name);
                jQuery('#' + id + '-preview .foto').prepend(elem);
                jQuery('#' + id + '-preview .foto .prepend').css({marginTop: margin}).fadeIn(600);
            }
            elem.onload = function(){};
        };
    },

    gallery: function() {
        jQuery().ready(function() {
            id = jQuery('.galery-select a:eq(0)').attr('id');
            var $curent = jQuery('#' + id + '-preview .pager li:eq(1) a');
            $curent.parent().addClass('active');
            photographers.slider($curent, id, false);
            jQuery('.fotosection .preview').not(':eq(0)').animate({opacity: 0}, 1, function() { jQuery(this).hide(); });
            jQuery('.galery-select a').not(':eq(0)').animate({opacity: 0.3});
        });

        jQuery('.pager a').bind('click', function() {
            var $title  = null;
            var $name = null;
            var $self = null;
            var block = false;

            if (block == false) {
                if (jQuery(this).is('.special')) {
                    var action  = jQuery(this).parent().attr('class');
                    if (action == 'next') {
                        if (jQuery('.active').is('.last')) {
                            block = true; return false;
                        }
                        var $self = jQuery(this).parents('ul').find('.active').removeClass('active').next();
                        jQuery($self).addClass('active');
                        $self = $self.find('a');
                    }
                    if (action == 'prev') {
                        if (jQuery('.active').is('.first')) {
                            block = true; return false;
                        }
                        var $self = jQuery(this).parents('ul').find('.active').removeClass('active').prev();
                        jQuery($self).addClass('active');
                        $self = $self.find('a');
                    }
                } else {
                    var $self = jQuery(this);
                    jQuery('.pager .active').removeClass('active');
                    jQuery(this).parent().addClass('active');
                }
                if ($self === null) {
                } else {
                    photographers.slider($self, id, false);
                }
            }
            return false;
        });

        jQuery('.galery-select a').bind('click', function() {
            id = jQuery(this).attr('id');
            var ids = '#' + id + '-preview';
            jQuery('.galery-select a').not(id).animate({opacity: 0.3});
            jQuery(this).animate({opacity: 1});
            var $other = jQuery('.fotosection .preview').not(id + '-preview');
            $other.animate({opacity: 0}, 600, function() {
                $other.hide();
            });
            jQuery('.pager .active').removeClass('active');

            jQuery(ids).animate({opacity: 1, height: 529}, 300, function() {
                jQuery(ids).show();
            });
            jQuery(ids + ' .pager li:eq(1)').addClass('active');
            photographers.slider(jQuery(ids + ' .pager li:eq(1) a'), id, true);
            return false;
        });
    },

    player: function() {
        var jsonPlayer = {
            "trzcinski": [{
                year: "2008",
                month: "10",
                video1_file: "/flv/trzcinski_wywiad.flv",
                video2_file: "/flv/trzcinski_praca.flv",
                video1_length: "276",
                video2_length: "27",
                video1_id: "6",
                video2_id: "7"
            }],
            "chara": [{
                year: "2008",
                month: "09",
                video1_file: "/flv/chara_wywiad.flv",
                video2_file: "/flv/chara_praca.flv",
                video1_length: "211",
                video2_length: "40",
                video1_id: "4",
                video2_id: "5"
            }],
            "mlodkowski": [{
                year: "2008",
                month: "11",
                video1_file: "/flv/mlodkowski_wywiad.flv",
                video2_file: "/flv/mlodkowski_praca.flv",
                video1_length: "326",
                video2_length: "31",
                video1_id: "8",
                video2_id: "9"
            }],
            "szurkowski": [{
                year: "2008",
                month: "12",
                video1_file: "/flv/szurkowski_wywiad.flv",
                video2_file: "/flv/szurkowski_praca.flv",
                video1_length: "342",
                video2_length: "87",
                video1_id: "19",
                video2_id: "20"
             }],
            "tomaszewski": [{
                year: "2009",
                month: "01",
                video1_file: "/flv/tomaszewski_wywiad_1.flv",
                video2_file: "/flv/tomaszewski_wywiad_2.flv",
                video3_file: "/flv/tomaszewski_praca.flv",
                video1_length: "265",
                video2_length: "220",
                video3_length: "95",
                video1_id: "21",
                video2_id: "22",
                video3_id: "23"
             }],
            "wieteska": [{
                year: "2009",
                month: "02",
                video1_file: "/flv/wieteska_wywiad.flv",
                video2_file: "/flv/wieteska_praca.flv",
                video1_length: "270",
                video2_length: "36",
                video1_id: "24",
                video2_id: "25"
             }],
            "bosiacki": [{
                year: "2009",
                month: "03",
                video1_file: "/flv/bosiacki_wywiad.flv",
                video2_file: "/flv/bosiacki_praca.flv",
                video1_length: "301",
                video2_length: "21",
                video1_id: "26",
                video2_id: "27"
             }],
            "fajfer": [{
                year: "2009",
                month: "04",
                video1_file: "/flv/fajfer_wywiad.flv",
                video2_file: "/flv/fajfer_praca.flv",
                video1_length: "324",
                video2_length: "54",
                video1_id: "28",
                video2_id: "29"
             }],
            "bielatowicz": [{
                year: "2009",
                month: "05",
                video1_file: "/flv/bielatowicz_wywiad.flv",
                video2_file: "/flv/bielatowicz_praca.flv",
                video1_length: "391",
                video2_length: "22",
                video1_id: "30",
                video2_id: "31"
             }],
            "kobusinski": [{
                year: "2009",
                month: "06",
                video1_file: "/flv/kobusinski_wywiad.flv",
                video2_file: "/flv/kobusinski_praca.flv",
                video1_length: "298",
                video2_length: "33",
                video1_id: "32",
                video2_id: "33"
             }],
             "krajniewski": [{
                 year: "2009",
                 month: "07",
                 video1_file: "/flv/krajniewski_wywiad.flv",
                 video2_file: "/flv/krajniewski_praca.flv",
                 video1_length: "412",
                 video2_length: "23",
                 video1_id: "34",
                 video2_id: "35"
              }],
             "kalamus": [{
                  year: "2009",
                  month: "08",
                  video1_file: "/flv/kalamus_wywiad.flv",
                  video2_file: "/flv/kalamus_praca.flv",
                  video1_length: "366",
                  video2_length: "14",
                  video1_id: "36",
                  video2_id: "37"
               }],
               "sikora": [{
                    year: "2009",
                    month: "09",
                    video1_file: "/flv/sikora_wywiad.flv",
                    video2_file: "/flv/sikora_praca.flv",
                    video1_length: "310",
                    video2_length: "28",
                    video1_id: "38",
                    video2_id: "39"
                 }]
        };
        if (typeof setJsonPlayer  === 'string' && setJsonPlayer != null) {
            var player = eval('jsonPlayer.' + setJsonPlayer)[0];
            if (typeof player === 'object') {
                var so = new SWFObject("/swf/vplayer.swf", "flashszerokikadr", "504", "384", "9", "#000000", true);
                jQuery.each(player, function(key, val){
                    so.addVariable(key, val);
                });
                so.addVariable("userId", playerUserId);
                so.addVariable("gateway", "/cake_gateway.php");
                so.addParam("allowScriptAccess", "always");
                so.addParam("scale", "noscale");
                so.write("flash-szeroki-kadr");
                jQuery.each(jQuery('#player_selection .label'), function(key, val){
                    jQuery(this).click(function(){
                        playVideo(key + 1);
                        return false;
                    })
                });
                jQuery('.contest_title_tomaszewski a').click(function(){
                    playVideo(3);
                });
                jQuery('.contest_title_wieteska a').click(function(){
                    playVideo(2);
                });
                jQuery('.contest_title_bosiacki a').click(function(){
                    playVideo(2);
                });
                jQuery('.contest_fajfer').click(function(){
                    playVideo(2);
                });
                jQuery('.contest_bielatowicz').click(function(){
                    playVideo(2);
                });
                jQuery('.contest_kobusinski').click(function(){
                    playVideo(2);
                });
                jQuery('.contest_sikora').click(function(){
                    playVideo(2);
                });                
            }
        }
    }
}
function initialize() {
    photographers.start();
    
    j("a[rel='lightbox']").click(function() {
        var source = {
            src: j(this).attr('href'),
            'title': 'Kliknij aby zamknąć zdjęcie.'
        };
        var content = j('<div id="image_window" class="wimage"></div>');
        content.append('<div class="content"><a class="image" href="javascript:void(0);" title=""></a></div>');
        content.append('<div class="close"><a class="terminate" href="javascript:void(0);"></a></div>');
        var values = {
            'height' : j('body').height(),
            'width'  : j('body').width()
        };
        j('<div id="image_overlay"></div>').animate({opacity: 0}, 0).prependTo('body').css(values).animate({opacity: 0.6}, 180, function() {
            j(content).animate({opacity: 0}, 0).prependTo('body').animate({opacity: 1}, 260, function() {
                new Loader(source, '#image_window');
                j('#image_window .image').click(function() {
                    j('#image_window').fadeOut('120', function() {
                        j('#image_overlay').fadeOut('60', function() {
                            j('#image_window').remove();
                            j('#image_overlay').remove();
                        });
                    });
                    return false;
                })
                Close();
            }).center();
        });
        return false;
    });
}
jQuery().ready(initialize);


