$(document).ready(function() {
	function header_init()
	{
		var logo = document.getElementById('head-logo');
		if(logo)
		{
			if(logo.getContext)
			{
				var radius = 13; //px
				var circle_colors = [
					'rgba(94, 124, 136, .5)',
					'rgba(254, 180, 28, .5)',
					'rgba(54, 63, 69, .5)'
				];
				var circle_coords_x = [ 6, 12, 0 ];
				var circle_coords_y = [ 0, 10, 10 ];
				var ctx = logo.getContext('2d');
				var end_point = ( Math.PI / 180 ) * 360;
				
				for(var i = 0; i < 3; i++)
				{			
					ctx.fillStyle = circle_colors[i];
					ctx.beginPath();
					ctx.arc(radius + circle_coords_x[i], radius + circle_coords_y[i], radius, 0, end_point, false);
					ctx.fill();
					ctx.closePath();
				}
			}
		}
	} // header_init();
	header_init();
	
	var sh_parent = $('.share-widgets .inset-inner');
	var sh_width = sh_parent.width();
	var sh_width_default = sh_width;
	var sh_open = false;
	$('span.share-button').click(function() {
		if(sh_width == sh_width_default)
		{
			sh_open = true;
			sh_parent.animate({
				width: 140
			}, 200, function() {
				sh_width = sh_parent.width();
				sh_parent.find('span.share-button').addClass('expanded');
			});
		}
		else
		{
			sh_parent.animate({
				width: sh_width_default
			}, 200, function() {
				sh_open = false;
				sh_width = sh_parent.width();
				sh_parent.find('span.share-button').removeClass('expanded');
			});
		}
		
	}).hover(
		function() {
			if(!sh_open) {
				sh_parent.animate({
					width: 37
				}, 100);
			}
		},
		function() {
			if(!sh_open)
			{
				sh_parent.animate({
					width: 34
				}, 100);
			}
		}
	);
	
	//
	// Gallery
	//
	$('a.gallery').fancybox({
		openEffect	: 'elastic',
		closeEffect	: 'elastic',
		padding : 5,
		helpers : {
			title : {
				type : 'inside'
			}
		}
	});
	
	//
	// Comments:
	//
	function clear_input(handle, type)
	{
		if(type == 'undefined' || handle.attr('disabled') == 'disabled')
			return;
		if(type == 'input')
		{
			handle.val('');
		}
		if(type == 'textarea')
		{
			handle.text('');
		}
	}
	
	function clear_comment_textarea(handle)
	{
		if(handle.text() == 'Коментар:')
			handle.text('');
		else if(handle.text() == '')
			handle.text('Коментар:');
	}
	//$('#respond #author, #respond #email, #respond #url').bind('focus', function() { clear_input($(this), 'input') });
	$('#respond #comment').bind('focus blur', function() { clear_comment_textarea($(this)) });
});
