function clickbox(obj, activeClassName, refresh){
    var active_class_name = (activeClassName) ? activeClassName : "active";
    $(obj).each(function (count, el){
        if ( $(this).find("a").size() > 0 ){
            $(el).bind({
                mouseover: function(){
                    $(this).addClass(active_class_name).css('cursor','pointer');
                    if ( refresh === true ) Cufon.refresh();
                },
                mouseleave: function(){
                    $(this).removeClass(active_class_name);
                    if ( refresh === true ) Cufon.refresh();
                },
                click: function(){
                    $(location).attr('href', $(this).find('a').attr('href') );
                }
            });
        }
    });
}

$(document).ready(function(){
    /** clickboxes **/
    clickbox($('#services-box > div'), 'active', true);
    clickbox($('#items .item'), 'active', true);
});

$(window).bind('load', function(){
    /** cufon **/
    $('#menu-box li:not(".active") a, #i-nav-box.services ul li:not(".active") a, #home-boxes #right-box p').each(function(){
        Cufon.replace(this, {
            hover: true,
            fontFamily: 'gbook'
        });
    })
    $('#menu-box li.active a, #items h2, #i-nav-box.services ul li.active a, .itemxxxxx h2, #title-box h1, #services-box h2').each(function(){
        Cufon.replace(this, {
            hover: true,
            fontFamily: 'gblack'
        });
    })
    $('#description-box').each(function(){
        Cufon.replace(this, {
            hover: true,
            fontFamily: 'glight'
        });
    })

    /** menu events **/
    $('#menu-box li img').width( $('#menu-box li img').parents('li').width() + 24);

    /** solve two-cells **/
    if ( $('.two-cells').size() > 0 ){
        var f = $('.two-cells .content:eq(0)');
        var s = $('.two-cells .content:eq(1)');
        var h2c = f.find('h2').size();
        var bool = false;
        var content = '';

        $('.two-cells .content').each(function(c,parentContent){
            for (var i = 0; i < h2c; ++i){
                $(this).append('<div class="wrap" />');
            }

            var $position = 0;
            $(this).find('> *:not("div.wrap")').each(function(cnt, el){
                if ( cnt != 0 && el.nodeName.toLowerCase() == 'h2') $position++;
                $(el).appendTo( $(parentContent).find('.wrap').eq($position) );
            })
        })

        f.find('.wrap').each(function(cnt, el){
            var maxHeight = Math.max( f.find('.wrap').eq(cnt).height(), s.find('.wrap').eq(cnt).height() );
            f.find('.wrap').eq(cnt).height( maxHeight + 15 );
            s.find('.wrap').eq(cnt).height( maxHeight + 15 );
        })

        /** solve height **/
        var lineHeight = $('.vertical-line:first').height();
        var contentHeight = 0;
        $('.two-cells .content').each(function(){
            if ( $(this).height() > contentHeight ) contentHeight = $(this).height();
        })

        if ( ($('.vertical-line').height() - contentHeight) <= 40 )
            $('.vertical-line').height( contentHeight + 40 );
    }

    /** solve three-cells line height **/
    var lineHeight = 0;
    var contentHeight = 0;

    $('.three-cells > p').each(function(){
        if ( $(this).height() > lineHeight ) lineHeight = $(this).height();
    })

    $('.three-cells > .content').each(function(){
        if ( $(this).outerHeight() > contentHeight ) contentHeight = $(this).outerHeight();
    })

    $('.three-cells > p').height( contentHeight );
});
