/*
might improve this script soon
created by zenverse.net
*/
var qv_postimagenum; //no. of post images
var qv_flydelay = 40;
var qv_nextrounddelay = 9000;
var qv_tohide = 1;
var qv_toshow = 2;
var qv_groupid = 'qv_img';
//var qv_spanid = 'qv_text';
var qv_running = false;

//#########################

function qv_gallery_run(rerun) {
if (rerun) {
qv_running = false;
}

if (!qv_running) {
setTimeout("qv_hideit('"+qv_tohide+"','"+qv_toshow+"');",qv_flydelay);
}
qv_running = true;

var zstart;
var zend;
//prepare for next round
switch (qv_postimagenum) {
  case 1:
  zstart = 1;
  zend = 1;
break;
  case 2:
  zstart = qv_toshow;
  zend = qv_tohide;
break;
  default:
  // start default
  zstart = qv_toshow;
  zend = qv_toshow+1;
  if (zend > qv_postimagenum) {
  zend = 1;
  }
  // end default
break;
} //end switch
//alert('hiding '+qv_tohide+', showing '+qv_toshow);
qv_tohide = zstart;
qv_toshow = zend;
}

//#########################

var qv_displacement = 55;
var qv_hide_pos = 0;
var qv_show_pos = 250;

function qv_hideit(id,toshow) {
document.getElementById(qv_groupid+id).style.position = 'relative';

qv_hide_pos = qv_hide_pos+qv_displacement;
document.getElementById(qv_groupid+id).style.left = '-'+qv_hide_pos+'px';

if (qv_hide_pos < 230) {
setTimeout("qv_hideit('"+id+"','"+toshow+"')",qv_flydelay);
} else {
qv_hide_pos = 0;
setTimeout("qv_showit('"+toshow+"','"+id+"')",qv_flydelay);
document.getElementById(qv_groupid+id).style.display = 'none';

document.getElementById(qv_groupid+toshow).style.position = 'relative';
document.getElementById(qv_groupid+toshow).style.left = qv_show_pos+'px';
document.getElementById(qv_groupid+toshow).style.display = 'block';
}
}

//#########################

function qv_showit(id,tohide) {
document.getElementById(qv_groupid+id).style.position = 'relative';

qv_show_pos = qv_show_pos-40;
document.getElementById(qv_groupid+id).style.left = qv_show_pos+'px';

if (qv_show_pos > 0) {
setTimeout("qv_showit('"+id+"','"+tohide+"')",qv_flydelay);
} else {
document.getElementById(qv_groupid+id).style.left = '0px';
qv_show_pos = 250;
setTimeout("qv_gallery_run(true);",qv_nextrounddelay);
}
}


//#########################

function qv_getnumofimages() {

var stopat = 1;
var tryx;
for ( var i=1; i<30; i++ ) {
  try {
    tryx = document.getElementById(qv_groupid+i).innerHTML;
  } catch (e) {
      stopat = i;
      break;
  }
}
qv_postimagenum = stopat-1;

if (qv_postimagenum == 1) {
qv_toshow = 1;
} else {
qv_toshow = 2;
}


if (qv_postimagenum) {

if (qv_postimagenum > 1) {
for (var x=2;x<=qv_postimagenum;x++) {
document.getElementById(qv_groupid+x).style.display = 'none';
//document.getElementById(qv_spanid+x).style.display = 'none';
document.getElementById(qv_groupid+x).style.visibility = 'visible';
//document.getElementById(qv_spanid+x).style.visibility = 'visible';
}
}

setTimeout("qv_gallery_run();",qv_nextrounddelay);
}
}


//#########################

function qv_addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

qv_addLoadEvent(qv_getnumofimages);
