| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- window.onload = function() {
- var req = new XMLHttpRequest();
- // first add raf shim
- // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
- window.requestAnimFrame = (function(){
- return window.requestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- function( callback ){
- window.setTimeout(callback, 1000 / 60);
- };
- })();
- // main function
- function scrollToY(scrollTargetY, speed, easing) {
- // scrollTargetY: the target scrollY property of the window
- // speed: time in pixels per second
- // easing: easing equation to use
- var scrollY = window.scrollY,
- scrollTargetY = scrollTargetY || 0,
- speed = speed || 2000,
- easing = easing || 'easeOutSine',
- currentTime = 0;
- // min time .1, max time .8 seconds
- var time = Math.max(.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, .8));
- // easing equations from https://github.com/danro/easing-js/blob/master/easing.js
- var PI_D2 = Math.PI / 2,
- easingEquations = {
- easeOutSine: function (pos) {
- return Math.sin(pos * (Math.PI / 2));
- },
- easeInOutSine: function (pos) {
- return (-0.5 * (Math.cos(Math.PI * pos) - 1));
- },
- easeInOutQuint: function (pos) {
- if ((pos /= 0.5) < 1) {
- return 0.5 * Math.pow(pos, 5);
- }
- return 0.5 * (Math.pow((pos - 2), 5) + 2);
- }
- };
- // add animation loop
- function tick() {
- currentTime += 1 / 60;
- var p = currentTime / time;
- var t = easingEquations[easing](p);
- if (p < 1) {
- requestAnimFrame(tick);
- window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t));
- } else {
- console.log('scroll done');
- window.scrollTo(0, scrollTargetY);
- }
- }
- // call it once to get started
- tick();
- }
- var availableWidth = [ 500, 1024, 1400, 1920];
- var size=0;
- var banner=document.getElementById("banner");
- while (window.innerWidth > availableWidth[size] && size < availableWidth.length-1 )
- size++;
- banner.src="Images/slider/slide1-"+availableWidth[size]+".jpg";
- var contact= document.getElementsByClassName("contact");
- var tit_curso = document.getElementsByClassName("titulo_curso");
- var desc_curso = document.getElementsByClassName("descripcion_curso");
- var list = document.getElementsByTagName("li");
- var overlay=document.getElementById('overlay-contact');
- var exit=document.getElementById('exit');
- var basicgrey=document.getElementById('basic-grey');
- var logo=document.getElementById('logo');
- var btnconsulta=document.getElementById('btnconsulta');
- var btnok=document.getElementById('ok');
- function curso_click(){
- for(var j =0; j < desc_curso.length; j++){
- if (desc_curso[j].getAttribute("title") == this.getAttribute("title")) {
- var child = this.firstElementChild;
- if(desc_curso[j].style.display=="block") {
- child.innerHTML = child.innerHTML.replace("-","+");
- desc_curso[j].style.display="none";
- } else {
- child.innerHTML = child.innerHTML.replace("+","-");
- desc_curso[j].style.display="block";
- }
- }
- }
- }
- overlay.onclick = function(){
- overlay.style.display="none";
- basicgrey.style.display="none";
- }
- exit.onclick=function(){
- overlay.style.display="none";
- basicgrey.style.display="none";
- }
- btnok.onclick=function(){
- var params="mail="+document.getElementById("suscribe").value;
- req.open("POST", "newsletter.php", true);
- req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- req.setRequestHeader("Content-length", params.length);
- req.setRequestHeader("Connection", "close");
- req.onreadystatechange=function(){
- if(req.readyState == 4 && req.status == 200)
- document.getElementById("respuestanewsletter").innerHTML=req.responseText;
- }
- req.send(params);
- };
- btnconsulta.onclick=function(){
- var params = "nombre="+document.getElementById("name").value;
- params=params+"&mail="+document.getElementById("email").value;
- params=params+"&consulta="+document.getElementById("message").value;
- req.open("POST", "contacto.php", true);
- req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- req.setRequestHeader("Content-length", params.length);
- req.setRequestHeader("Connection", "close");
- req.onreadystatechange=function(){
- if(req.readyState == 4 && req.status == 200)
- document.getElementById("respuestacontacto").innerHTML=req.responseText;
- }
- req.send(params);
- };
- for(var i =0; i < tit_curso.length; i++)
- tit_curso[i].onclick=curso_click;
- for(var i =0; i < contact.length; i++)
- contact[i].onclick=showContact;
- for(var i =0; i < list.length; i++)
- if(list[i].firstChild.tagName=="A")
- list[i].firstChild.addEventListener("click", function(e) {
- var target=document.getElementById(this.hash.replace("#",""))
- scrollToY(target.offsetTop, 1500, 'easeInOutQuint');
- if (this.hash=='#footer-outer')
- showContact();
- e.preventDefault();
- });
- function showContact() {
- basicgrey.style.display="block";
- overlay.style.display="block";
- }
- var startY=banner.scrollHeight;
- window.onscroll = function () {
- logo.style.opacity=1*(window.pageYOffset > startY ); //bool->int
- };
- var curImg=1;
- setInterval(slide, 8000);
- var distrib;
- if (window.innerWidth <= 890) { //distribuidoras
- var xhr = new XMLHttpRequest();
- xhr.open('GET', encodeURI('lista_distrib.php'));
- xhr.onload = function() {
- if (xhr.status === 200) {
- distrib=JSON.parse(xhr.responseText);
- var sel = document.createElement("select");
- var selProv= document.createElement("select");
- var selZona = document.createElement("select");
- var result= document.createElement("div");
- sel.id="pais";
- selProv.id="prov";
- selZona.id="zona";
- result.id="result";
- for (country in distrib) {
- var opt = document.createElement("option");
- var node = document.createTextNode(country);
- opt.appendChild(node);
- sel.appendChild(opt);
- }
- sel.selectedIndex=-1;
- sel.onchange=changeCountry;
- selProv.onchange=changeProv;
- selZona.onchange=changeZona;
- document.getElementById("distribuidoras").appendChild(sel);
- document.getElementById("distribuidoras").appendChild(selProv);
- document.getElementById("distribuidoras").appendChild(selZona);
- document.getElementById("distribuidoras").appendChild(result);
- }
- else {
- alert('Request failed. Returned status of ' + xhr.status);
- }
- };
- xhr.send();
- }
- function changeCountry() {
- var pais = document.getElementById("pais").value;
- var prov = document.getElementById("prov");
- var zona = document.getElementById("zona");
- zona.innerHTML="";
- prov.innerHTML="";
- if(distrib[pais] == undefined) return;
- for (provincia in distrib[pais]) {
- var opt = document.createElement("option");
- var node = document.createTextNode(provincia);
- opt.appendChild(node);
- prov.appendChild(opt);
- }
- prov.selectedIndex=-1;
- }
- function changeProv() {
- var pais = document.getElementById("pais").value;
- var prov = document.getElementById("prov").value;
- var zona = document.getElementById("zona");
- prov.innerHTML="";
- zona.innerHTML="";
- if(distrib[pais] == undefined || distrib[pais][prov] == undefined) return;
- for (zone in distrib[pais][prov]) {
- var opt = document.createElement("option");
- var node = document.createTextNode(zone);
- opt.appendChild(node);
- zona.appendChild(opt);
- }
- zona.selectedIndex=-1;
- }
- function changeZona() {
- var pais = document.getElementById("pais").value;
- var prov = document.getElementById("prov").value;
- var zona = document.getElementById("zona").value;
- var result = document.getElementById("result");
- result.innerHTML="";
- var z = distrib[pais][prov][zona];
- var text="";
- for (distr in z ) {
- for (p in z[distr]) {
- result.appendChild(document.createTextNode(p+":"+z[distr][p]))
- result.appendChild(document.createElement("br"))
- }
- result.appendChild(document.createElement("br"))
- }
- }
- function slide() {
- banner.className='transp';
- setTimeout(transp, 500);
- curImg++;
- if(curImg>5) curImg=1;
- }
- function transp() {
- banner.src="Images/slider/slide"+curImg+"-"+availableWidth[size]+".jpg";
- banner.removeAttribute('class');
- }
- }
|