var comments_loader = {

	site_code : '',
	page_code : '',
	page_title : '',
	page_colors : '',
	container_id : '',
		
	load_comments : function()
	{
		var comments_block = document.getElementById(comments_loader.container_id);
		if (comments_block)
		{
			var iframe = document.createElement('iframe');
			if (iframe)
			{
				var b_location = String(document.location);
				var dl = b_location.indexOf('#');
				if (dl > 0) b_location = b_location.substring(0, dl);

				iframe.setAttribute('src', 'http://comments.li.ru/client/index.php?s=comments&ev=listing&site_code=' + encodeURIComponent(comments_loader.site_code) + '&page_code=' + encodeURIComponent(comments_loader.page_code) + '&page_url=' + encodeURIComponent(b_location) + '&page_title=' + encodeURIComponent(comments_loader.page_title) + (comments_loader.page_colors ? '&colors=' + encodeURIComponent(comments_loader.page_colors) : ''));
				iframe.setAttribute('style', 'position: relative; width: 100%; height: 100%; border: 0px; margin: 0px; padding: 0px');

				var ua = navigator.userAgent.toLowerCase();
				var is_ie = ((ua.indexOf("msie") != -1) && ((ua.indexOf("opera") == -1) || (!window.opera)));
				if (is_ie)
				{
					iframe.frameBorder = 'no';
					iframe.border = '0';
					iframe.style.width = '100%';
					iframe.style.height = '100%';
					iframe.style.margin = '0px 16px 16px 0px';
				}

				comments_block.appendChild(iframe);
			}
		}
	},
	
	init : function(container_id, site_code, page_code, page_title)
	{
		if (container_id && site_code)
		{
			comments_loader.container_id = container_id;
			comments_loader.site_code = site_code;
			comments_loader.page_code = (page_code ? page_code : 0);
			comments_loader.page_title = (page_title ? page_title : String(document.title));
			window.attachEvent ? window.attachEvent('onload', comments_loader.load_comments) : window.addEventListener('load', comments_loader.load_comments, false);
		}
	},

	colors : function(colors)
	{
		var scheme = '';

		for (var name in colors)
		{
			var part = '';

			for (var prop in colors[name])
			{
				if (part) part += ',';
				part += prop + ':' + colors[name][prop]; 
			}

			if (scheme) scheme += ',';
			scheme += name + ':{'+ part + '}';
		}
		comments_loader.page_colors = scheme;
	}

};

var counters_loader = {

	site_code : '',

	load_counters : function()
	{
		var images = document.images;
		for (var i = 0, j = images.length; i < j; i++)
		{
			var image = images[i];
			var page_url = image.getAttribute('page_url');
			var page_code = image.getAttribute('page_code');
			
			if (page_url)
			{
				image.setAttribute('src', 'http://comments.li.ru/client/counters.php?site_code=' + encodeURIComponent(counters_loader.site_code) + '&page_url=' + encodeURIComponent(page_url));

			} else if (page_code)
			{
				image.setAttribute('src', 'http://comments.li.ru/client/counters.php?site_code=' + encodeURIComponent(counters_loader.site_code) + '&page_code=' + encodeURIComponent(page_code));
			}
		}
	},

	init : function(site_code)
	{
		counters_loader.site_code = site_code;
		window.attachEvent ? window.attachEvent('onload', counters_loader.load_counters) : window.addEventListener('load', counters_loader.load_counters, false);
	}
};


