﻿$(document).ready(function()
{
    // setup top menu

    $images = ['images/m2m.jpg', 'images/m2m.jpg'];

    $loaded = 0;
    var preload = document.createElement('img');
    $(preload).load(function(){
        if ($loaded == $images.length)
        {
            start_timer();
        }
        else
        {
            $(preload).attr('src', $images[$loaded++]);
        }        
    }).trigger('load');

    $('div.toggle').hide();
    
    $('div.toggle').each(function(e) {
        $div = $(this)
        $(this).next().click(function(e)
        {
            $(this).hide();
            $div.toggle();
            new ElementMaxHeight();
            return false;
        });
    });

    // setup buttons

    $('ul.menu li:first-child').addClass('first');
    $('ul.menu li:last-child').addClass('last');

    $('ul.menu li:nth-child(6)').addClass('last');
    $('ul.menu li:nth-child(7)').addClass('first');

    $('ul.menu li').hover(
        function(){ 
            $(this).addClass('highlight'); 
        },
        function(){ 
            $(this).removeClass('highlight'); 
        }).
        click(function() {
            document.location.href = $(this).children('a')[0].href;
        });
        
    $('.button').hover(
        function(){ $(this).addClass('highlight'); },
        function(){ $(this).removeClass('highlight'); }).
        click(function() {
            var anchor = $(this).children('a')[0];
            if (anchor.onclick != undefined && anchor.onclick())
            {
                document.location.href = anchor.href;
            }
        });
        
     // setup "show more" anchor
        
     $('.text_full').hide();
        
     $('.more').click(
        function() {
            $('.more').show();
            $(this).hide();
            $('.text_full').hide();
            $('.text_preview').show();
            $(this).parents('p').children('.text_preview').hide();
            $(this).parents('p').children('.text_full').show();
            
            $('p').removeClass('highlight');
            $(this).parents('p').addClass('highlight');
            
            return false;
        }
     );

     
    // setup heights
     
    new ElementMaxHeight();

});