var tabs = new Array();
tabs[0] = 'p1';
tabs[1] = 'p2';
tabs[2] = 'p3';
tabs[3] = 'p4';
tabs[4] = 'p5';

function changeTab(tab) {
	for (var i=0;i<tabs.length;i++) {
		var t = document.getElementById(tabs[i]);
		var tb = document.getElementById(tabs[i]+'b');
		if (tab == tabs[i]) {
			t.className = 'show';
			tb.className = 'active';
		} else {
			t.className = 'hide';
			tb.className = '';
		}
	}
}

function closeWindow() {
    $('#popup').hide().html('');
}

function sendMessage(obj) {
        $('#place').hide();
        $('#load').show();
        $.post('/profil/send_message/'+obj.pid.value,{pyt: obj.pyt.value}, function(result) {
            $('#load').hide();
            $('#place').html(result.html).show();
        }, 'json');
}

$(document).ready(function() {
    changeTab('p1');

    $('#mojejulie').click(function() {
        url = $(this).attr('href') + $(this).attr('rel');
        $.getJSON(url,'', function(result) {
            $('#mojejulie').html(result.html);
            $('#mojejulie').attr('href',result.url);
        });
       return false;
    });

    $('#analiza').click(function() {
        url = $(this).attr('href') + $(this).attr('rel');
        $.getJSON(url,'', function(result) {
            $('#analiza').html(result.html);
            $('#analiza').attr('href',result.url);
        });
       return false;
    });

    $('#message').click(function() {
        $('#popup').html('');
        $(document.createElement("DIV")).attr('id','topbar').appendTo('#popup');
        $(document.createElement("DIV")).attr('id','close').text('X').appendTo('#topbar').bind('click',closeWindow);
        $(document.createElement("DIV")).attr('id','load').appendTo('#popup');
        $(document.createElement("IMG")).attr('src','/media/images/loading.gif').appendTo('#load');
        $(document.createElement("DIV")).text('sending...').appendTo('#load');
        $(document.createElement("DIV")).attr('id','place').attr('name','place').appendTo('#popup');
        $('#popup').show();

        url = $(this).attr('href') + $(this).attr('rel');
        $.getJSON(url,'', function(result) {
            $('#load').hide();
            $('#place').html(result.html).show();
        });
        return false;
    });
});