function uutiset() {
  var e = document.getElementById('ajankohtaista');
  if(e) $.getJSON("http://194.79.19.86/autosofta/portals/news38.php?format=json&callback=?",
  {
	c: "PAAKKONE",
  },
  function(response) {
	var l = response.length;
	
	if(l > 1) {
		e.innerHTML = '<h2>Ajankohtaista</h2>' + e.innerHTML;
	}
	
	for(var i = 0; i < l; i++) {
		
		var Parent = document.getElementById("ajankohtaiset");
		var NewLI = document.createElement("li");
		var content = response[i];
		
		//NewLI.setAttribute("class", "sliderImage");
		//NewLI.setAttribute("style", "display: none;");
		//NewLI.setAttribute("onclick", "location.href = 'index.php?p=2&v=" + response[i]["id"] + "'");
		if(content != "") {
			NewLI.innerHTML = content;
			
			Parent.insertBefore(NewLI, Parent.firstChild);
		}
	}
  });
}

function mainos() {
  var e = document.getElementById('mainos');  
  if(e) $.getJSON("http://194.79.19.86/autosofta/portals/mainos38.php?format=json&callback=?",
  {
	c: "PAAKKONE",
  },
  function(response) {
	e.innerHTML=muuta(response);
	
	$('.horizontal_scroller').SetScroller({	velocity: 	 70,
											direction: 	 'horizontal',
											startfrom: 	 'right',
											loop:		 'infinite',
											movetype: 	 'linear',
											onmouseover: 'pause',
											onmouseout:  'play',
											onstartup: 	 'play',
											cursor: 	 'pointer'
										});
  });
}

function lataaSlider() {
  var e = document.getElementById('slider');  

if(e) $.getJSON("http://194.79.19.86/autosofta/portals/ajoneuvontiedot.php?format=json&callback=?",
  {
	c: "PAAKKONE",
  },
  function(response) {
	var l = response.length;
	var position = "top";
	
	for(var i = 0; i < l; i++) {
		
		var Parent = document.getElementById("sliderContent");
		var NewLI = document.createElement("li");
		/*
		if((i % 2) == 0) position = "top";
		else position = "bottom";
		*/
		
		var content = '<img src="' + response[i]["kuva"] + '">'
					+ '<span class="' + position + '" style="display: none;"><table cellspacing="0" cellpadding="0" width="100%"><tr><td width="70%">' + response[i]["merkki"] + ' ' + response[i]["malli"] + ' ' + response[i]["mallitarkenne"] + '</td><td rowspan="2" class="s-hinta">' + response[i]["pyyntihinta"] + '&euro;</td></tr><tr><td>' + response[i]["vuosimalli"] + ', ' + response[i]["km"] + 'km</td></tr></table></span>';
		
		NewLI.setAttribute("class", "sliderImage");
		NewLI.setAttribute("style", "display: none;");
		NewLI.setAttribute("onclick", "location.href = 'index.php?p=2&ty=" + response[i]["ty"] + "&v=" + response[i]["id"] + "'");
		NewLI.innerHTML = content;
		
		Parent.insertBefore(NewLI, Parent.firstChild);
	}
	
	$('#slider').s3Slider({
		timeOut: 4000 
	});
  });
  
}

function muuta(string) {
	var etsi = new Array("\u00a4");
	var korvaa = new Array("&euro;");
	
	for (var i=0; i < etsi.length; i++) {
		var lista = new Array();
		lista = string.split(etsi[i]);
		string = lista.join(korvaa[i]);
	}

	return string;
} 
