sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

$(document).ready(function() {
    $('textarea.expanding').autogrow();
    $('.visuals').cycle({
        fx:      'fade',
        timeout: 5000,
        speed:   2000,
        pause:   0
     });
    $('.enlarge').lightBox();
    $(document).pngFix();

    /**
     *  Specific class for odd table rows
     */
    if ( $('table').length > 0 ) {
        $('table:not(.clean) tr:odd').addClass('odd');
    }

    $('#tooltips a.tooltip').mouseover(function(){
        tooltip_id = $(this).attr('id');
        tooltip_id = tooltip_id.replace("t", "");

        _show_tooltip(tooltip_id);
    })

    _show_tooltips();

    $('ul#objecthash a').click(function(){
        _check_hashes();
    })

    _check_hashes();
});

function _check_hashes() {

    setTimeout(function(){
        $(document).ready(function() {

            var current_hash = window.location.hash;

            if ( current_hash == '#energiebesparing' ) {

                $('div.content a[name=energiebesparing]').closest('strong').addClass('highlight');
            }
            else {

                $('div.content strong').removeClass('highlight');
            }
        });
    }, 100);
}

function _show_tooltips() {

    _hide_tooltip();
    _hide_tooltips();
    $('#tooltips a.tooltip').removeClass('hide');
}

function _hide_tooltips() {

    $('#tooltips a.tooltip').addClass('hide');
}

function _show_tooltip(item_id) {

    var total_w  = $('img#impression').width();
    var total_h  = $('img#impression').height();

    var tt_pos   = $('a#t'+item_id).position();
    var tt_off_w = $('a#t'+item_id).width();

    var tt_pos_x = tt_pos.left + tt_off_w - 8;
    var tt_pos_y = tt_pos.top - 4;

    $('.tooltip-content').html('bezig met laden...');

    $.get('action=box_summary&load=ajax&item_id='+item_id, function(data) {
        $('.tooltip-content').html(data);
    });

    $('#tooltips a.tooltip').removeClass('active');
    $('#tooltips a#t'+item_id).addClass('active');

    $('.tooltip-content').css({'display':'block','left':tt_pos_x+'px','top':tt_pos_y+'px'});
}

function _hide_tooltip() {

    $('#tooltips a.tooltip').removeClass('active');
    $('.tooltip-content').hide();
}
