

$(function(){
    
    // nav active
    var hidFirst=$("#hidFirst");
    var hidSecond=$("#hidSecond");
    
    if(hidFirst.size()>0)
    {
        $("#navigation").find("li").eq(hidFirst.val()).addClass("active");
    }
    
    if(hidSecond.size()>0)
    {
        $("#navigation").find("li").eq(hidFirst.val()).find("div a").eq(hidSecond.val()).addClass("active");
    }
    
    
    // accordion 
    
    var _accordions=$(".accordion");
    if(_accordions.size()>0)
    {
        _accordions.each(function(){
            var _accordion=$(this);
            var _items=_accordion.find("div.item");
            if(_items.size()>0)
            {
                _accordion.find("div.item div.header strong").css("cursor","pointer");
                _items.eq(0).addClass("active");
                
                _items.find("div.header").click(function(){
                    var _itemHeader=$(this);
                    var _item=_itemHeader.parent();
                    if(!_item.hasClass("active"))
                    {
                        _items.removeClass("active");
                        _item.addClass("active");
                    }
                    
                }); 
            }
        });
    }
    
    //photo slider
    
    SlideGallery(5,5,"chaplainsUSA_Gallery");
    

})





function SlideGallery(_screen,_scroll,id)
{
    
    var _gal=$("#"+id);
    if(_gal.size()>0)
    {
        var _sum=_gal.find(".thumbs a").size();
        
        if(_sum>0)
        {
            var _big_a=_gal.find("div.main").children();
            
            var _prev=_gal.find("a.prev").eq(0);
            var _next=_gal.find("a.next").eq(0);
            
            var _photos=_gal.find(".thumbs a img");
            
            //_big_photo.attr("src",_photos.eq(0).attr("src")).css({"width":"313px","height":"207px"});
            
            _gal.find(".thumbs a").each(function(i,el){
                
                var _a=$(this);
                
                _a.click(function(){
                    _gal.find("div.main").fadeOut(function(){
                        _big_a.hide();
                        if(_big_a.find("a.close").size()>0)
                        {
                            _big_a.find("a.close").parent().show();
                        }
                        _big_a.eq(i).show();                        
                        $(this).fadeIn();
                    });
                })
                
            })

            
            if(_sum<=_screen)
            {
                _prev.hide();
                _next.hide();
                if(_sum==1)
                {
                    //_gal.find(".scroller").hide().end().css("height","230px");
                    _gal.find(".scroller").hide();
                }
            }
            else
            {   
                var i=0;
                var _itemWidth=_gal.find(".thumbs a").eq(0).width()+2;
                
                if ($.browser.msie && $.browser.version <= 7) 
                {
                    _itemWidth=_gal.find(".thumbs a").eq(0).width()+12;
                }
                
                var _width=_itemWidth*(_sum-_screen);
                var _box=$("#galleryBox");
                
                _next.click(function(){
                    i+=_scroll;
                    _x=_itemWidth*i;
                    if(i>_sum-_screen)
                    {
                        i=_sum-_screen;
                        _x=_width;
                    }
                    _box.animate({'marginLeft':-_x+'.px'},'1000',function(){ });
                });
            
                _prev.click(function(){
                    i-=_scroll;
                    _x=_itemWidth*i;
                    if(i<0)
                    {
                        i=0;
                        _x=0;
                    }
                    _box.animate({'marginLeft':-_x+'.px'},'1000',function(){ });
                });
                
            }
        }
        else
        {
            _gal.remove();
        }
    }
}


