/* library.js */

Ext.onReady(function(){
        Ext.select('#featured-sections li a').each(function(item, array, index){
            item.on('mouseover', function(evt, el, o){
                Ext.get(el).parent().radioClass('selected');
            });
            item.on('click', function(evt, el, o){
                doClick('sections', el.href.split('#')[1]);
                return false;
            }, null, {
                preventDefault: true,
                stopPropagation: true,
                stopEvent: true
            });
        });
});

/*

Ext.onReady(function(){
    var current_rel = null;
    var data = {};

    Ext.History.init();

    function initNav(){
        Ext.select('#navigation li a').each(function(item, array, index){
            item.on('click', function(evt, el, o){
                if(el.rel){
                    doClick(el.rel);
                }else{
                    location.href = el.href;
                }
                return false;
            }, null, {
                preventDefault: true,
                stopPropagation: true,
                stopEvent: true
            });
        });
        var content = Ext.get('content');
        content.setVisibilityMode(Ext.Element.DISPLAY);
    }
    
    function initContent(){
        Ext.select('#featured-sections li a').each(function(item, array, index){
            item.on('mouseover', function(evt, el, o){
                Ext.get(el).parent().radioClass('selected');
            });
            item.on('click', function(evt, el, o){
                doClick('sections', el.href.split('#')[1]);
                return false;
            }, null, {
                preventDefault: true,
                stopPropagation: true,
                stopEvent: true
            });
        });

        Ext.select('#mollys-story a').each(function(item, array, index){
            item.on('click', function(evt, el, o){
                doClick('mollys-story', el.href);
                return false;
            }, null, {
                preventDefault: true,
                stopPropagation: true,
                stopEvent: true
            });
        });

        Ext.select('#page-sections ol.rows li dl dd.thumb a').each(function(item, array, index){
            item.on('click', function(evt, el, o){
                var image_link = Ext.get(el).parent();
                Shadowbox.open({
                    content:    image_link.dom.href,
                    player:     'img',
                    title:      image_link.dom.title
                });
            }, null, {
                preventDefault: true,
                stopPropagation: true,
                stopEvent: true
            });
        });
        
        Ext.select('#news-main a').each(function(item, array, index){
            console.log('#news-main a', index, item);
            item.on('click', function(evt, el, o){
                doClick('news', el.href, el.href);
                return false;
            }, null, {
                preventDefault: true,
                stopPropagation: true,
                stopEvent: true
            });
        });
    };
    
    function init(){
        Ext.History.on('change', function(token){
            var content = Ext.get('content');
            if(token && data[token]){
                Ext.get(document.body).dom.id = 'page-' + data[token].rel;
                content.update(data[token].content);
                document.title = data[token].title;
            }
        });
        doClick('home', '', '/');
    }
    
    function doClick(rel, hash){
        var header = Ext.get('header');
        var logo = Ext.get('logo');
        var last_nav = null;
        var current_nav = Ext.get('nav-' + rel);
        var main = Ext.get('main');
        var content = Ext.get('content');
        var url = '/' + rel + '/';
        if(arguments.length >= 3)
          url = arguments[2];
        content.hide();
        main.addClass('loading');
        Ext.Ajax.request({
          	url: url
          , params: {}
          , method: 'GET'
          , success: function(response, obj) {
                data[url] = {
                    rel: rel
                  , content: response.responseText
                  , title: response.getResponseHeader('title')
                }
                if(current_nav){
                    current_nav.radioClass('selected');
                }
                if(rel === 'home'){
                    if(current_rel !== 'home'){
                        logo.move('down', 24, {
                            duration: 0.5
                        });
                    }
                    header.setHeight(411, {
                        duration: 0.5,
                        callback: function(){
                            this.removeClass('short');
                        }
                    });
                }else{
                    if(current_rel === 'home' || current_rel === null){
                        logo.move('up', 24, {
                            duration: 0.5
                        });
                    }
                    header.setHeight(209, {
                        duration: 0.5
                    });
                    header.addClass('short');
                }

                Ext.History.add(url);
                initContent();
                content.show();
                main.removeClass('loading');
                if(hash){
                    var item_anchor = Ext.get(hash);
                    var body = Ext.get(document.body);
                    if(item_anchor){
                        item_anchor.scrollIntoView();
//                        var top = (item_anchor.getOffsetsTo(body)[1]) + body.dom.scrollTop;
//                        body.scrollTo('top', top-25);
                    }
                }
                current_rel = rel;
            }
          , failure: function(response, obj){
                console.log(arguments);
            }
        });              
    }

    initNav();
    initContent();
    init();
});

*/

function launchVideo(title, video_src, width, height){
    var news_url = cgi.script_name.split('/')[2];
    Shadowbox.open({
        player: 'flv',
        width: width + 'px',
        height: height + 'px',
        title: title,
        content: '/files/news-and-press/' + news_url + '/' + video_src
    });
}

function launchYoutube(title, youtube_src, width, height){
    Shadowbox.open({
        player: 'swf',
        width: width + 'px',
        height: height + 'px',
        title: title,
        content: 'http://www.youtube.com/v/' + youtube_src + '&hl=en&fs=1&rel=0&autoplay=1&color1=0xc31130&amp;color2=0xc31130'



    }); 
}