					$(function(){
						$("div.fotogalerieBox").carousel({
							btnsPosition: 'inside',
							autoSlideInterval: 5000,
							loop: false,
							animSpeed: "slower",
							pagination: false,
							direction: "horizontal",
							dispItems: 5,
							autoSlide: false,
							effect: "slide",
							nextBtn: '<img src="/styles/default/btnDalsi.gif" alt="Další" title="Další" class="nextBtn" />',
							prevBtn: '<img src="/styles/default/btnPredchozi.gif" alt="Předchozí" title="Předchozí" class="prevBtn" />'
						});
          	$("a.group").fancybox({
          		'transitionIn'	:	'elastic',
          		'transitionOut'	:	'elastic',
          		'speedIn'		:	600, 
          		'speedOut'		:	200, 
          		'overlayShow'	:	true
          	});
        		$.widget( "ui.combobox", {
        			_create: function() {
        				var self = this,
        					select = this.element.hide(),
        					selected = select.children( ":selected" ),
        					value = selected.val() ? selected.text() : "";
        				var input = $( "<input>" )
        					.insertAfter( select )
        					.val( value )
        					.autocomplete({
        						delay: 0,
        						minLength: 0,
        						source: function( request, response ) {
        							var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
        							response( select.children( "option" ).map(function() {
        								var text = $( this ).text();
        								if ( this.value && ( !request.term || matcher.test(text) ) )
        									return {
        										label: text.replace(
        											new RegExp(
        												"(?![^&;]+;)(?!<[^<>]*)(" +
        												$.ui.autocomplete.escapeRegex(request.term) +
        												")(?![^<>]*>)(?![^&;]+;)", "gi"
        											), "<strong>$1</strong>" ),
        										value: text,
        										option: this
        									};
        							}) );
        						},
        						select: function( event, ui ) {
        							ui.item.option.selected = true;
        							self._trigger( "selected", event, {
        								item: ui.item.option
        							});
        							pos = ui.item.option.value.split("_");
        							id = pos[2];
        							cena = pos[1];
        							tab = pos[3];
        							var lastPrice = $(".helpSelect"+id+"_"+tab).attr("value");
        							$(".selectedPrice"+id+"_"+tab).attr("innerHTML", cena);
        							$(".helpSelect"+id+"_"+tab).attr("value", parseInt(cena));
        							if ($(".over_sale"+id+"_"+tab).attr("value") == 0) {
        							
        							   var finalPrice = parseInt($(".finalPriceInput"+"_"+tab).attr("value"));
                         finalPrice = finalPrice - parseInt(lastPrice);
                         finalPrice = finalPrice + parseInt(cena);
                         $(".finalPrice"+"_"+tab).attr("innerHTML", finalPrice);
                         $(".finalPriceInput"+"_"+tab).attr("value", finalPrice);
                         spocitejProcenta(tab);
                      }
                      else {
                      
                         $(".parc"+id+"_"+tab).attr("value", cena);
                         spocitejProcenta(tab);
                      }
        						},
        						change: function( event, ui ) {
        							if ( !ui.item ) {
        								var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
        									valid = false;
        								select.children( "option" ).each(function() {
        									if ( this.value.match( matcher ) ) {
        										this.selected = valid = true;
        										return false;
        									}
        								});
        								if ( !valid ) {
        									// remove invalid value, as it didn't match anything
        									$( this ).val( "" );
        									select.val( "" );
        									return false;
        								}
        							}
        							alert('test');
        						}
        					})
        					.addClass( "ui-widget ui-widget-content ui-corner-left" );
        
        				input.data( "autocomplete" )._renderItem = function( ul, item ) {
        					return $( "<li></li>" )
        						.data( "item.autocomplete", item )
        						.append( "<a>" + item.label + "</a>" )
        						.appendTo( ul );
        				};
        
        				$( "<button>&nbsp;</button>" )
        					.attr( "tabIndex", -1 )
        					.attr( "title", "Show All Items" )
        					.insertAfter( input )
        					.button({
        						icons: {
        							primary: "ui-icon-triangle-1-s"
        						},
        						text: false
        					})
        					.removeClass( "ui-corner-all" )
        					.addClass( "ui-corner-right ui-button-icon" )
        					.click(function() {
        						// close if already visible
        						if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
        							input.autocomplete( "close" );
        							return false;
        						}
                   
        						// pass empty string as value to search for, displaying all results
        						input.autocomplete( "search", "" );
        						input.focus();
        						return false;
        					});
        			}
        		});
//           	var finalPrice = 0;
        		$("#default-usage-select").selectbox();
        		$( ".combobox" ).combobox();
            $("div.tooltipitem").tooltip();

            spocitejProcenta("tab1");
            spocitejProcenta("tab2");
            spocitejProcenta("tab3");
            setTimeout('addOnClicks();', 100);
});
					
function addOnClicks() {
    $(".btnNezavaznaObjednavka").each(function(cnt, el) {
    	el.onclick = function() {
        	$('.contactForm').slideDown('fast', function() {
        		if(document.location.hash.indexOf('buttons') == -1) {
        			document.location.hash = 'buttons';
        		}
        		$('input[name=userData[company]]').focus();
        	});
        	$("input[name='formType']").attr("value", "Nezávazná poptávka"); 
        	$('.serviceSubmit').html('Odeslat poptávku');
            $('.orderFormDescription').show();
            $('.orderFormRules').hide();
        	$('.orderFormRulesCheckBox').hide();
    	};
    });
    $(".btnObjednat").click(function(){
    	$('.contactForm').slideDown('fast', function() {
    		if(document.location.hash.indexOf('buttons') == -1) {
    			document.location.hash = 'buttons';
    		}
    		$('input[name=userData[company]]').focus();
    	});
    	$("input[name='formType']").attr("value", "Objednávka");
    	$('.serviceSubmit').html('Odeslat objednávku');
    	$('.orderFormDescription').hide();
    	if (window.location.pathname == '/virtualni-servery/') {
        $('.orderFormRules').show();
        $('.orderFormRulesCheckBox').show();
      } else {
        $('.orderFormRules').hide();
        $('.orderFormRulesCheckBox').hide();
      }  
    });
    $("#btnOdeslat").click(function(){
      $("#vimcochci_tab1_form").submit();
    });
}
					
function spocitejProcenta(tab) {

         var inputs = $(".percentage_"+tab);
         var fPriceB = parseFloat($(".finalPriceInput_"+tab).val());
         var fPriceA = fPriceB;
         for (i=0; i<inputs.length; i++) {

             var zmena = (fPriceB / 100) * parseFloat(inputs[i].value);
             if (zmena < 0)
                fPriceA = fPriceA - (zmena*(-1));
             else
                fPriceA = fPriceA + zmena;
         }
         $(".finalPrice_"+tab).attr("innerHTML", Math.round(fPriceA));
}
