var imagethumb = new Array();
var imagepost = new Array();

var entry_id='';
var optionid='';
var nvotes=0;
var countimage=0;
var currentimage=0;

function nextimage(noimageinpanel){

   // var noimageinpanel=6;
    arr1=imagethumb.length;

    document.getElementById('previmage').style.visibility="visible";
    
	var looptime=noimageinpanel;

    countimage+=noimageinpanel;
    //currentimage=countimage;
    if(countimage>=(arr1-3))
    {
       document.getElementById('nextimage').style.visibility="hidden";
    }

 
   document.getElementById('thumbimg_1').src=imagethumb[countimage];

   for(j=1;j<noimageinpanel;j++)
   {

      var elementid="thumbimg_" + (j+1);

      if(countimage>=(arr1-j))
      {		  
         document.getElementById(elementid).style.display="none";
      }
      else
	  {      
         document.getElementById(elementid).src=imagethumb[countimage+j];
      }

   }
    
}

function previmage(noimageinpanel){
//   var divid="imagepost_" + currentimage;
//   var imageid="img_" + currentimage;
//   document.getElementById(divid).style.display="none";
//   document.getElementById(imageid).src="";

//   var noimageinpanel=3;

   document.getElementById('nextimage').style.visibility="visible";;


    countimage-=noimageinpanel;
//  currentimage=countimage;
 //   alert(countimage);
   if(countimage<=0)
   {
      document.getElementById('previmage').style.visibility="hidden";;
   }

   for(j=0;j<noimageinpanel;j++)
   {
      var elementid="thumbimg_" + (j+1);

     document.getElementById(elementid).src=imagethumb[countimage+j];
     document.getElementById(elementid).style.display="block";
   }
   
//   document.getElementById('thumbimg_2').src=imagethumb[countimage+1];
//   document.getElementById('thumbimg_3').src=imagethumb[countimage+2];

//  document.getElementById('thumbimg_2').style.display="block";
//  document.getElementById('thumbimg_3').style.display="block";

//    var divid="imagepost_" + countimage;
//    var imageid="img_" + countimage;
//    document.getElementById(divid).style.display="block";
//    document.getElementById(imageid).src=imagepost[countimage];

}

function changepost(imgno){
//	alert('test1  ' + imgno);
   var divid="imagepost_" + currentimage;
  // alert(divid);
   var imageid="img_" + currentimage;
 //  alert(imageid);
   document.getElementById(divid).style.display="none";
//    alert(document.getElementById(divid).style.display);
   document.getElementById(imageid).src="";
//alert(countimage);
  currentimage=countimage+imgno;

    var divid="imagepost_" + currentimage;
    var imageid="img_" + currentimage;
    document.getElementById(divid).style.display="block";
    document.getElementById(imageid).src=imagepost[currentimage];

}

function addvote(entryid,option,votes){
        //     alert(entryid);
		var serviceurl = "http://www.royalchallengers.com/ee/index.php/misc/votes/" + entryid + "/" + option + "/";
          //  alert(serviceurl);          
           var params = "";	
		postData(serviceurl,params,getvote);

                entry_id=entryid;
                optionid=option;
                nvotes=votes;
}

function getvote(data){
      //  alert(data);
         var divid = "like_" + entry_id +"_" + optionid;


     if(data.indexOf('You voted +1')!=-1){
      //   alert(divid);

         nvotes++;
         document.getElementById(divid).innerHTML=nvotes;
     }
     else if(data.indexOf('You voted -1')!=-1){
    //     alert(divid);

         nvotes++;
         document.getElementById(divid).innerHTML=nvotes;
     }
     else{
     }
}

function addfavorite(entryid,option){
//alert(entryid);
                var inhtml='';
		var serviceurl = "http://www.royalchallengers.com/ee/index.php/misc/favorite_add/" + entryid + "/";
                
                 if(option=='delete'){
                    serviceurl +="delete/"
                    inhtml='<a href="javascript:addfavorite(\''+ entryid+'\',\'add\')" >Add as a favorites</a>';
                 }
                else{
                  inhtml='<a href="javascript:addfavorite(\''+ entryid+'\',\'delete\')" >Remove from favorites</a>';
                }
           //    alert(serviceurl);	
	
                var params = "";	
		postData(serviceurl,params,getfavorite);

               var divid = "fav_" + entryid;
               document.getElementById(divid).innerHTML=inhtml;
                
}
function getfavorite(data){
  // alert(data);
}