//funkce pro odstranéní / vrácení hodnoty po kliku na input
function make_empty_input(jquery_selector, css)
{
 input = $(jquery_selector);
 input.bind('blur focus', function() {
  //prohodit hodnoty
  if (this.value == this.title) {
   this.value = '';
   if (css) {
    $(this).css('text-align', 'left');
   }
  } 
  else if (this.value == '') {
   this.value = this.title;
   if (css) {
	$(this).css('text-align', 'center');
   }
  }
   
 });
}

//skrýt dodací adresu
function hide_daddreess(checked)
{
 if (checked) {
  $('#daddreess_block').slideUp();
 }
 else {
  $('#daddreess_block').slideDown();
 }
}

//změna zmemé pro doručení
function change_country_del(country_id)
{
	$('#country_del').attr('innerHTML', countries[country_id]);
	$('#country_del').attr('innerText', countries[country_id]);
}

/**
 * Ajaxové zpracování variant
 */

//callback funkce po zpracování variant
function combinations_set()
{
	combinations_images_fancybox();
	combinations_set_click();
    /*$('#product').css('opacity', '1');
    $('#product').css('-ms-filter', '"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"');
    $('#product').css('filter', 'alpha(opacity=100)');*/
}

//fancybox obrázkům
function combinations_images_fancybox()
{
	//obrázky otevírat do fancyboxu
	$("a.image").fancybox({transitionIn		: 'elastic',
		                   transitionOut	: 'elastic'
	});
}

//nastavení radio buttonům funkci odeslání
function combinations_set_click()
{
	$("#combinations_table input").change(function() {
	 $("#combinations_form").submit();
	});
	
	/*
	//odeslat formulář po zvolení varianty
	$(".combinations_row input").change(function() {
	 $("#combinations_form").submit();
	});*/
}

//dokument ready
$(document).ready(function(){
	//odstranění popisků z inputů
	make_empty_input('#top_login', true);
	make_empty_input('#search_box_value', true);
	make_empty_input('#newsletter input[name=jmeno]', false);
	make_empty_input('#newsletter input[name=prijmeni]', false);
	
	//levé menu
	$('.menu_left_top').hover(function() {
		$(this).children('.sub_menu').css('display', 'block');
 	 },
 	 function() {
 		$(this).children('.sub_menu').css('display', 'none');
 	 });
 	 
	
    //fancybox obrázkům
    combinations_images_fancybox();
	
	//odeslat formulář po zvolení varianty
	combinations_set_click();

	$("#add_to_basket_disabled").click(function() {
		$("#combinations_table").effect("highlight", {}, 3000);
	});
	
	$("#products_control input").change(function() {
		$("#products_control").submit();
	});
	
	//parametry ajaxem
	$("#combinations_form").submit(function() {
     /*$('#product').css('opacity', '0.3');
     $('#product').css('-ms-filter', '"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"');
     $('#product').css('filter', 'alpha(opacity=30)');*/
        
     $(this).ajaxRequest($(this).formGetParsedValues(), {processor: 'combinations'});
	 return false;	
	})

})
