$(document).ready(function(){   
	$(window).load(function () {
		$('#imageBoxWide, #top_slide').show();
	 	$(".menu-category li ul.disabled").hide();
        $('.menu_category_top_l').addClass('active_l');
        $("div.brand").hide();
		
		/********** BEGIN image cycle header **********/	
		$('#imageBoxWide').cycle({
			fx: 'fade', 
			speed:  'slow',
			delay: -4500,  
			speed:   4050
		});
		
		
		$('#imageBoxRight').cycle({
			fx: 'fade', 
			speed:  'slow',
			delay: -4500,  
			speed:   4050
		});
		
		
		/********** END image cycle header **********/	
		
		/********** BEGIN Lightbox init **********/	
			$('#informationLeft a').lightBox();	
		/********** END Lightbox init **********/
		
	});
	
	/********** BEGIN continous scroll **********/	
		$('#foot_up_right .upppp').click(function(e){		
			$.scrollTo( this.hash || 0, 1000);
			e.preventDefault();
		});
	/********** END continous scroll **********/	
		
		
		
		$('.hp.main .showMore, .inactiveWrap').hide();
		$('.tabs [no="tab-1"]').removeClass('inactiveTab');
		$('.tabs [no="tab-1"]').addClass('activeTab');
		var bg;
		var minPrice = 5000;
		var maxPrice = 19000;
		



		$('.tabs li a').click(
		        function () {
					$(this).removeClass('inactiveTab');
					var ct = $(this).parent().parent().find('.activeTab').removeClass('activeTab');
					ct.addClass('inactiveTab');
					$(this).addClass('activeTab');
					var t = $(this).attr('no');
					$('#sliders > div').removeClass('activeWrap');
					$('#sliders > div').addClass('inactiveWrap');
					$('#sliders').find("#"+t).removeClass('inactiveWrap');
					$('.inactiveWrap').hide();
					$('#sliders').find("#"+t).addClass('activeWrap');
					$('.activeWrap').show();
				}
		  	);	
	
	  
	  
	       
});
	

function initSlider(absmin, absmax, min, max){

	$("#slider").slider({
		range: true,
		min: absmin,
		max: absmax,
		values: [min, max],
		slide: function(event, ui) {
			$("#amountMin").val(ui.values[0]);
			$("#amountMax").val(ui.values[1]);
			
		}
	});
	$("#amountMin").val(min);
	$("#amountMax").val(max);
	
};


if (window.ActiveXObject) {
    var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
    var httpRequest = new XMLHttpRequest();
}

function GetKeyCode(e) {
	  if (e) {
	    return e.charCode ? e.charCode : e.keyCode;
	  }
	  else {
	    return window.event.charCode ? window.event.charCode : window.event.keyCode;
	  }
	}
function generujNaseptavac(e) {
  var unicode = GetKeyCode(e);
  var str = document.getElementById("filterKeyword").value;
  if (unicode != 38 && unicode != 40 && unicode != 27 && unicode!= 13) {
    if (str != "") {

      var url = "/ajax.php?method=naseptavac&str=" + encodeURI(str);
     
      httpRequest.open("GET", url);
      httpRequest.onreadystatechange= function () {processRequestNaseptavac(); } ;
      httpRequest.send(null);
    }
    else {
      document.getElementById("naseptavacDiv").innerHTML = "";
    }
  }
}

function posunNaseptavac(e) {
  var unicode = GetKeyCode(e);
  var naseptavac = document.getElementById("naseptavac");
  if(unicode == 27){
	  document.getElementById("naseptavacDiv").innerHTML = "";
  }
  else if (unicode == 40) {
    // šipka dolů
    naseptavac.options.selectedIndex =
      naseptavac.options.selectedIndex >= 0 &&
      naseptavac.options.selectedIndex < naseptavac.options.length-1 ?
      naseptavac.options.selectedIndex+1 : 0;
    getChangeHandler();
    return;
  }
  else if (unicode == 38) {
    // šipka nahoru
    naseptavac.options.selectedIndex =
      naseptavac.options.selectedIndex > 0 ?
      naseptavac.options.selectedIndex-1 : naseptavac.options.length-1;
    getChangeHandler();
    return;
  }
  else if (unicode == 13 && document.getElementById("naseptavacDiv").style.visibility!="hidden" ) {
	  
    lastSelected = document.getElementById("filterKeyword").value;
    // na enter ve textovém poli nechceme odesílat formulář
    if (window.event)
      e.returnValue = false;
    else
      e.preventDefault();
    document.getElementById("naseptavacDiv").style.visibility  = "hidden";
  }
}

function processRequestNaseptavac() {
  if (httpRequest.readyState == 4) {
    if(httpRequest.status == 200) {
      var response = httpRequest.responseText;
    
      if (response == 'EMPTY') {
        document.getElementById("naseptavacDiv").innerHTML = "";
      }
      else {
        document.getElementById("naseptavacDiv").innerHTML = response;

      }
    }
    else {
     // alert("Chyba při načítání stránky"
      //  + httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}

function getChangeHandler() {
  var select = document.getElementById("naseptavac");
  var nazev = select.options[select.selectedIndex].innerHTML;

  document.getElementById("filterKeyword").value = nazev.replace(/\&amp;/g,'&');
}

function getResultClickHandler() {
  getChangeHandler();
  document.getElementById("naseptavacDiv").style.visibility = "hidden";
}

