var curNum=0;
var CurDocument=0;
var wait=200;


var cur_step=0;
var flip_timer=0
var pattern = 	[1,2,1,1,2,1,2,2,1,1,1,1,2,2,2,2];
	pattern	=	[1,1,1,1,2,2,2,2,1,1,2,2,1,1,2,2];
	//pattern	=	[1,2,1,2,1,1,2,1,2,1,2,2,1,2,1,2];
	//pattern =   [1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,2];
	//pattern = 	[1,2,1,2,1,1,1,1,1,2,1,2,1,1,1,1];
	//pattern =	[1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2];
	pattern =	[1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,2];
	pattern = 	[1,2,1,2];
var steps=pattern.length;

function preLoadPicture(pic) {
	heavyImage = new Image(); 
	heavyImage.src = pic;

}

function next_flip(docID,img1,img2,off_x,off_y){
cur_step++;

if (cur_step>steps){
cur_step=1;
}
//confirm(cur_step);
show_img=pattern[cur_step];

if (show_img==2){
document.getElementById(docID).src=img2;

}else{
document.getElementById(docID).src=img1;
}

flip_timer = setTimeout("next_flip('"+docID+"','"+img1+"','"+img2+"','"+off_x+"','"+off_y+"')",wait);

}


function start_flip(docID,img1,img2,speed, off_x,off_y){
clearTimeout(flip_timer);
CurDocument=docID;
wait=speed;
preLoadPicture(img2);
preLoadPicture(img1);
flip_timer = setTimeout("next_flip('"+CurDocument+"','"+img1+"','"+img2+"','"+off_x+"','"+off_y+"')",wait)
}

function stop_flip(){
clearTimeout(flip_timer);
flip_timer="";
}
//here starts the code for calculating a bpm variable

function bpm_to_ms(in_bpm){
return ((240000*(1/4))/(in_bpm))/2;
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


// form validation functions
function input_default(field,text,action){
if (action=="empty"){
if(field.value==""||field.value==text){
field.value="";
}
} else if (action=="fill") {
if (field.value==""){
field.value=text;
}
}
}

function ge(id){
return document.getElementById(id);
}
