var UFSGROUP = function(){}

UFSGROUP.homeAnimationImages =  new Array(
                                    '/images/img_ufsgroup-nyito-01.jpg',
                                    '/images/img_ufsgroup-nyito-02.jpg',
                                    '/images/img_ufsgroup-nyito-03.jpg',
                                    '/images/img_ufsgroup-nyito-04.jpg'
                                );
UFSGROUP.homeAnimationCurrentIndex = 0;

UFSGROUP.homeAnimation = function(){
    if($(document.body).is('.home')){
        for(var i=0; i<UFSGROUP.homeAnimationImages.length;i++){
            var img = $('<img style="display:none" src="'+UFSGROUP.homeAnimationImages[i]+'">');
            $(document.body).append(img)
        }
        setInterval("UFSGROUP.homeCreateAnimation()", 5000);
    }
    
}
UFSGROUP.homeCreateAnimation = function(){
    
    UFSGROUP.homeAnimationCurrentIndex++;
    if(UFSGROUP.homeAnimationCurrentIndex>UFSGROUP.homeAnimationImages.length-1) UFSGROUP.homeAnimationCurrentIndex = 0;
    
    var bgContainer = $('.home #pBgContainer .pbg');
    
    bgContainer.filter(':hidden').css({background: 'url("'+UFSGROUP.homeAnimationImages[UFSGROUP.homeAnimationCurrentIndex]+'")'});
    
    bgContainer.filter(':visible').fadeOut('slow')
    bgContainer.filter(':hidden').fadeIn('slow')
    
    
}

UFSGROUP.GALLERY = function(){}
UFSGROUP.GALLERY.init = function(){
    var galImages = $('.galleryContainer a.image');
    galImages.each(function(){
       var img = $('img', $(this));
       $(this).attr('title', $(img).attr('alt'));
       $(this).attr('href', $(img).attr('src').replace('150x112_', ''));
    })
    
    galImages.lightbox();
    
    $('.galleryContainer').each(function(){
        var parent = $(this);
        var link = $('<a href="#">Galéria megtekintése</a>')
        
        $(this).after(link);

        $(link).click(function(){
            $('a.image:eq(0)', parent).click()
            return false;
        })
    })
}

UFSGROUP.SEARCH = function(){}
UFSGROUP.SEARCH.init = function(){
    $('#queryString').focus(function(){
        $(this).val()=='Keresés'?$(this).val(''):'';
    })
    $('#queryString').blur(function(){
        $.trim($(this).val())==''?$(this).val('Keresés'):'';
    })
}


$(function(){
    UFSGROUP.homeAnimation();
    UFSGROUP.GALLERY.init();
    UFSGROUP.SEARCH.init();
})
