$(document).ready(function(){
    $(document)[0].oncontextmenu = function() {return false;}
    // Externe Links
    $('a[rev=ext]').attr('target','_blank');
    
    // Product Compare Form
    $('form.clear-product-form').each(function(){
        if($(this).find('input').size()>0){
            $(this).find('a').click(function(){
                $(this).parents('form').submit();
                return false;
            });
        } return true;
    });

    $('#sub-navigation .first-child a').attr('href',ABS_URI);

    $('#navigation li a[href$=/ext_dealers/]').each(function(){
        $(this).attr('href','http://accell.orange-juice.nl/');
        $(this).attr('target','_blank');
    });

   $('input.reseller').click(function(){
       location.href = ABS_URI+'resellers/';
       return false;
    });
    
    $('form.select-product-form').each(function(){
        $(this).find('select').change(function(){
            $(this).parents('form').submit();
        }) 
    });
    
    // Print link
    $('a[rel=print]').click(function(){
        window.print();
        return false; 
    });
    
    // Checkboxes 
    var checkboxes = $('#product-overview input[type=checkbox]'); 
    checkboxes.click(function(){
        if($('#product-overview input[type=checkbox]:checked').size()==3) {
            checkboxes.each(function(){
                if(!$(this).attr('checked')){
                    $(this).attr('disabled','disabled');
                }    
            });
        } else {
            checkboxes.removeAttr('disabled');
        }
    });
    
    // Zoek Machine
    var search_input_value;
    var search_input = $('#search input');
    
    search_input.click(function(){
        search_input_value = $(this).val();
        $(this).val('');         
    });
    
    search_input.blur(function(){
        if($(this).val() == '') {
            $(this).val(search_input_value);
        }
    });
    
    $('#category-menu li a.hasSubMenu').click(function(){
        return false;
    });
    
    brochureReplace.init();

});

var brochureReplace = {
    targetReplace:     null,
    iframe:            null,
    
    init: function() {
        this.targetReplace         = $('#brochure-replace');
        this.iframe                = $('<object>');
        $('body').removeClass('no-menu');
        this.replace();
        
    },
    
    replace: function() {
        this.iframe.attr('data', BROCHURE_FOLDER);
        this.iframe.attr('type','text/html');
        this.targetReplace.html(this.iframe);
    }
}