﻿var photoCount;
var currentPos=1;
var sID='#smallPic';
var lID='#largePic';
var previewObjId = 'smallObjBl';
var prevBl='.prevbl';
var maxPreviews=4;
var viewPos = currentPos;

function checkCount()
{
    if(photoCount > maxPreviews)
        photoCount = maxPreviews;

}

function getActivePhoto()
{

    return currentPos;

}

function NextPhoto(pos)
{
    $(lID+currentPos).hide();
    UnDecorateActive();
    if(currentPos >= photoCount)
        {
            currentPos = 0;
            newcycle();    
        }
        
    currentPos++;
    DecorateActive();
    $(lID+currentPos).show();


}

function openByPreview(pos)
{
    $(lID+currentPos).hide();
    UnDecorateActive();
    currentPos = pos;
    DecorateActive();
    $(lID+currentPos).show();
}

function UnDecorateActive()
{
    pos = currentPos;
    $(sID+pos).css({'border':'none'});

}

function DecorateActive()
{
    pos= currentPos;
    
    $(sID+pos).css({'border':'2px solid White'});
    showHideObjects();


}

function showHideObjects()
{   

    if(photoCount > maxPreviews)
    {
       if(currentPos > maxPreviews)
       {
        //code 
        var res=currentPos;
        res-=maxPreviews;
        
     //   while(res > maxPreviews)
      //      res-=maxPreviews;
            
         
        
        objlist=$(prevBl);
        
        objlist.hide();
        
//        for(i=0; i < objlist.length && i < res; ++i)
//        {
//            objlist.eq(i).hide();

//        }
                
        for(i=res; i < objlist.length && i < res+maxPreviews; ++i)
        {
                objlist.eq(i).show();
            
        }
      }          
    }
 }
 
 
 function newcycle()
 {
    objlist = $(prevBl);
    
    $(objlist).hide();
    
    for(i=0; i <= objlist.length && i <maxPreviews ; ++i)
    {
       $(objlist).eq(i).show();
    
    }
 
 
 }

$(document).ready(function(){




    /*        qc=$('.jcenter').length;
            for(i=0; i != qc ; ++i)
            {
                $('.prevbl').eq(i).show();
                height = $('.jcenter').eq(i).height();
                if(i > 7)
                  $('.prevbl').eq(i).hide();
                margin= (76 - height)/2;
                if(margin > 0)
                    $('.jcenter').eq(i).css("margin-top",margin+"px");

            }

          


    DecorateActive();*/

});


function Arrs(direction)
{
    
     var div_class= "prevbl";
    first_obj=$("."+div_class+":visible:first");
    last_obj=$("."+div_class+":visible:last");
    

    if(direction)
    {
    
        if(last_obj.next().hasClass(div_class))
        {
            first_obj.hide();
            last_obj.next().show();
           
        }
        else
        {
            $("."+div_class).hide();
            for(i=0; i < maxPreviews; ++i)
                $("."+div_class).eq(i).show();
        }
    }
    else
    {
        if(first_obj.prev().hasClass(div_class))
        {
            last_obj.hide();
            first_obj.prev().show();
           
        }
        else
        {
            $("."+div_class).hide();
            count= $('.'+div_class).length;
            
            for(i=count; i>=0 && i >= count - maxPreviews; --i)
                $('.'+div_class).eq(i).show();
        }
    }
    

}

