<!-- 
$(document).ready(function()
{
	// Your code here	
	
	/** 
	 * calculates max left position
	 * @param object scrollable_object
	 * @return int 
	 */
	function getMaxLeft(obj)
	{
		var parent_width = parseInt(obj.parent().css('width'));
		if(isNaN(parent_width))
		{
			parent_width = 0;
		}
		
		var obj_width = parseInt(obj.css('width'));
		if(isNaN(obj_width))
		{
			obj_width = 0;
		}
		
		var max_left = obj_width - parent_width;
		return max_left;
	} // end of function getMaxLeft(obj)
	
	
	// manage preporucujemo
	var todays_recommendations = $('ul#todays_recommendations');
	
	// calculate width for todays_recommendations
	var todays_recommendations_width = (todays_recommendations.find('li.lista-clan').length * 162);
	todays_recommendations.css('width', todays_recommendations_width + 'px');
	
	var rec_parent_width 	= parseInt(todays_recommendations.parent().css('width'));
	if(isNaN(rec_parent_width))
	{
		rec_parent_width = 486;
	}
	
	var rec_max_left 		= todays_recommendations_width - rec_parent_width;
	var rec_common_step		= 486;
	
	// handle right_arrow_small
	$('a#right_arrow_small_1').click(function()
	{
		// check num of elements
		if(todays_recommendations.find('li.lista-clan').length < 4)
		{
			return false;
		}
		
		// get current left
		var curr_left = Math.abs(parseInt(todays_recommendations.css('left')));
		
		if(isNaN(curr_left))
		{
			curr_left = 0;
		}
		
		// calculate step
		var step  		= rec_common_step;
		var temp_left 	= curr_left + rec_common_step;
		if(temp_left > rec_max_left)
		{
			//step = temp_left - rec_max_left;
			step = rec_common_step - (temp_left - rec_max_left);
		}
		
		//if((curr_left + step) > rec_max_left)
		if(step == 0)
		{
			// scroll back to beginning - rewind
			todays_recommendations.animate({"left": "0px"}, 200);
		}
		else
		{
			todays_recommendations.animate({"left": "-=" + step + "px"}, 200);
		}
		
		$(this).blur();
		return false;
	});
	
	
	// handle left_arrow_small 
	$('a#left_arrow_small_1').click(function()
	{
		// get current left
		var curr_left = Math.abs(parseInt(todays_recommendations.css('left')));
		if(isNaN(curr_left))
		{
			curr_left = 0;
		}
		
		if(curr_left == 0)
		{
			// just exit
			return false;
		}
		
		// calculate step
		var step  		= rec_common_step;
		var temp_left 	= curr_left + rec_common_step;
		
		if(temp_left > todays_recommendations_width)
		{
			step = temp_left - todays_recommendations_width;
		}
		
		
		//if((todays_recommendations_width - (curr_left + step)) > rec_parent_width)
		if(curr_left < rec_parent_width)
		{
			// scroll back to beginning - rewind
			todays_recommendations.animate({"left": "0px"}, 200);
		}
		else
		{
			todays_recommendations.animate({"left": "+=" + step + "px"}, 200);
		}
		
		$(this).blur();
		return false;
	});
	
	
	// close comment div
	$('div#form-kompletna').hide();
	
	// handle send_comment click
	$('a#send_comment').click(function()
	{
		$('div#form-kompletna').toggle();	
		$(this).blur();
		return false;
 	});
	
	
	// post comments via ajax
	var subm_btn = $('input#submit_btn');
	var comm_frm = $('form#comment_form');
	
	var mail_regexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	subm_btn.click(function()
	{
		var ok = true;
		
		var form_data = {};
		
		// check inputs
		$.each($('input'), function(i, val)
		{
			// trim
			$(this).attr('value', $(this).val().replace(/^[\s]+|[\s]+$/, ''));
			
			if($(this).attr('value') == '')
			{
				alert('Sva polja su obavezna!');
				
				$(this).select();
				$(this).focus();
				
				ok = false;
				
				return false;
			}
			
			// check email is valid
			if($(this).attr('name') == 'email')
			{
				if(!mail_regexp.test($(this).val()))
				{
					alert('Proverite format email adrese!');
					$(this).select();
					$(this).focus();
					
					ok = false;
					return false;
				}
		    }
			
			form_data[$(this).attr('name')] = $(this).val();
		});
		
		
		if(!ok)
		{
			return false;
		}
		
		// check textarea
		var comment_text = $('textarea#comment').val().replace(/^[\s]+|[\s]+$/, '');
		
		if(comment_text == '')
		{
			alert('Sva polja su obavezna!');	
			$('textarea#comment').focus();
			
			return false;
		}
		
		// comment length, should not be more than 500 chars
		if(comment_text.length > 500)
		{
			alert('Komentar je predugacak. Ako zelite mozete ostaviti vise komentara!');
			return false;
		}
		
		$('textarea#comment').val(comment_text);
		
		form_data['comment'] = comment_text;
		form_data['ajax_call'] = 1;
		
		// manage ajax
		$('div#ajax-loader').ajaxStart(function()
		{ 
			$(this).css('visibility', 'visible');
		});
		
		$('div#ajax-loader').ajaxStop(function()
		{ 
			$(this).css('visibility', 'hidden');
		});
		
		// post data
		$.post(document.location.href, form_data, function(data)
		{
			var date = new Date();
			
			if(data == '')
			{
				$('div#ajax-loader').css('visibility', 'hidden');
				alert('Hm, nije kako treba. Refreshujte stranicu i pokusajte ponovo!');
			}
			else
			{
				$('div#ajax-loader').css('visibility', 'hidden');
				alert(data);
				
				if(data.indexOf('Hvala!') != -1)
				{
					$('div#form-kompletna').hide();
				}
			}
			
			// refresh captcha image
			var src = $('img#captcha_img').attr('src') + '?tstmp=' + date.getTime();
			
			$('img#captcha_img').attr('src', src);
			
			return false;
		});
		
		return false;
	});
	
});


function sendLink(ovo)
{
	ovo.href = ovo.href + window.escape(document.title) + '&body=Ciao, naletoh na stranicu: ' + window.escape(document.title) + ' na adresi: ' + window.location.href + ' pa ako te zanima svrati. Pozdrav!';	

	return true;
}


function share(ovo)
{
	var site = ovo.title;
	if(site == '')
	{
		return false;
	}
	
	var url 		= '';
	var local_url	= window.encodeURIComponent(document.location.href);
	var title		= window.encodeURIComponent(document.title);
	
	
	switch(site)
	{	
		case "facebook":
			url = 'http://www.facebook.com/sharer.php?u=' + local_url + '&t=' + title;
			break;
			
			
		case "twitter":
			url = 'http://twitter.com/home?status=Moja+preporuka+' + local_url;
			break;
		
		default:
			break;
	}
	
	if(url != '')
	{
		ovo.href = url;
		return true;
	}
	
	return false;
}
-->
