﻿var time = 6000;
var default_time = time;
var timeout;
var timeout2;


function addOnloadEvent(){

  if ( typeof window.addEventListener != "undefined" ) {
    window.addEventListener( "load", initTO, false );
  }
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", initTO );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[initTO]();
      };
    }
    else {
      window.onload = initTO;
	}
}
}

// properties (product_desc)



function changePic(way) {
	
	if(document.getElementById("md_ind_slider")) {
		var classname = document.getElementById("md_ind_slider").className;
		//alert(classname);
		var id = Number(classname.replace('opaa',''));
		var divli = document.getElementById("md_ind_slider").getElementsByTagName("div");
		
		if (way = 0) {
			var way = -1;
		} else if (way = 1) {
			var way = 1;
		}
		
		var idN = id + way;
		
		if (id < divli.length) {
			//alert('ok');
			if(document.getElementById('opt'+idN)) {
				document.getElementById("md_ind_slider").className = "opaa" + idN;
				document.getElementById('opt'+id).style.display = 'none';
				document.getElementById('opt'+idN).style.display = '';
				clearTime();
			} else {
				var idN = 1;
				document.getElementById("md_ind_slider").className = "opaa" + idN;
				document.getElementById('opt'+id).style.display = 'none';
				document.getElementById('opt'+idN).style.display = '';
				clearTime();
			}
		} else {
			//alert('nem');
			var idN = 1;
			document.getElementById("md_ind_slider").className = "opaa" + idN;
			document.getElementById('opt'+id).style.display = 'none';
			document.getElementById('opt'+idN).style.display = '';
			clearTime();
		}
	}
}

function hidaAll() {
	if(document.getElementById("md_ind_slider")) {
		var divli = document.getElementById("md_ind_slider").getElementsByTagName("div");
		for(var i=1; i<=divli.length; i++) {
			document.getElementById('opt'+i).style.display = 'none';	
		}
	}
}

function clearTime() {

	clearTimeout(timeout);
	time = 12000;
	timeout = setTimeout("initTO()", time);
}

// properties timeout

function initTO() {
	if(document.getElementById("md_ind_slider")) {
		var classname = document.getElementById("md_ind_slider").className;
		//alert(classname);
		var id = Number(classname.replace('opaa',''));
		//alert(id);
		if (id < 6) {
			
			var idN = id + 1;
			
			//alert(idN);
				if(document.getElementById('opt'+idN)) {
					document.getElementById("md_ind_slider").className = "opaa" + idN;
					document.getElementById('opt'+id).style.display = 'none';
					document.getElementById('opt'+idN).style.display = '';
				} else {
					var idN = 1;
					document.getElementById("md_ind_slider").className = "opaa" + idN;
					document.getElementById('opt'+id).style.display = 'none';
					document.getElementById('opt'+idN).style.display = '';
				}
		} else {
			var idN = 1;
			//alert(idN);
			document.getElementById("md_ind_slider").className = "opaa" + idN;
			document.getElementById('opt'+id).style.display = 'none';
			document.getElementById('opt'+idN).style.display = '';
		}
		
		if(time>default_time) {
			time = default_time;
			clearTimeout(timeout2);
			clearTimeout(timeout);
		}
		
		timeout = setTimeout("initTO()", time);
		
	}
}

//
addOnloadEvent();
