/**

/**
 * Speed of animations in seconds
 */
var speed = .7;
var nextSection;

/**
 * Init jQuery javascripts when dom is ready
 *
 * @return void
 */
$(function()
{
    // -- make the bottom area of the home page scrollable
    if ($(".scrollable"))
    {
        var api = $(".scrollable").scrollable({
            size      : 1,
            clickable : false,
            keyboard  : true,
            items     : ".panels",
            api       : true,
            speed     : speed * 1000,
            loop      : true
        });
    }
    
    // -- set up custom scroll bars
    if ($(".scroll-pane"))
    {
        $(".scroll-pane").jScrollPane({
            scrollbarWidth  : 8
        });
    }
    
    // -- add hover line to feature boxes
    $('.feature').hover(
        function(e){
            $(this).find("hr").css({
                "color"            : "#e4ff00",
                "background-color" : "#e4ff00"
            });
        },
        function(e){
            $(this).find("hr").css({
                "color"            : "transparent",
                "background-color" : "transparent"
            });
        }
    );
    
    // -- make faceboxes work
    $("a[rel*=facebox]").facebox({
        opacity:0.75
    });
    
    // -- facebox closer
    $("#closer a").live("click", function(e) {
        e.preventDefault();
        
        $(document).trigger('close.facebox');
    });
    
});

/**
 * Scroll the bottom content area to specific content.
 *
 * @param string section  Section to jump to; based on id's of panels
 * @return void
 */
function gotoContent(section)
{
    if (section == undefined) section = nextSection;
    var api = $(".scrollable").scrollable();
    var index = 0;
    
    switch (section) 
    {
        case "video"   : index = 1; break;
        case "photo"   : index = 2; break;
        case "artworks"   : index = 3; break;
        case "about"   : index = 4; break;
        case "contact"   : index = 5; break;


        default        : index = 0; break;
    }
    
    api.seekTo(index);
	
}

/**
 * Jump to a content section.
 *
 * Automatically scrolls to the content-bottom div and
 * calls the corresponding section animation when complete.
 * 
 * @param string section  Section to jump to; based on id's of panels
 * @return void
 */
function gotoSection(section)
{
    var complete = false;
    var targetOffset = $("#content-bottom").offset().top;
    
    gotoContent(section);
    
    // $("html,body").animate({scrollTop: targetOffset}, speed * 1000, "swing", function()
    //     {
    //         if (complete != true)
    //         {
    //             complete = true;
    //             
    //             gotoContent(section);
    //         }
    //     });
}

/**
 * Handle changes in address.
 *
 * @param Event event  SWFAddress change event
 * @return void
 */
function _handleChange(event) 
{
    if (event.path)
        {
            if (event.path.length && event.path != "/")
            {
                var path = event.path;
                            
                if (path.charAt(0) == "/") path = path.substr(1);
                if (path.charAt(path.length - 1) == "/") path = path.substr(0, path.length - 2);        
                
                gotoSection(path);
            }
        }
}

// -- register change handlers
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, _handleChange);

// -- configure sifr
var futura = { src: '/swf/bfuturah.swf' };

sIFR.activate(futura);

sIFR.replace(futura, {
    css: [
        '.sIFR-root { background-color:transparent; color: #ffffff; font-size:20px; text-transform:uppercase; }'
    ],
    fitExactly      : true,
    forceClear      : true,
    forceSingleLine : true,
    selector        : 'h2',
    transparent     : true
});

sIFR.replace(futura, {
    css: [
        '.sIFR-root { background-color:transparent; color: #ffffff; font-size:14px; leading:-7; text-transform:uppercase; }'
    ],
    fitExactly      : true,
    forceSingleLine : false,
    selector        : '.feature h3',
    transparent     : true,
    tuneHeight      : -7
});

sIFR.replace(futura, {
    css: [
        '.sIFR-root { background-color:transparent; color: #ffffff; font-size:8px; text-transform:uppercase; }'
    ],
    fitExactly      : true,
    forceSingleLine : true,
    selector        : '.feature span',
    transparent     : true
});

sIFR.replace(futura, {
    css: [
        '.sIFR-root { background-color:transparent; color: #ffffff; font-size:14px; text-transform:uppercase; }',
        'a { color:#e4ff00; text-decoration:none; }',
        'a:hover { color:#e4ff00; text-decoration:underline; }'
    ],
    selector        : '.info p',
    transparent     : true
});

// sIFR.replace(futura, {
//     css: [
//         '.sIFR-root { background-color:transparent; color: #ffffff; font-size:16px; text-transform:uppercase; letterSpacing:-0.2; }'
//     ],
//     fitExactly      : true,
//     forceSingleLine : true,
//     selector        : '.project-titles',
//     transparent     : true,
//     tuneHeight      : -5
// });

sIFR.replace(futura, {
    css: [
        '.sIFR-root { background-color:transparent; color: #ffffff; font-size:10px; text-transform:uppercase; }',
        'a { color:#ffffff; text-decoration:none; }',
        'a:hover { color:#e4ff00; text-decoration:none; }',
        '.active { color:#e4ff00; }'
    ],
    fitExactly      : true,
    forceSingleLine : true,
    selector        : '#category-menu ul li',
    transparent     : true
});

