var second_level = false;

function middle_listeners(){
	if( document.location.href.toString().indexOf('#') < document.location.href.toString().indexOf('&') ){
	
		second_level = document.location.href.toString().substr(document.location.href.indexOf('&') + 1);

		document.location.href = document.location.href.toString().substr(0, document.location.href.indexOf('&'));
	}

    $('#nav-right ul a').each(function(){
        $(this).attr("href",'#' + $(this).attr("href").split('?')[1]);
    });

    // center menu
    $('#nav-right ul a').history(function(){

        $('#nav-right ul a').removeClass('selected');
        
        $(this).addClass('selected');
        
        var url = document.location.href.toString().substr(0, document.location.href.indexOf('#')) + $(this).attr("href").replace('#', '?');

        $.ajax({
            type    : 'post',
            url     : url,
            data    : 'ajax=true',
            success: function(msg){

                $('#vid-right').show();
                    
                if( lbMovie('movie') ) {
                
                	try { lbMovie('movie').doPause(); }
                	catch(err) { };

	                setTimeout( function(){
	                    try { lbMovie('movie').playVideo(msg); }
	                    catch(err) { }
	                }, 500)

                }else {
                    LbVideoPlace('our-video', {
                                        height      : 288,
                                        width       : 426,
                                        skin        : root + 'swf/blip.swf',
                                        videoFile   : msg,
                                        flashFile   : root + 'swf/video.swf'
                                      });
                }

            }
        });
    
    });
}

function left_listeners(){

    // left menu
    $('#nav-left ul a').history(function(){

        $('#nav-left ul a').removeClass('selected');
        
        $(this).addClass('selected');
        $(this).blur();

        if( lbMovie('movie') ){

            try { lbMovie('movie').doPause(); }
            catch(err) { }

        }

        $('#nav-right ul, #vid-right').fadeOut(200);
        
        var url = document.location.href.toString().substr(0, document.location.href.indexOf('#')) + $(this).attr("href").replace('#', '?');

        $.ajax({
            type    : 'post',
            url     : url,
            data    : 'ajax=true',
            success: function(msg){

                $(this).delay(100, function(){
                    $('#nav-right').html(msg);          // load in new html
                    middle_listeners();
                    $('#nav-right ul').fadeIn(200);  	// show list
                    
                    if( second_level && !isNaN(second_level) ){
                    	setTimeout(function(){

                    		if( typeof(second_level) != 'boolean' )
	                    		document.location.href = document.location.href + "&" + second_level;

                    		second_level = false;

                    	}, 250);
                    }
                });

            }
          });
    
    });
}

$(document).ready(function() {
/*    $('#nav-left ul a').each(function(){
        $(this).attr("href",'#' + $(this).attr("href").split('?')[1]);
    });

    left_listeners()
    middle_listeners();
    
    $.ajaxHistory.initialize();*/
});