/**
 * @author rysiu
 */  
    
var mlekolaki = {
    
	vote_url: 'vote/mkomiks.html/',
	get_news:  'co_nowego/get.html/',
	voted : false,
	
    init: function(domain) 
    {
		this.url = domain;
    },
    
    $: function(id) 
    {
        return document.getElementById(id);
    },
	
	stop : function (url)
	{
		window.location = url;	
	},
	
	set_star : function(points)
	{
		__dir = 'images/layout/m_komiks/points/';
		for(var i = 1; i <= 5; i++)
		{
			__star = this.$('star'+i);
			__star.src = __dir + ( i <= points ? i+'point_on.jpg' : i + 'point_off.jpg');
		}
		this.clear_timer();
	},

	clear_star : function()
	{
		this.timer = window.setTimeout("mlekolaki.clear_star_real()", 400);
	},
	
	clear_star_real : function()
	{
		this.clear_stars();
	},
	
	clear_stars : function()
	{
		__dir = 'images/layout/m_komiks/points/';
		for (var i = 1; i <= 5; i++) {
			__star = this.$('star' + i);
			__star.src = __dir + i + 'point_off.jpg';
		}
	},
	
	clear_timer : function()
	{
		if (this.timer) 
		{
			window.clearTimeout(this.timer);
			this.timer = null;
		}
	},
	
	vote : function(id_comics, points)
	{
		advAJAX.post({
    		url: this.url + this.vote_url,
    		id_comics : id_comics,
			points : points,
    		onSuccess : function(obj) { mlekolaki.voted(obj.responseText); },
    		onError : function(obj) { mlekolaki.voted('fail'); }
		});
	},
	
	voted : function (response)
	{
		this.$('score').className = 'hide';
		
		if(response != 'false')
		{
			this.voted = true;
			this.$('score_thnx').className = 'show';
			this.$('score_pkt').innerHTML = response + ' pkt.';
		}
		else
		{
			this.$('score_error').className = 'show';
		}
	},
	
	getNews : function (id_news)
	{
		advAJAX.post({
    		url: this.url + this.get_news,
    		id : id_news,
    		onSuccess : function(obj) { 
			mlekolaki.showNews(obj.responseText);
			
			},
    		onError : function(obj) { }
		});
		
		return false;
	},
	
	showNews : function (data)
	{
		var $j = jQuery.noConflict();
    
        $j("#current_news").fadeOut("slow", function () { 
        	mlekolaki.$('current_news').innerHTML = data;
			if ( $j.browser.msie && $j.browser.version < 7 ) {
				$j('.current img').ifixpng();
			}
        	$j("#current_news").fadeIn('slow');
        });
        
	}
	
}
