/*
 * Call Classes
 */
$(document).ready(
    function(){
        new programm_filter();
        new gallery_archive();
        new bandarchiv();
        // Fancy Box
        $('.fancy').fancybox()
        // Forms
        $('input[type=text]').live('click',function(){
            if($(this).val() == $(this).attr('lang')){
                $(this).val('');
            }
        })
        $('input[type=text]').live('focusout',function(){
            if($(this).val()==''){
                $(this).val($(this).attr('lang'));  
            }
        })
        $('textarea').live('click',function(){
            if($(this).html() == $(this).attr('lang')){
                $(this).html('');
            }
        })
        $('textarea').live('focusout',function(){
            if($(this).html()==''){
                $(this).html($(this).attr('lang'));  
            }
        })
        // Form Validate
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var checked = false;
        $('form').live('submit',function(event){
            if(!$(this).hasClass('no_validate')){
                if(!checked){
                    $this = $(this)
                    event.preventDefault();
                    $($this).find('.email').each(function(index){
                        if(!emailReg.test($(this).val())){
                            $(this).attr('style','color:#FFF;background:#A04141');
                        }else{
                            checked = true;
                            $this.submit();
                        }
                    })
                }
            }
        })
    });

/*
 * Define the classes here
 */
// ----------------------------------------------------------------------------
// homesite
programm_filter = function(){
    $('.filter').live('click',function(event){
        if($(this).attr('id')=='all'){
            $(".programm").show();
        }else{
            $(".category-"+$(this).attr('id')).show();
            $("#programm_front .programm:not(.category-"+$(this).attr('id')+")").hide();  
        }
        $('.filter').removeClass('selected');
        $(this).addClass('selected'); 
    }
    )
}
// ----------------------------------------------------------------------------
// gallery archive
gallery_archive = function(){
    // Start Up
    $('.gallery-archive').children().not('.header').hide();
    
    // Click Header
    $('.gallery-archive .header').live('click',function(event){
        id = $(this).attr('id');
        $('.sub').not($('#sub_'+id)).slideUp('slow');
        $('#sub_'+id).slideDown('slow',function(){
            });
    })
}
// ----------------------------------------------------------------------------
// gallery archive
bandarchiv = function(){
    var headings = '0123456789ABCDEFGHIJKLMNOPQERSTUVWXYZ';
    $('.entry-bandarchiv-content ul li').each(function(index){
        $(this).addClass($(this).html().substr(0,1));
    })
    var $recipes = $('.entry-bandarchiv-content ul').detach();
    $('.entry-bandarchiv-content').append('<ul></ul>')
    $.each(headings, function(){
        if($recipes.find('.'+this).length >0){
            $('.entry-bandarchiv-content ul').append('<li><h3>' + this + '</h3></li>');
            $('.entry-bandarchiv-content ul').append($recipes.find('.'+this));
        }
    });
    $('.entry-bandarchiv-content ul').makeacolumnlists({
        cols: 3, 
        colWidth: 0, 
        equalHeight: 'ul', 
        startN: 1
    });
}
