var imgPath = "/images/template/home/photo";
var logoPath = "/images/template/home/logo";
var imgspeed = 700;
var imgtimeout = 6000;

$(document).ready( function(){	
  var elements = $("#imagefade").children();
  var producttype;
  if (elements.length > 1) {
    for (var i = 0; i < elements.length; i++) {
     $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
    };
    $(elements[0]).show();
    nextimage = function(elements, current, last) {
      producttype = $(elements[current])[0].className;
      $(elements[last]).fadeOut(imgspeed);
      $(elements[current]).fadeIn(imgspeed, function() {	removeFilter($(this)[0]); });
      if ((current + 1) < elements.length) {
         current = current + 1;
         last = current - 1;
      } else {
         current = 0;
         last = elements.length - 1;
      }						
  		$('#productname').html('<a href="http://www.metrological.com/node/products/' + products[producttype][0] + '/" style="color: #ffffff;">' + products[producttype][5] + '</a>');
  		$('#description').html(products[producttype][1]);
  		if (!products[producttype][2]) {
  		   $('#new').css('position', 'absolute').fadeOut(imgspeed);
  	    } else {
  		   $('#new').css('position', 'absolute').fadeIn(imgspeed, function() { removeFilter($(this)[0]); });
  		}
      if (!products[producttype][3]){
        $('#rohs').css('position', 'absolute').fadeOut(imgspeed);
      } else {
        $('#rohs').css('position', 'absolute').fadeIn(imgspeed, function() {	removeFilter($(this)[0]); });
      }			
      if (products[producttype][4] == null) {
        $('#logos').html("");
      } else {
        $('#logos').html("<img src='"+logoPath+"/"+products[producttype][4]+"' alt=''  />");
      }	
      setTimeout(function() {
        nextimage(elements, current, last);
      }, imgtimeout);	
    }
    nextimage (elements, 0, elements.length-1);
  }	
});
