$(document).ready(function(){
  
  var slidetimer = 6000;
  var slideint;
  var b=0;
  var c=0;
  var loopnum = 0;
  var slideon = 1;
  var images = new Array(
    '<img src="images/slide/slide_1.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />',
    '<img src="images/slide/slide_2.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />',
    '<img src="images/slide/slide_3.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />',
    '<img src="images/slide/slide_4.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />',
    '<img src="images/slide/slide_5.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />',
    '<img src="images/slide/slide_6.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />',
    '<img src="images/slide/slide_7.jpg" width="730" height="296" title="printernet.gr" alt="printernet.gr" />'
  );

  startslideshow();

  function startslideshow() {
    if ($("#slideshow").length != 0) {
      if (b < (images.length) - 1) { b = b+1; } else { b = 0; loopnum++; }
      slideint = setInterval(function() { imgToLoad(b); }, slidetimer);
    }
  }
  /*
  $('.sl1').click(function() {
    if (slideon == 1) { clearInterval(slideint); slideon = 0; }
    if (slideon == 0) { startslideshow(); slideon = 1; }
  });
  $('.sl2').click(function() {
    if (slideon == 1) { clearInterval(slideint); slideon = 0; }
    if (slideon == 0) { startslideshow(); slideon = 1; }
  });
  */
  function imgToLoad(b) {
  
    if (images.length%2 && loopnum%2) {
      if (b%2) { var toin = '.sl1'; var toout = '.sl2'; } else { toin = '.sl2'; var toout = '.sl1' };
    } else {
      if (b%2) { var toin = '.sl2'; var toout = '.sl1'; } else { toin = '.sl1'; var toout = '.sl2' };
    }
    
    if (b < (images.length) - 1) { c = b+1; } else { c =0; }
    $(toout).fadeOut(1000, function (){ 
        $(toout).html(images[c]);
      });
    $(toin).fadeIn(1000);
    clearInterval(slideint);
    startslideshow();
  }
});
