// attach links to select box options and set select box value
$(function() {
	var sizeSelect = $('#variants select:last').val();
	var sexSelect = $('#variants select:first').val();

	$('#variants').addClass('a-hidden');
	
	addSexLinks();

	function addSexLinks() {
		var sexId = 'select_' + $('#variants select:first').attr('id');
		var itemCount = 0;
		var sex = '';
		var optLabel = '';

		$('#det-variants').append('<ul id="' + sexId + '" class="sex"></ul>');

		$('#variants select:first option').each(function(){
			optLabel = $(this).attr('label');
			var optVal = $(this).attr('value');

			if (optLabel != '-- vyberte --') {
			 optLabel = optLabel.replace(' ', '');

        if (optLabel == 'Dámské'){
          sex = 'damske';
        } else {
          sex = 'panske';
        }
        
        if ($(this).attr('disabled')) {
          $('#' + sexId).append('<li class="' + sex + '"><span class="disabled">' + optLabel + '<span class="ir"></span></a></li>');
        } else {
          $('#' + sexId).append('<li class="' + sex + '"><a href="#" rel="' + optVal + '" title="' + optLabel + '">' + optLabel + '<span class="ir"></span></a></li>');
        }
			}
		});

		// setup sex select element change...
    $('#' + sexId + ' a').click(function(){
			selectSexId = sexId.replace('select_', '');
			optVal = $(this).attr('rel');

			if ($(this).hasClass('selected')) {
				$(this).removeClass('selected');

				$('#' + selectSexId).val(0);
				$('#' + selectSexId).change();
			} else {
				$(this).parents('ul').find('a').removeClass('selected');
				$('#' + selectSexId).val(optVal);
				$('#' + selectSexId).change();
	
				$(this).addClass('selected');
			}

			addSizeLinks();
			return false;
		});

	}

	
	function addSizeLinks() {
		var sizeId = 'select_' + $('#variants select:last').attr('id');
		if ($('#det-variants ul').length > 1) $('#det-variants ul:last').remove();
		$('#det-variants').append('<ul id="' + sizeId + '" class="size"></ul>');
		$('#variants select:last option').each(function(){
			var disable = 0;
			var optLabel = $(this).attr('label');
			var optVal = $(this).attr('value');
			
			if (optLabel != '-- vyberte --') {
				optLabel = optLabel.replace(' ', '');
				if ($(this).attr('disabled')) { 
					disable = 1;
				}
				if (disable == 1) {
					disable = 0;
				} else {
					$('#' + sizeId).append('<li><a href="#" rel="' + optVal + '">' + optLabel + '</a></li>');

					disable = 0;					
				}
			}
		});
	
		if (sizeSelect > 0) {
			if (!opt) {
				addSexLinks();
				$('a[rel=' + sexSelect +']').addClass('selected');
			}
			$('a[rel=' + sizeSelect +']').addClass('selected');
		}
		
		// setup size select element change...
		$('#' + sizeId + ' a').click(function(){
			selectSizeId = sizeId.replace('select_', '');
			var optVal = $(this).attr('rel');
	
			if ($(this).hasClass('selected')) {
				$(this).removeClass('selected');
				if ($('#det-variants ul').length > 1) $('#det-variants ul:last').remove();
	
				$('#' + selectSizeId).val(0);
				$('#' + selectSizeId).change();
			} else {
				$(this).parents('ul').find('a').removeClass('selected');
				$('#' + selectSizeId).val(optVal);
				$('#' + selectSizeId).change();
	
				$(this).addClass('selected');
			}
	
			return false;
		});
	}

});


$(function() {
    $('.panel_tool_tip').tooltip({
	    track: true,
	    delay: 0,
	    showURL: false,
	    showBody: " - ",
	    opacity: 0.9
    });	 	
    $('.panel_tool_tip img').attr('alt','');
});

$(function() {
    if ($('.form-error').length) {
        $('.form-error a').click(function () {
             var href = $(this).attr('href');
             $(href).focus();
             return false;
         });
     }
});

	$(function(){
		if ($('#w').val() == '') {
			$('#w').val(' vyhledávání ');
		}
		$('#w').click(function(){
		    if ($(this).val() == ' vyhledávání ') {
		    	$(this).val('');
		    }
		});
	});
	
$(function() {
    if ($('.item').length) {
        $('.item').addClass('inactive');
        $('.item').mouseover(function () {
             $(this).removeClass('inactive');
             $(this).addClass('activate');
         })
         .mouseout(function () {
             $(this).addClass('inactive');
             $(this).removeClass('activate');
         });
     }
});
