$(document).ready(function() {

    var max_height = 0;
    $('#content ul.news-list li').each(function() {
        var curr_height = $(this).children('SPAN.border-all').height();
        if (curr_height > max_height) {
            max_height = curr_height;
        }
    });
    $('SPAN.border-all').css('height', max_height);

    // BANNERS SMALL
    var new_src = '';
    $('ul.banners.small li A').hover(function() {
        new_src = $(this).find('IMG').attr('src').replace('black', 'color');
        $(this).find('IMG').attr('src', new_src);
    }, function() {
        new_src = $(this).find('IMG').attr('src').replace('color', 'black');
        $(this).find('IMG').attr('src', new_src);
    });

    // TAB
    if ($('.tabs LI').length) {
        var id_curr = $('.tabs LI.active A').attr('rel');
        var height_max = $('#' + id_curr).height();
        $('#' + id_curr).css('display', 'block')
        $('.tabs-power').height(height_max);
        $('#start.content-about-box').css('position', 'absolute')
        $('#power-quality.content-about-box').css('position', 'absolute')
    }

    $('.tabs LI A').click(function() {
        if ($(this).parent().hasClass('active')) {
            return false;
        }
        $('.tabs LI.active').removeClass('active');
        $(this).parent().addClass('active');
        var id_cur = $(this).attr('rel');
        var height_min = $('#' + id_cur).height();
        $('.content-about-box').fadeOut(1000);
        $('#' + id_cur).fadeIn(1000);
        setTimeout(function() {
            $('.tabs-power').height(height_min)
        }, 400);
        return true;
    });

    // CHECKBOX STYLE
    if ($('INPUT.map-input').attr("checked")) $('INPUT.map-input').parent().children('label').addClass('checked');
    $('INPUT.map-input').change(function() {
        if ($(this).attr("checked")) {
            $(this).parent().children('label').addClass('checked');
        } else {
            $(this).parent().children('label').removeClass('checked');
        }

    });

    // MAP
    if ($('#content .map').length > 0) {
        $('.map').maphilight();
    }
    // SLIDE UP-DOWN
    $('.over-cobouw A').click(function() {
        if ($(this).hasClass('no-active')) {
            $(this).removeClass('no-active');
            $(this).addClass('active');
            $(this).parent().children('DIV.over-text').stop(true, true).slideDown(200);
            $(this).parent('DIV').addClass('curr');
        } else {
            $(this).removeClass('active');
            $(this).addClass('no-active');
            $(this).parent().children('DIV.over-text').stop(true, true).slideUp(200);
            $(this).parent('DIV').removeClass('curr');
        }
    });
    $('A.lock.top-arr').click(function() {
        if ($(this).hasClass('lock-top')) {
            $(this).removeClass('lock-top');
            $(this).parent('.dow-excel').parent('LI').children('UL.sub-dow').stop(true, true).slideUp(200);
        } else {
            $(this).addClass('lock-top');
            $(this).parent('.dow-excel').parent('LI').children('UL.sub-dow').stop(true, true).slideDown(200);
        }

    });
    
    // LIGHTBOX
    $('A.lightbox').lightBox();
    
    //SELECTBOX
    $('SELECT:not([multiple])').selectbox();
    if ($('SELECT[multiple]').length) {
        $('#my_select').coolMultiple();
        $('#my_select2').coolMultiple();
    }    
    
    // INPUT AUTO HINT
    $('INPUT.auto-hint').each(function(i, el) {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
        $(el).focus(function() {
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }
        });
        $(el).blur(function() {
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
            }
        });
    });
    
    // TEXTAREA AUTO HINT
    $('TEXTAREA.auto-hint').each(function(i, el) {
        if ($(this).html() == '') {
            $(this).html($(this).attr('title'));
        }
        $(el).focus(function() {
            if ($(this).html() == $(this).attr('title')) {
                $(this).html('');
            }
        });
        $(el).blur(function() {
            if ($(this).html() == '') {
                $(this).html($(this).attr('title'));
            }
        });
    });

    /* formulier.js */
    if ($('#file').length) {
        $('#file').customFileInput();
    }

    $('.selchange').bind('change', function() {
        var index = $(this).attr('value');
        if (index == 'anders') {
            $(this).parent('.jquery-selectbox').parent('.select-large').parent('.border-white').children('.select-visible').css('display', 'block');
        } else {
            $(this).parent('.jquery-selectbox').parent('.select-large').parent('.border-white').children('.select-visible').css('display', 'none');
        }
    });

    $('.hover-title').hover(function() {
        var curr = $(this).attr('id');
        $(this).parent('map').parent('.map-area').children('.map-title').children('A.' + curr).addClass('change-color');
    }, function() {
        //$(this).parent('map').parent('.map-area').children('.map-title').children('A' + curr).removeClass('change-color');
        $('.map-title A').removeClass('change-color');
    });
    $('.map-title A').hover(function() {
        $('#' + $(this).attr('class')).mouseover();
    }, function() {

    });
    $('.tab-sub').hover(function() {
        $(this).parent('LI').addClass('hover-active');
    }, function() {
        $(this).parent('LI').removeClass('hover-active');
    });

    $('#header .main-menu LI, #content UL.tabs LI, BUTTON.button, .popup .thumbs-list UL LI, #content .main .news.servicepagina .slider .links-slide UL LI, #content .slider.green-box .links-slide UL LI, #content .slider .links-slide  UL LI').hover(function() {
        if ($(this).hasClass('new-sub-menu')) $(this).children('A').addClass('no-bg');
        $(this).addClass('iehover');
    }, function() {
        if ($(this).hasClass('new-sub-menu')) $(this).children('A').removeClass('no-bg');
        $(this).removeClass('iehover');
    });
    $('#header .main-menu LI UL LI.with-ic').hover(function() {
        $(this).children('.tab-sub').show();
    }, function() {
        $(this).children('.tab-sub').hide();
    });

});

	// todo: still used?
    $('.thumbs-box ul li').live('click', function() {
        setTimeout(function() {
        }, 1000);
		var topDiv = $(this).parents('div.popup')[0];
        $('.thumbs-box ul li', topDiv).removeClass('active');
        $('.thumbs-box ul li', topDiv).removeClass('onhover');
        $(this).addClass('active');

        var id_slide = $(this).children('A').attr('class');
        $('.rotator LI', topDiv).removeClass('curr_id');
        $('.rotator LI' + id_slide, topDiv).addClass('curr_id');
    });
    $('.next-btn').live('click', function() {
		var topDiv = $(this).parents('div.popup')[0];
        if ($('.rotator LI', topDiv).length  < 2 ) {
			return;
		}
        if ($('.rotator LI', topDiv).last().hasClass('curr_id')) {
            $('.rotator LI', topDiv).first().addClass('curr_id');
            $('.rotator LI.curr_id', topDiv).last().removeClass('curr_id');
        } else {
            $('.rotator LI.curr_id', topDiv).next('LI').addClass('curr_id');
            $('.rotator LI.curr_id', topDiv).prev('LI').removeClass('curr_id');
        }
    });
    $('.prev-btn').live('click', function() {
		var topDiv = $(this).parents('div.popup')[0];
        if ($('.rotator LI', topDiv).length  < 2) {
			return;
		}
        if ($('.rotator LI', topDiv).first().hasClass('curr_id')) {
            $('.rotator LI', topDiv).last().addClass('curr_id');
            $('.rotator LI.curr_id', topDiv).first().removeClass('curr_id');
        } else {
            $('.rotator LI.curr_id', topDiv).prev('LI').addClass('curr_id');
            $('.rotator LI.curr_id', topDiv).next('LI').removeClass('curr_id');
        }
    });

//$('SELECT.mult').coolMultiple();
    
