$(function(){
    var nbt = $(".gal-next");
    var bbt = $(".gal-pre");
    var checkNB = function(x){
        var count = $(".scrollable a").length;
	    var i = parseInt($("a.activeSlide").html())-1;
        if(x){
            i+=x;
            $(".scrollable a:eq("+i+")").click();
	    }else{
    	    $("a.activeSlide").click();
	    }
        bbt[(i>0)?"show":"hide"]();
        nbt[(i<count-1)?"show":"hide"]();
    };
    nbt.click(function(){
        checkNB(1);
        return false;
    });
    bbt.click(function(){
        checkNB(-1);
        return false;
    });
	$("#gallery-view-image2").cycle({
			fx:    'scrollLeft',
			delay: 5000,
			timeout:5000,
			speed: 1000,
			pause: 1,
			cleartypeNoBg : true,
			pager:'.scrollable',
			/*pagerAnchorBuilder:function(i,el){
			    return '<li class="gallery-item-'+(i+1)+'"><a href="#'+i+'"><img src="images/blank.gif" /></a></li>';
				//return '<li class="gallery-item-'+(i+1)+'"><a href="#'+i+'"><img src="images/blank.gif" style="background: url(\''+$(el).attr('alt')+'\') no-repeat center center;"/></a></li>';
			},*/
			after:function(currSlideElement, nextSlideElement, options, forwardFlag){
			    checkNB();
			}
		});
	/*$("#gallery-popup2 div.scrollable").scrollable({
		size: 1,
		items: 'ul'
	});	
	if($("#gallery-popup2 div.scrollable ul li").length<=1)
	    $("#gallery-popup2>a").addClass("disabled");
	*/
	$(".gallery-item-1 a").click();
	checkNB();
});