function changeImage (url,foto) {
	if (document.getElementById) {
    	//window.alert(foto);    
                document.getElementById('mainphoto').src = url;
                document.getElementById('largephoto').href = foto;
               // photo_id = fotka_id;
        }
        return false;
}

function newWindow(url){
	x = window.open(url, "new_win", "");
	if (x) return false;
}

function ajax(url,idElement){
	if (url != 0){
		if (window.ActiveXObject){
    		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
        else{
			httpRequest = new XMLHttpRequest();
		}
    	httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(idElement); } ;
        httpRequest.send(null);
	}
	else{
		document.getElementById(idElement).innerHTML = "";
	}
	//setTimeout("alert('"+idElement+"')",10);
}

function processRequest(element){
	if (httpRequest.readyState == 4){
		if(httpRequest.status == 200){
			var vystup = document.getElementById(element);
			vystup.innerHTML = httpRequest.responseText;
		}
		else{
			alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
		}
	}
}

// vlozime id prvku jako parametr, pokud je viditelny, skryje se a naopak
function ShowORhidden(prvek){
	if (document.getElementById(prvek).style.display == 'none' || document.getElementById(prvek).style.display == '')
		document.getElementById(prvek).style.display='block';
	else
		document.getElementById(prvek).style.display='none'
}

function setClass(prvek,className){
	$("#"+prvek).addClass(className);
}

function tabs_tooltips(){
	$("#tabs a[title]").tooltip({
		tip: '#bubble', 
		offset: [10, 2],
		effect: 'slide'
	}).dynamic( {
		bottom: {
			direction: 'down',
			bounce: true
		}
	});
}

function animateGrpCars(){
	$("#osobni").hover(function() { $(this).addClass("no-image"); $("#osobni a").css("display","none").addClass("osobni-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#osobni a").removeClass("osobni-h"); });
	$("#uzitkove").hover(function() { $(this).addClass("no-image"); $("#uzitkove a").css("display","none").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#uzitkove a").removeClass("uzitkove-h"); });
	$("#terenni").hover(function() { $(this).addClass("no-image"); $("#terenni a").css("display","none").addClass("terenni-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#terenni a").removeClass("terenni-h"); });
	$("#kombi").hover(function() { $(this).addClass("no-image"); $("#kombi a").css("display","none").addClass("kombi-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#kombi a").removeClass("kombi-h"); });
	$("#mala-auta").hover(function() { $(this).addClass("no-image"); $("#mala-auta a").css("display","none").addClass("mala-auta-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#mala-auta a").removeClass("mala-auta-h"); });
	$("#luxusni").hover(function() { $(this).addClass("no-image"); $("#luxusni a").css("display","none").addClass("luxusni-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#luxusni a").removeClass("luxusni-h"); });
	$("#skoda").hover(function() { $(this).addClass("no-image"); $("#skoda a").css("display","none").addClass("skoda-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#skoda a").removeClass("skoda-h"); });
	$("#vse").hover(function() { $(this).addClass("no-image"); $("#vse a").css("display","none").addClass("vse-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#vse a").removeClass("vse-h"); });
	$("#motorky").hover(function() { $(this).addClass("no-image"); $("#motorky a").css("display","none").addClass("motorky-h").fadeIn(600); }, function() { $(this).removeClass("no-image"); $("#motorky a").removeClass("motorky-h"); });
}

function carBox(){
	$(".carbox").hover(function() {
		$(this).addClass("hover");
	},
	function() {
		$(this).removeClass("hover");
	});
}

function changeImage(id,src){
	$("#carPhoto #carAjax").hide();
	$("#carPhoto .topPhoto").show();
	$("#"+id).hide().attr("src", src).fadeIn(500);
	
	return false;
}

function AddFavorite(linkObj,addUrl,addTitle)
{
  if (document.all && !window.opera)
  {
    window.external.AddFavorite(addUrl,addTitle);
    return false;
  }
  else if (window.opera && window.print)
  {
    linkObj.title = addTitle;
    return true;
  }
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
  {
    if (window.confirm('Přidat oblíbenou stránku jako nový panel?'))
    {
      window.sidebar.addPanel(addTitle,addUrl,'');
      return false;
    }
  }
  window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.');
  return false;
}

function calculateHeightCols(){
	// popis vozidla + info o autobazaru
	if ($("#dealerInfo .border").height() > $("#carInfo .border").height())	$("#carInfo .border").height(  ($("#dealerInfo .border").height())  );
	else																	$("#dealerInfo .border").height(  ($("#carInfo .border").height())  );
	
	// nastaveni odsazeni odkazu pod popisem vozidla v karte vozu
	$(".carDetail").css("margin-top", $("#carInfo .border").height()+50);																
	
	// auto_boxy
	if ($(".halfbox.right").height() > $(".halfbox.left").height())	$(".halfbox.left").height(  ($(".halfbox.right").height())  );
	else															$(".halfbox.right").height(  ($(".halfbox.left").height())  );
}

function ajaxLoadPages(){
	$('.napsat-prodejci a, .email a, .rezervace a, .splatky a').click(function() {
		$("#carPhoto .topPhoto").hide();
		$("#carPhoto #carAjax").load($(this).attr("href")).fadeIn(500);
		return false;
	});
}

function ajaxForm(){
	$("#formulare .sendForm").submit(function(){
		var data = $(":input").serializeArray();
	    
		$.ajax({
			type: "POST",
			url: "/processdata/",
			cache: false, 
			data: data,
			dataType: "html", 
			success: function(data){
				$("#formulare .message").replaceWith(data);
			}
	    });    
	    return false;
	});
}

function showSearchParams(){
	
	// zobrazuje a schovava polozky rozsireneho vyhledavani
	$('#searchParams').click(function() {
		
		if (!$(this).hasClass('selected')){
			$(this).addClass("selected");
			$("#searchParams span").replaceWith("<span>Zobrazit méně parametrů</span>");
			$("#searchEquipment span").replaceWith("<span>Zobrazit výbavu</span>");
			$("#search-ex").fadeIn(500);
			$("#equipment").hide();
			$("#searchEquipment").removeClass("selected");
		}
		else{
			$(this).removeClass("selected");
			$("#searchParams span").replaceWith("<span>Zobrazit více parametrů</span>");
			$("#search-ex").hide();
		}
		
		return false;
	});
	
	// zobrazuje a schovava vybavu ve vyhledavaci
	$('#searchEquipment').click(function() {
		
		if (!$(this).hasClass('selected')){
			$(this).addClass("selected");
			$("#searchEquipment span").replaceWith("<span>Schovat výbavu</span>");
			$("#searchParams span").replaceWith("<span>Zobrazit více parametrů</span>");
			$("#equipment").fadeIn(500);
			$("#search-ex").hide();
			$("#searchParams").removeClass("selected");
		}
		else{
			$(this).removeClass("selected");
			$("#searchEquipment span").replaceWith("<span>Zobrazit výbavu</span>");
			$("#equipment").hide();
		}
		
		return false;
	});

	// meni barvy nazvu polozek pri najeti mysi
	$('#equipment label').mouseover(function() {
		$(this).addClass("hover");
	}).mouseout(function(){
		$(this).removeClass("hover");
    });
    
    // zaklikne nebo odklikne checkbox pri kliknuti na nazev polozky
    $('#equipment label').click(function() {
    	var id = $(this).attr('id');
    	
    	if (!$("#equipment input:checkbox[value=" + id + "]").attr('checked')){
			$("#equipment input:checkbox[value=" + id + "]").attr('checked', 'checked');
			$(this).css('font-weight', 'bold');
		}
		else{
			
			$("#equipment input:checkbox[value=" + id + "]").removeAttr('checked');
			$(this).css('font-weight', 'normal');
		}
	})
}

// GOOGLE MAPS //
function initialize() {
    var latlng = new google.maps.LatLng(49.8,15.472962);
    var myOptions = {
      zoom: 7,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:"Hello World!"
  });   
  
  marker.setMap(map);  
  
  }

