var vimg=[];var poscrt=1,preposcrt=1,nrtot=0;
var imgcrt=null;
$(document).ready(function(){
     nrtot=$('.cimgi').length;if(nrtot>1)$('#ctnav').css({'visibility':'visible'});
     function rsz(newimg){// constraint by width
	    var wrez=0.01,hrez=0.01,w0=0,h0=0,rap=0.01,wdat=580;
        w0=newimg.width;h0=newimg.height;rap=w0/h0;
		if(w0 >= wdat){wrez=wdat;hrez=Math.round(wrez/rap);}
		else{wrez=w0;hrez=h0;}
		newimg.width=wrez;newimg.height=hrez;
     }

    $('.ccp').click(function(){
       var pos=$(document).scrollTop();
       var href=$(this).attr('href');
       $(this).attr('href',href+"&pos="+pos);
    });
    $(document).scrollTop(pagpos);
    /*function fpreload(){
	  var newimg=null;nrtot=vimgsrc.length-1;
	  for(var i=1;i<=nrtot;i++){newimg=new Image();newimg.src=vimgsrc[i];rsz(newimg);vimg[i]=newimg;}
	}*/
    //fpreload();
    //$('#ph').css({'width':vimg[1].width+'px','height':vimg[1].height+'px'});$('#ph').attr('src',vimgsrc[1]);
    $('.caph').click(function(){
        //fpreload()
        preposcrt=poscrt;
		var href=$(this).attr('href');poscrt=href;
        
		//var newimg=new Image();newimg.src=vimgsrc[poscrt];
         //$(newimg).attr('src',vimgsrc[poscrt])
        /*var w0=newimg.width,h0=newimg.height,rap=w0/h0,wdat=580,wrez=0.01,hrez=0.01;
		if(w0 >= wdat){wrez=wdat;hrez=Math.round(wrez/rap);}
		else{wrez=w0;hrez=h0;}
		newimg.width=wrez;newimg.height=hrez;*/
        //alert(newimg.width);
        //$('#ph').css({'width':vimg[poscrt].width+'px','height':vimg[poscrt].height+'px'});$('#ph').attr('src',vimgsrc[poscrt]);
        //$('#ph').css({'width':newimg.width+'px','height':newimg.height+'px'});
        $("#ctimg").height($('#im'+preposcrt).height());
		$('#im'+preposcrt).fadeOut("slow",function(){$('#im'+poscrt).fadeIn("slow");});
		$("#ctimg").height($('#im'+poscrt).height());
		//if($('#im'+poscrt).width()>580)$('#im'+poscrt).width(580);
        $('.caph').css({'font-weight':'normal','color':'#000000'})
        $(this).css({'font-weight':'bold','color':'#c73831'})
        return false;
    });
    //if(vimgsrc.length > 2 )$('#ctnav').css({'visibility':'visible'});
    $('.cnext').click(function(){
        if(poscrt==nrtot){poscrt=1;preposcrt=nrtot;}else{if(poscrt<nrtot){preposcrt=poscrt;poscrt++;}}
        //$('#ph').css({'width':vimg[poscrt].width+'px','height':vimg[poscrt].height+'px'});$('#ph').attr('src',vimgsrc[poscrt]);
        $("#ctimg").height($('#im'+preposcrt).height());
		$('#im'+preposcrt).fadeOut("slow",function(){$('#im'+poscrt).fadeIn("slow");});
		$("#ctimg").height($('#im'+poscrt).height());
		
		//$('.cimgi').hide();if($('#im'+poscrt).width()>580)$('#im'+poscrt).width(580);$('#im'+poscrt).show();
        $('.caph').css({'font-weight':'normal','color':'#000000'})
        $('.caph').each(function(){if($(this).attr('href')==poscrt+''){$(this).css({'font-weight':'bold','color':'#c73831'})}})
        
        return false;
    })
    $('.cprev').click(function(){
        if(poscrt==1){preposcrt=1;poscrt=nrtot;}else{if(poscrt>1){preposcrt=poscrt;poscrt--;}}
        //$('.cimgi').hide();if($('#im'+poscrt).width()>580)$('#im'+poscrt).width(580);$('#im'+poscrt).show();
        //$('#ph').css({'width':vimg[poscrt].width+'px','height':vimg[poscrt].height+'px'});$('#ph').attr('src',vimgsrc[poscrt]);
        $("#ctimg").height($('#im'+preposcrt).height());
		$('#im'+preposcrt).fadeOut("slow",function(){$('#im'+poscrt).fadeIn("slow");});
		$("#ctimg").height($('#im'+poscrt).height());
        $('.caph').css({'font-weight':'normal','color':'#000000'})
        $('.caph').each(function(){if($(this).attr('href')==poscrt+''){$(this).css({'font-weight':'bold','color':'#c73831'})}})
        return false;
    })
})