jQuery(document).ready(function(){
	Shadowbox.init({
		players: 		["html", "iframe"],
		initialWidth: 	50,
		initialHeight: 	50,
		language:   	"ro"
	})
	init();
});

function reinit(){
	
	alert(jQuery('sb-content').html());
	
	jQuery("a.bt").click(function(){
		var id_mesaj = jQuery(this).parent().children('p#in_reply_to_status_id').html();
		var mesaj = jQuery(this).parent().children('textarea#status').val();

		alert('AAA');
		/*
		jQuery.ajax({
			type: "POST",
			url: "/twit/raspunde",
			data: "id_mesaj=" + id_mesaj + "&mesaj=" + mesaj,
			success: function(msg) {
		   		if(msg == "ok") {
		   	 		alert("Mesajul a fost trimis.");
		   		}
		   		else {
		   	 		alert("Oooops!\nCeva nu a mers bine!");
		   		}
			}
		});
		*/
	});
	
}

function init(){	
	
	
	jQuery("a.tm_auth").click(function(){
		location.href = "/twit/auth";
	})
	
	jQuery("a.tm_retweet").click(function(){
		var user = jQuery(this).parent().parent().children("div.twt_text").children("span.twt_user").children("a").html();
		var mesaj = "RT @" + user + " " + jQuery(this).parent().parent().children("div.twt_text").children("p.mesaj_ascuns").html();
		//alert(mesaj);		
		jQuery.ajax({
			type: "POST",
			url: "/twit/retweet",
			data: "mesaj="+mesaj,
			success: function(msg) {
		   		if(msg == "ok") {
		   	 		alert("RT-ul tau a fost postat pe Twitter.");
		   		}
		   		else {
		   	 		alert("Oooops!\nCeva nu a mers bine!");
		   		}
			}
		});
	});
	
	jQuery("a.tm_raspunde").click(function(){
		var user = jQuery(this).parent().parent().children("div.twt_text").children("span.twt_user").children("a").html();
		var id_mesaj = jQuery(this).parent().parent().children("div.twt_text").children("p.id_mesaj_ascuns").html();
		var text = "@" + user;
		Shadowbox.open({
	        content:    '/form/' + user + '/' + id_mesaj,
	        player:     "iframe",
	        title:      "",
	        height:     135,
	        width:      426,
	        options: {
	        		onFinish: function(){
	        			reinit();
	        		}
	        }
	    });


	})
	
	jQuery("a.tm_follow").click(function(){
		var user = jQuery(this).parent().parent().children("div.twt_text").children("span.twt_user").children("a").html();
		//var text = "Folowing: " + user;
		jQuery.ajax({
			type: "POST",
			url: "/twit/follow",
			data: "user="+user,
			success: function(msg) {
		   		if(msg == "ok") {
		   	 		alert("Acum urmaresti si utilizatorul " + user + ".");
		   		}
		   		else {
		   	 		alert("Oooops!\nCeva nu a mers bine!");
		   		}
			}
		});
	})
	
	

	
}

