var Response = {
	current : 0,
	total	: 0,
	init:function(){
		this.current = responseState['current'];
		this.total = responseState['total'];
		
		$('#response-next').click(function(){
			Response.goNext()
		});
		$('#response-prev').click(function(){
			Response.goPrev()
		});
	},
	goPrev : function(){		
		if (this.current>0){			
			this.current--;
			this.loadData();
		} else {
			this.current = this.total-1;
			this.loadData();		
		}	
	},
	goNext : function(){		
		if (this.current<this.total-1){			
			this.current++;
			this.loadData();
		} else {
			this.current = 0;
			this.loadData();
		}		
	},
	setData : function(data) {
		$('#response-name').attr('href', data.link);
		$('#response-name').html(data.name);
		$('#response-text').html(data.text);		
		$('#response-photo').attr('src', data.photo);
	},
	loadData : function(){
		$('#response-photo').attr('src', '/common/preloaders/white_circle_big.gif');
		jQuery.get('/', {
			mode	: 'front-gateway',
			module	: 'copyright_market',
			controller: 'api',
			action	: 'get_response',
			format	: 'json',
			key		: this.current
		}, function(result) {
			if (result.success){
				Response.setData(result.data);
			} else {
				alert(result.errors[0]);
			}
		}, 'json');
	}
	
}

$(document).ready(function(){ 	
 	Response.init();
});
