$(document).ready(function() {
		
	// css improvements
	$('span.phone').html('+420 737 890 715');
	$('span.mail').html('mike.92@seznam.cz');
	$('.cms_item:odd').css('margin-right', '0px');
	$('.cms_show:last').css('margin-bottom', '0px');
	$('.contact_table1 tr:even td').css('background-color', '#ededed');
	$('.contact_table2 tr:even td').css('background-color', '#ededed');
	$('.contact_table3 tr:even td').css('background-color', '#ededed');
	$('.contact_table tr:first-child td').css({'background-color' : '#dfdede', 'font-weight' : 'bold', 'font-size' : '13px', 'color' : '#414141'});
	$('.ref_item:even').css('margin-right', '24px');
	$('.link_r_item_content .ref_item:visible:even').css('margin-right', '32px');
	$('.link_r_item_content .ref_item').css('margin-bottom', '0px');
	
	// QUESTION FORM SUBMIT
	
	$('.question_form').submit(function(ev) {
	ev.preventDefault();
	
	var contact_mail = $("input[name = contact_mail]").val();
	var contact_name = $("input[name = contact_name]").val();
	var contact_question = $("textarea[name = contact_question]").val();
	
	if ((contact_question.length !== 0 ) && (contact_mail.length != 0) ) {
	
		$.post('scripts/contactForm.php', { 'contact_question': contact_question, 'contact_mail': contact_mail, 'contact_name': contact_name }, function(data) { 
					
				$('<div id="form_output"></div>').insertAfter('.question_form').hide();
				$('.question_form').slideUp('slow', function() {
					$('#form_output').html(data).slideDown(1000);
				});
				
		});
	
	} else {
		alert( 'Musíte vyplnit alespoň e-mail a dotaz.' );
	}

	}); // END: question form submit
	
	// contact table hover
	
	$('.contact_table tr').hover(function() {
		$(this).find('td').css('background-color', '#eaf9ff');
	}, function() {
		$(this).find('td').css('background-color', '');
		$('.contact_table1 tr:even td').css('background-color', '#ededed');
		$('.contact_table2 tr:even td').css('background-color', '#ededed');
		$('.contact_table3 tr:even td').css('background-color', '#ededed');
		$('.contact_table tr:first-child td').css({'background-color' : '#dfdede'});
	}); // end: hover
	
	// menu
	
	$('#menu a:first').css('background-image', 'none');
	$('#menu img').not('.selected img').animate({ opacity: 0.5 }, 0)
	$('#menu a').not('.selected').hover(function() {
		var eqOfItem = $(this).attr('rel');
		$(this).find('img').animate({ opacity: 1 }, 'fast')
		var item = $('#holder .menu_item:eq('+(eqOfItem -1)+')');
		item.fadeIn('fast');
	}, function() {
		var eqOfItem = $(this).attr('rel');
		$(this).find('img').animate({ opacity: 0.5 }, 'fast')
		var item = $('#holder .menu_item:eq('+(eqOfItem -1)+')');
		item.fadeOut('fast');	
	});

	function aFunction() {
	
		$('.link_r_item_content .ref_item:eq(' + c_num + ')').hide('slow', function() {
			
			$('.link_r_item_content .ref_item:eq(' + c_num + ')').css('margin-right', '0px');
			
			if(direction == 0) {
				var numToShow = c_num - 2;
			} else {
				numToShow = c_num + 2;
			}
			
					
			$('.link_r_item_content .ref_item:eq(' + numToShow + ')').show('slow', function() {
	
				if(c_num == 2 && direction == 0) {
					direction = 1;
					c_num = -1;
				}
				
				if(c_num == (numOfRefs - 2) && direction == 1) {
					direction = 0;
					c_num = numOfRefs + 1;
				}
				
				if(direction == 0) {
					c_num = c_num - 1;
					
				} else {
					c_num = c_num + 1;
				}
	
				aFunction();
			});
		});
	}
	
	var numOfRefs = $(".link_r_item_content > div").size();
	numOfRefs  = numOfRefs - 2;
	var c_num = numOfRefs;
	var direction = 0;
	
	// reference item hover
	$('.holder').hover(function() {
		$(this).find('.magnifier').fadeIn('fast');
		$(this).find('.light').fadeIn('fast');
	}, function() {
		$(this).find('.magnifier').fadeOut('fast');
		$(this).find('.light').fadeOut('fast');
	});
	
	//$(document).ready(aFunction());
	
});
