$(document).ready( function() {
	LoadTableIndex();
		
	$('.view_index tr.captions th .show_tooltip').hover ( function () {
		$(this).css('color', '#000000');
		$(this).children('span').show();
	}, function () {
		$(this).css('color', '#FFFFFF');
		$(this).children('span').hide();
	});
	$('table.view_index tr.results').hover ( function () {
		$(this).children('.t_3').css('background', '#C8E7E9');
		$(this).children('.t_4').css('background', '#C8E7E9');
		$(this).children('.t_5').css('background', '#C8E7E9');
		$(this).children('.t_6').css('background', '#C8E7E9');
	}, function () {
		$(this).children('.t_3').css('background', '#CDE9EC');
		$(this).children('.t_4').css('background', '#DAEFF1');
		$(this).children('.t_5').css('background', '#EEF8F8');
		$(this).children('.t_6').css('background', '#FFFFFF');
	});
	$('#header h1').click( function() {
		window.location = '/'+lang+'/index';
	});
	$('.formManager input.query').focus ( function () {
		$(this).css('border', '2px solid #57B6BD');
	});
	$('.formManager input.query').blur ( function () {
		$(this).css('border', '2px solid #FFFFFF');
	});
	$('.formManager textarea').focus ( function () {
		$(this).css('border', '2px solid #57B6BD');
	});
	$('.formManager textarea').blur ( function () {
		$(this).css('border', '2px solid #FFFFFF');
	});
	$('.send-to-friend-link').click( function() {
		var height = $(window).height();
		var height_form = $('.send-to-friend').height();
		$('.send-to-friend').css('margin-top', '-' + (height_form / 2) - 20 + 'px');
		$('.send-to-friend').show();
		$('.send-to-friend .form fieldset').show();
		$('.send-to-friend .form p').hide();
		$('.darker').show();
		return false;
	});
	$('.send-to-friend .close').click( function() {
		$('.send-to-friend').hide();
		$('.darker').hide();
		return false;
	});
	$('.send-to-friend .send').click( function() {	
		var regEmail = /^[A-Za-z0-9\-_]+(\.[A-Za-z0-9\-_]+)*@([A-Za-z0-9\-_\.]+\.)+[A-Za-z]{2,8}$/i;
		var send_to_friend_your_name = $('#send-to-friend-your-name').val();
		var send_to_friend_your_mail = $('#send-to-friend-your-mail').val();
		var send_to_friend_it_mail = $('#send-to-friend-it-mail').val();
		var send_to_friend_message = $('#send-to-friend-message').val();
		var send_to_friend_address = $('#send-to-friend-address').val();
		if 	( 	
				send_to_friend_your_name == '' || 
				send_to_friend_your_mail == '' ||
				send_to_friend_it_mail == '' ||
				send_to_friend_message == '' ||
				send_to_friend_address == ''
			)	{
					alert('Please fill in all fields.');
					return false;
				}
		if ($('#send-to-friend-it-mail').get(0).value.search(regEmail) == -1 || $('#send-to-friend-your-mail').get(0).value.search(regEmail) == -1) {
			alert('Please enter correct email address.');
			return false;
		}
		$.post( send_to_friend_address, { 
			action: 'send_to_friend', 
			send_to_friend_your_name: send_to_friend_your_name,
			send_to_friend_your_mail: send_to_friend_your_mail,
			send_to_friend_it_mail: send_to_friend_it_mail,
			send_to_friend_message: send_to_friend_message,
			send_to_friend_address: send_to_friend_address
		}, function(data) {
			$('.send-to-friend .form fieldset').hide();
			$('.send-to-friend .form p').show();
		});
		return false;
	});
});

function LoadTableIndex () {
	$('.view_index').tablesorter();
	$('.view_index').tablesorter({ sortList: [[1,0]] }); 
	$('tr.results:odd').addClass('t_3');
	$('tr.results:even').addClass('t_4');
	$('.t_4 td').css('background', '#FFFFFF');
	$('.t_4 td:first-child').css('background', '#DAEFF1');
	$('.t_3 td').css('background', '#DAEFF1');
	$('.t_3 td:first-child').css('background', '#CDE9EC');
}
