index_center = {
    config: {
        css: {
            imgFlickCss: {
                'width': '75px',
                'height': '75px'
            },
            flickrBox: "#flickr"
        }
    },
    init: function(){
        this.initFlickr()
    },
    initFlickr: function(){
        parm = {
            tag: 'poznań',
            group: '69862877@N00',
            format: 'json',
            url: '3'
        }
        url = "/proxy.php"
        $.getJSON(url, parm, function(data){
            maxElements = data.items.length - (data.items.length % 8)
            $.each(data.items, function(i, item){
                if (i == maxElements) 
                    return false;
                img = $("<img/>").attr({
                    "src": item.media.m,
                    'alt': item.title + "/" + item.author
                })
                //img.css(index_center.config.css.imgFlickCss)
                $("<a/>").attr({
                    'href': item.link
                }).append(img).appendTo($(index_center.config.css.flickrBox))

            });
        });
    }
}

var href_id = null;
var objid;
var loggedIN = false;
function gogo(objectid){
    //console.log(objectid);
    objid = objectid;
    href_id = objectid.attr('href');
    link_id = href_id.split(',')[0].split('/')[2];
    time_id = href_id.split(',')[1];
    user_id = href_id.split(',')[2];
    if (user_id == 0) {
        t = "Logowanie";
        a = "/login/?modal=true&width=250&height=220";
        g = false;
        tb_show(t, a, g);
    }
    else {
        //http://test.marysia.webd.pl/ide/840,392,2,cec4a5150c7f809c434c6a1981d71342
        $.get(href_id + ",1", null, function(data){
            if (data == "OK") 
                $(objectid).hide();
        });
    }
}

function afterLogin(){
    try {
        if (href_id != null) {
            $.get(href_id + ",1", null, function(data){
                if (data == "OK") {
                    $(objid).hide();
                    window.location = ".";
                }
                else {
                    window.location = ".";
                }
            });
        }
        else {
            window.location = '.';
        }
    } 
    catch (e) {
        window.location = '.';
    }
    tb_remove();
}

$(document).ready(function(){
    index_center.init()
    $(".a-wybieramsie").bind('click', function(){
        gogo($(this));
        return false;
    });
});
