$(document).ready(function(){

     
    var fade_time = 1000;
    var page_title = 'Belgrade Tango Encuentro 2011.';
    // news ticker
    autoScroller('news-content', 1, 'news');

   // hash functions
   var hash = false;
   checkHash();

    function checkHash(){
        if(window.location.hash != hash) {
            hash = window.location.hash;
            processHash(hash);
        }
    }

       function processHash(hash){
           //$('#video').hide();
         if($(hash + ' h2').html()){
        if(hash == '#artists') {
           $('#bg_fade').addClass('darker');
           $('.artist-content').hide();
            $('#artist-index').show();
        }
            $('#primary-content').removeClass('empty-stage');
            $('#bg_fade').fadeIn(500);
            $(hash).fadeIn(500);    
       
        document.title = $(hash + ' h2').html() + ' | '+ page_title;
        }
        return false;
    }





    // preload images
    var images = new Array()
    function preload() {
        for (i = 0; i < preload.arguments.length; i++) {
            images[i] = new Image()
            images[i].src = preload.arguments[i]
        }
    }
    preload(
        "images/menu/menu_artists.png",
        "images/menu/menu_program.png",
        "images/menu/menu_workshops.png",
        "images/menu/menu_prices.png",        
        "images/menu/menu_gallery.png",
        "images/menu/menu_registration.png",
        "images/menu/menu_city_map.png",
        "images/menu/menu_accomodation.png",
        "images/menu/menu_transportation.png",
        "images/menu/menu_partners.png",
        "images/menu/menu_contacts.png",
        "images/menu/menu_bte_2010.png")
   
  



    /*  menu
     * -------------------------------------------------------------*/    



    // menu
    $('#menu a[href*=#], #otros-link').click(function(){
        var link = $(this).attr('href');
        var empty_stage = $('#primary-content').hasClass('empty-stage');
        var artist_link = $(this).hasClass('fnc-menu-artist');           
        //$('#video').hide();
        if (artist_link) {            
            setTimeout(function(){
                $('#bg_fade').addClass('darker');
            }, fade_time);
            $('.artist-content').hide();
            $('#artist-index').show();                
        } else {
            $('#bg_fade').removeClass('darker');
        }

        if(empty_stage){
            $('#bg_fade').fadeIn(fade_time);
            $(link).fadeIn(fade_time);
            $('#primary-content').removeClass('empty-stage')
        } else {
            $('#primary-content .frame').fadeOut(fade_time);
            $('#bg_fade').fadeOut(fade_time);            

            setTimeout(function(){                
                $('#bg_fade').fadeIn(fade_time);
                $(link).fadeIn(fade_time);                
            }, fade_time);
        }
        
        if($(this).attr('title') ){             
            document.title = $(this).attr('title') + ' | ' + page_title;
        }
       
        return true;

        
        
    });

    // home link
    $('#logo').click(function(){
        $('#primary-content .frame').fadeOut(fade_time);
        $('#bg_fade').fadeOut(fade_time);
        $('#primary-content').addClass('empty-stage');
        setTimeout(function(){
            $('#video').fadeIn(fade_time);
            }, fade_time);
        
        document.title = page_title;
        window.location.hash = '';
        return false;
    });

    // menu hover
    $('#menu li a').hover(function(){
        $('#menu').css( 'background-image' ,'url(images/menu/menu_' + $(this).attr('rel') + '.png)');
    }, function(){
        $('#menu').removeAttr('style');
    });    
    
    
     
    /*  artist navigation
     * ------------------------------------------------------*/

    function show_artist(id) {        
        $('.artist-content').fadeOut(fade_time);
        setTimeout(function(){
            $('#bg_fade').fadeIn(fade_time);
            $(id).fadeIn(fade_time);
        }, fade_time);
        return false;
    }
 
    // artist index links
    $('#artist-index a[href*=#]').click(function(){        
        $('#artist-index').fadeOut(fade_time);
        show_artist($(this).attr('href'));
        return false;
    });    
    
    // artist controls
    $('#artists .controls a').click(function(){
        show_artist($(this).attr('href'));
        return false;
    });


    

    
    // external-link
    $('.external-link').click(function(){
        window.open(this.href);
        return false;
    });

});
