$(document).ready(function() {

    $('#search a.submit').click(function() { $("form#search_form").submit(); });


    if ($('div.fce_gallery .thumbs .items')) {
        $('div.fce_gallery .thumbs .items').append($('div.fce_gallery img.thumb'));

        var thumbimgs = $('div.fce_gallery .thumbs img');
        var numbers = $('div.fce_gallery .numbers');

        for(var i = 0; i < thumbimgs.length; i+=10) {
          thumbimgs.slice(i, i+10).wrapAll("<div></div>");
        }

        $('div.fce_gallery .thumbs').scrollable({
            speed: 700,
            circular: false,
            next: ".nextButton",
            prev: ".prevButton",
            onSeek: function(event) {
                var api = $('div.fce_gallery .thumbs').data("scrollable");
                numbers.html((api.getIndex()+1)+'/'+api.getSize());
            }
        });

        var api = $('div.fce_gallery .thumbs').data("scrollable");
        if (api) {
            numbers.html('1/'+api.getSize());
        }

        $("div.fce_gallery .thumbs .items img").click(function() {
            if ($(this).hasClass("active")) {return;}
            var currentId = $(this).attr('id');
            var idArray = currentId.split('_');

            var nr = idArray[1];

            //$('div.fce_gallery .items .item').css('display', 'none');
            $('div.fce_gallery .items .item').fadeOut('slow');
            $('div.fce_gallery_item').fadeOut('slow');
            //$('div.fce_gallery .items .item_'+nr).css('display', 'block');
            $('div.fce_gallery .items .item_'+nr).fadeIn('slow');
            $('div.fce_gallery_item_'+nr).fadeIn('slow');

            $("div.fce_gallery .thumbs .items img").fadeTo('fast', 1);
            $(this).fadeTo('fast', 0.5);


            // activate item
            $("div.fce_gallery .thumbs .items img").removeClass("active");
            $(this).addClass("active");


        }).filter(":first").click();
    }

    $('#searchfield').searchField();

    $("#navigation li:contains('<ul>')").css("background", "green");
    
    $(".fce_images img").each(function () {
        if (this.width < 50) {
          this.width = 50;
        }
    });
});
// DEVELOPMENT

function switchBg(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	} else { 
		el.style.display = 'block';
	}
}
