$(document).ready(function() 
{
	//taby vpravo
	
	$('#tabs a').click(function(){showTab(this);return false;});
	
	var current_tab = $('#tabs li a:first').attr('id');
	
	function showTab(elem)
	{
		clicked_tab_name = $(elem).attr('id');
		
		$('#'+current_tab).attr('class','');
		$(elem).attr('class','active');
		
		//zobrazenie obsahu
		$('.'+current_tab).hide();
		$('.'+clicked_tab_name).show();
		
		current_tab = clicked_tab_name;
	}
	
	$('#center-tabs a').click(function(){showCenterTab(this);return false;});
	var current_center_tab = $('#center-tabs li a:first').attr('id');
	function showCenterTab(elem)
	{
		clicked_tab_name = $(elem).attr('id');
		
		
		$('#'+current_center_tab).attr('class','');
		$(elem).attr('class','active');
		
		//zobrazenie obsahu
		$('.'+current_center_tab).hide();
		$('.'+clicked_tab_name).show();
		
		current_center_tab = clicked_tab_name;
	}
	
	
	var form_data = $('#poll_form').serializeArray();
	
	//abecedny zoznam firiem
    $('#comp_letter a').click(function(){getCompanyByLetter(this);return false;});
	
	function getCompanyByLetter(elem)
	{
        $.ajax({
            type: "GET",
            url: "/getCompany.php?letter="+$(elem).text(),
            success: function(msg)
            {
                $('#comp_letter_result').html(msg);
            }
        });
    }
    
    //anketa
    $('.poll_vote').click(function(){pollVote(this);return false});
	
	function pollVote(elem)
	{
		var form_data = $('#poll_form').serializeArray();
		$.ajax({
			   type: "GET",
			   url: "/anketa/vote.php",
			   url: $(elem).attr('href'),
			   success: function(msg)
			   {
					$('#poll_form').html(msg);
					$('.poll_vote').unbind();
					$('.poll_vote').click(function(){pollVote(this);return false});
			   }
		   });	
	}
	
	$("a#sendFriend").colorbox({
			width: '550px',
			height: '550px',
			iframe:true,
			opacity: 0.5
	});

});

	jQuery.fn.resizeImg = function()
	{
		var max_width = 80;
		var max_height = 50;
		var heights = '';
		$('#random img').each(function(){
			
			
			if($(this).width() > max_width || $(this).height() > max_height)
			{
				
				width_scale = max_width/$(this).width();
				height_scale = max_height/$(this).height();
				//alert(width_scale);
				
				if(width_scale <  height_scale)
				{
					scale = width_scale;
				}
				else
				{
					scale = height_scale;
				}
				
				new_width = Math.round(scale*$(this).width());
				new_height = Math.round(scale*$(this).height());
				$(this).css('width',new_width+'px');
				$(this).css('height',new_height+'px');
			}
			
			
			
		})
		//alert(heights);
	}
	
	//jQuery.fn.resizeImg();