$(function(){
    var gview=$("#gallery-view");
    var gviewimg=$("#gallery-view-image");
    var c=0;
    var active=null;
    gviewimg.append($("h6",gviewimg).clone(true));
	gviewimg.append($("b",gviewimg).clone(true));
	gviewimg.append($("img",gviewimg).clone(true));
	$("h6:eq("+c+"),b:eq("+c+"),img:eq("+c+")",gview).hide();
	
    $("#gallery-popup div.scrollable").scrollable({
		size: 3,
		items: 'ul'
	});	
	if($("#gallery-popup div.scrollable ul li").length<=3)
	    $("#gallery-popup>a").addClass("disabled");
	$("#gallery-popup div.scrollable ul li>a").each(function(){
	    var href="javascript:void('"+$(this).attr("href")+"');";
	    $(this).attr("href",href);
	});
	var xfunc=function(){
	    active=$(this).parent();
	    $("h6:eq("+c+")",gview).html($("h6",active).html());
	    //$("b:eq("+c+")",gview).html($("img",this).attr("title"));
	    $("img:eq("+c+")",gview).css("background-image","url("+$(this).attr("href").replace("javascript:void('","").replace("');","")+")");
	    
	    $("h6:eq("+c+"),b:eq("+c+"),img:eq("+c+")",gview).fadeIn(1000);
	    c=1-c;
	    $("h6:eq("+c+"),b:eq("+c+"),img:eq("+c+")",gview).fadeOut(1000);
	    
	    $("a.prev",gview).css("visibility",(active.prev().length>0)?"visible":"hidden");
	    $("a.next",gview).css("visibility",(active.next().length>0)?"visible":"hidden");
	    return true;
	};
	$("#gallery-popup div.scrollable ul li>a").click(xfunc);//.mouseover(xfunc);
	$("a.prev",gview).click(function(){
	    if(active){
	        if(active.prev().length>0)
	            $("a",active.prev()).click();
	    }
	    return false;
	});
	$("a.next",gview).click(function(){
	    if(active){
	        if(active.next().length>0)
	            $("a",active.next()).click();
	    }
	    return false;	
	});
	$("#gallery-popup div.scrollable ul li:first>a").click();
});