// JavaScript Document
// showslide bottom on item-layout
$(function() {
		  
	    var $galitem = $('#nextpreview').children();
	    // Ð?m các ?nh trong gallery
	    var $galsize = $('#nextpreview ul').size();
	    // Thêm nút Prev và Next vào gallery
	   // $('#nextPreview').append('<div id="galprev">Prev</div><div id="galnext">Next</div>');
	   
	    // ?n t?t c? các ?nh và hi?n ?nh d?u tiên
	    $('#nextpreview ul:gt(0)').hide();
		$currentimg = 0;
		// Thêm id d? phân bi?t riêng t?ng ?nh
	    $galitem.attr("id", function (arr) {
	        return "galleryitem" + arr;
	    });
	     
	    // Thêm s? ki?n click vào nút Prev
    $('#galprev').click(function () { 
			   if ($currentimg > 0) {
				document.getElementById("galnext").style.backgroundPosition="bottom";
	            previmg($currentimg);
	            $currentimg = $currentimg - 1;
				if($currentimg == 0)
					document.getElementById("galprev").style.backgroundPosition="top";
			}
	    });
	    // Thêm s? ki?n click vào nút Next
	    $('#galnext').click(function () {
	        if ($currentimg < $galsize - 1) {
				document.getElementById("galprev").style.backgroundPosition="bottom";
	            nextimg($currentimg, $galsize);
	            $currentimg = $currentimg + 1;
				if($currentimg == $galsize -1)
					document.getElementById("galnext").style.backgroundPosition="top";
			}
	    });
	})
	 
	// Hàm x? lý khi nút Next du?c ?n
	function nextimg($img, $size) {
	    $n_img = $img + 1;
		  if ($n_img < $size) {
	       /* $('#galleryitem' + $img).fadeOut();
	        $('#galleryitem' + $n_img).fadeIn();*/
			 $('#galleryitem' + $img).hide("slow");
	        $('#galleryitem' + $n_img).show("slow");
		 }
				
	}
	// Hàm x? lý khi nút Previous du?c ?n
	function previmg($img) {
	    $p_img = $img - 1;
		if ($p_img >= 0) {
	      	 $('#galleryitem' + $img).hide("slow");
	        $('#galleryitem' + $p_img).show("slow");
	    }
		 
		
	}
