﻿var time = 6000;
var default_time = time;
var timeout;
var timeout2;


function addOnloadEvent(){

  if ( typeof window.addEventListener != "undefined" ) {
    window.addEventListener( "load", initUl, false );
    window.addEventListener( "load", initTO, false );
  }
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", initUl );
    window.attachEvent( "onload", initTO );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[initUl]();
        window[initTO]();
      };
    }
    else {
      window.onload = initUl;
      window.onload = initTO;
	}
}
}

// properties (product_desc)



function initUl() {
	
	if(document.getElementById("propul")) {
		var divli = document.getElementById("propul").getElementsByTagName("li");
		
		
		for(var i=0; i<divli.length; i++) {
			divli.item(i).data_id = i+1; 
			divli.item(i).onclick = function() {
				var id = this.data_id;
				if(document.getElementById('opt'+id)) {
					this.parentNode.className = "opaa" + id;
					
					// document.getElementById('opt'+akt).style.display = 'none';
					hidaAll();
					document.getElementById('opt'+id).style.display = '';
					
					clearTime();
				};
			};
		};
	}
}

function hidaAll() {
	if(document.getElementById("propul")) {
		var divli = document.getElementById("propul").getElementsByTagName("li");
		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 (product_desc)

function initTO() {
	if(document.getElementById("propul")) {
		var classname = document.getElementById("propul").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("propul").className = "opaa" + idN;
					document.getElementById('opt'+id).style.display = 'none';
					document.getElementById('opt'+idN).style.display = '';
				} else {
					var idN = 1;
					document.getElementById("propul").className = "opaa" + idN;
					document.getElementById('opt'+id).style.display = 'none';
					document.getElementById('opt'+idN).style.display = '';
				}
		} else {
			var idN = 1;
			//alert(idN);
			document.getElementById("propul").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();