$(document).ready(function(){
	var params = {changedEl: "#selectLine",visRows:$("#selectLine").attr("countLines")+1,scrollArrows: true}
	cuSel(params);	
})

function setHighslide(){		
	hs.align = 'center';
	hs.graphicsDir = '../js/highslide/graphics/';
	hs.transitions = ['expand', 'crossfade'];
		
	hs.outlineType = 'glossy-dark';
	hs.wrapperClassName = 'dark';
	hs.fadeInOut = true;
	hs.capture = true;
	hs.dimmingOpacity = 0.75;
	
	hs.registerOverlay({
		html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
		position: 'top right',
		fade: 2 // fading the semi-transparent overlay looks bad in IE
	});
}


function printContent(content){		 
	$(content).jqprint();
	return false;
}


function setGallaryHorizontal(){
		var div = $('#photoMenuHorisontal');
		var ul = $('ul.photoLentaHorisontal');
		
      	$("#scrollRight").click(function(){
			scrollGallery(div,ul,-1);
			return false;
		});
        $("#scrollLeft").click(function(){
		 	scrollGallery(div,ul,+1);
			return false;
		});
		
		$('ul.photoLentaHorisontal li a').bind("click",function(e){
			photo = $(this).attr("photo");
			$('ul.photoLentaHorisontal li a').removeClass("active");
			ifn = this;
			$(this).addClass("active");
			titleImg = this.title!=""?this.title:"&nbsp;";
			currentPhoto = this.nom;
			$("#slideshowContainer img").fadeOut(400,function(e){						
						$("#slideshowContainer img").parent("a").attr("href",ifn);
						$("#slideshowContainer img").css("height","auto").css("width","auto");						
						$("#slideshowContainer img").attr("src",ifn);						
												
						$("#slideshowContainer img").load(function(){
										var im = $("#slideshowContainer img");
										if (im.outerHeight() >= im.outerWidth()) {
											if(im.outerHeight()>387) im.css("height","387px");	
										}else{
											if(im.outerWidth()>633) im.css("width","633px");	
										}
										
										$("#slideshowContainer img").fadeIn("slow");
									}
						);										
			});
	
			return false;
		});
		
		$('ul.photoLentaHorisontal li a:eq(0)').click();
		setHighslide();
}

function scrollGallery(div,ul,step){
	var widthItem = 111;
	var ulPadding = 19;
	
	if(step>0){		
		// toRight
		if(ul[0].offsetLeft>=0) 
			step = 0; 
	}else{
		// toLeft
		var lastLi = $('#lastLi');
//		console.log(lastLi.offset().left);		
//		var lastLi = ul.find('li:last-child');
		var countLi = ul.find('li').length;
		var ulWidth = lastLi.offsetLeft + lastLi.outerWidth();
		var limitLeft = Math.abs(lastLi.offsetLeft-420);
//		if(console) 
//			console.log(ulWidth);
		
		if((lastLi.offset().left) < 937 || countLi<=4) step = 0;
		//if((countLi<=4)) step = 0;
	}	
	
	ul.animate({left: '+='+parseInt(step)*widthItem});
}
