Cronica = window.Cronica || {};


Cronica.Photo = {
	
	init: function() {

	},

	tabs: function() {
		return j('.view-body-tab-bar > li');
	},
	tab: function(name) {
		return j('.view-body-tab-bar > li.'+name);
	},
	
	view: function(sender) {

		this.tabs().removeClass('selected');
		
		var c = j(sender).attr('class');
		var id = j(sender).attr('name');
	
		
		j('#view .view-body > div').hide();
		
		if (c=='comment-photo') {
			//j('#view .view-body > .'+c).load('/c/forum/photo/'+id);
			j.get('/c/forum/photo/'+id, function(r) {
				j('#view .view-body > .'+c).get(0).innerHTML = r;
			});
		}
		else if (c=='comment-location'){
			// j('#view .view-body > .'+c).load('/c/forum/location/'+id);
			j.get('/c/forum/location/'+id, function(r) {
				j('#view .view-body > .'+c).get(0).innerHTML = r;
			});
		}
		j('#view .view-body > .'+c).show();

		j(sender).addClass('selected');
				
	},
	
	comment: function(type) {
				
		var text	= j('#view .view-body .comment-'+type+' textarea').val();
		
		if (j.trim(text)=='') return;
		
		// var id 		= j('#view .view-body .comment-'+type).attr('name');
		var id 		= j('#view .view-body .comment-photo').attr('name');
		j('#view .view-body .comment-'+type).text('');
										
		j.post('/c/de/forum/post',{
				type: type,
				id: id,
				comment: text 
			}, 
			function() {
				Cronica.Photo.view(j('#view .view-body-tab-bar .comment-'+type));
				var c = parseInt(j('.comment-count-'+type).text());
				c++;
				j('.comment-count-'+type).text(c);
			}
		);
	}
	
};