$(document).ready(function(){
    
    // EQUAL HEIGHTS:
    window.onload = function(){
        //Get heights:
        var subcontentHeight = $('div.subcontent').height();
        var contentHeight = $('div.content').height();
        var sidebarHeight = $('div.sidebar').height() - subcontentHeight;
        //Set content height if less than sidebar:
        if ( contentHeight < sidebarHeight ) {
            $('div.content').height( sidebarHeight );
        };
    };
    
    //HOME PAGE STORIES
    $('.storyarea').scrollable({ size: 1, clickable: false, loop: true }).autoscroll(9000).navigator({navi:'.tabs'});
    
    //SPEAKER TOPICS HOVER
    $('div.speaker-block').hover(
        function() {
            $(this).children('ul.topics-list').fadeIn('def');
            return false;
        },
        function() {
            $(this).children('ul.topics-list').fadeOut('def');
            return false;
        }
    );
    
    //EXPANDABLE LISTS
    //remove empty expandable lists:
    $('ul.expandable').not(':has(li ul li)').remove();
    
    //expand lists
   $('ul.expandable').children('li').children('a').click(function(e) {
        var parentlist = $(this).parent('li').parent('ul');
        if( parentlist.hasClass('collapse-onclick') ){
            if( $(this).next('ul').hasClass('expanded') ){
                $(this).next('ul').slideToggle("fast");
                $(this).next('ul').toggleClass('expanded');
                return false;
            } else {
                parentlist.children('li').children('ul.expanded').slideUp("fast");
                parentlist.children('li').children('ul.expanded').toggleClass('expanded');
                $(this).next('ul').slideToggle("fast");
                $(this).next('ul').toggleClass('expanded');
                return false;
            }
        } else {
            //Show list
            $(this).next('ul').slideToggle("fast");
            $(this).next('ul').toggleClass('expanded');
            return false;
        }
        return false;
    });
    
    //CYCLE SLIDESHOW
    $('.adbox').cycle({
	fx: 'fade',
        timeout: 6000
    });
    //CYCLE SLIDESHOW
    $('.adbox1').cycle({
	fx: 'fade',
        timeout: 6000
    });
    //CYCLE SLIDESHOW
    $('.adbox2').cycle({
	fx: 'fade',
        timeout: 6000,
        delay: 3000
    });

    ////CYCLE SLIDESHOW
    $('.testimonial-rotation').cycle({
	fx: 'fade',
        timeout: 10000
    });
    
    //SPEAKERS LIST SCROLL
    //add tabs for each slide (weird but works)
    $("div.item").each(function (i) {
        $('div.tabstatic').append('<a href="#"></a>');
    });

    //initiate tabs:
    $('div.tabstatic').tabs('.scrollable > div', {
        effect: 'default',
        rotate: false
    }).slideshow({ clickable: false });
    
    //MEDIA LISTS
    //add msg to empty lists:
    $('ol.media-list').not(':has(li)').append('Coming soon');
    
    //Value Modal
    $('a.value-modal-trigger').click(function(e) {
        $('div.value-modal-container').fadeIn('fast');
        e.preventDefault();
    });
    $('div.value-modal-content .closebtn').click(function() {$('div.value-modal-container').fadeOut('fast');});
    $('div.value-modal-container').click(function() {$(this).fadeOut('fast');});
    
    //Media Modal
    $('a.modal-trigger').click(function(e) {
        var modalSrc = $(this).attr('href');
	$('#modal-frame').attr('src', modalSrc);
	$('div.modal-container').fadeIn('fast');
	e.preventDefault();
    });
    $('div.modal-container').click(function(){
	$(this).fadeOut('fast');
        $('#modal-frame').attr('src', '');
    });
    $('div.modal-container a.closebtn').click(function() {
        $('div.modal-container').fadeOut('fast');
        $('#modal-frame').attr('src', '');
    });
    
});
