//----------------------------------------------------------------
// toggleProductData
//----------------------------------------------------------------
function toggleProductData(tab_id) {

    if( tab_id != contentID ) {      
        fadeOutElement('content'+ contentID +'',tab_id);
        contentID = tab_id;
    }
}


//----------------------------------------------------------------
// toggleDownloads
//----------------------------------------------------------------
function toggleDownloads() {
    if( jQuery('#driver').hasClass('content-hide') ) {
        jQuery('#driver').removeClass('content-hide');
        jQuery('#download-menu a:last').addClass('wactive');
        
        jQuery('#general').addClass('content-hide');
        jQuery('#download-menu a:first').removeClass('wactive');
        
    } else {
        jQuery('#general').removeClass('content-hide');
        jQuery('#download-menu a:first').addClass('wactive');
        
        jQuery('#driver').addClass('content-hide');
        jQuery('#download-menu a:last').removeClass('wactive');
    }
}


//----------------------------------------------------------------
// displayPicture
//----------------------------------------------------------------
function displayPicture(picture_name, gallery_name, picture_id) {
    jQuery('#picture_link_'+ pictureID + '').removeClass('display');
    jQuery('#picture_file_'+ pictureID + '').hide();
    
    jQuery('#picture_link_'+ picture_id + '').addClass('display');
    jQuery('#picture_file_'+ picture_id + '').show();
    
    pictureID = picture_id;

    jQuery("#gallery").attr({ 
        href: '/img/products/big/'+ gallery_name +''
    });
}


//----------------------------------------------------------------
// skipPicture
//----------------------------------------------------------------
function skipPicture(direction, max_items) {

    if( pictureID == 1 && direction == 'prev' ) {
        jQuery('#picture_link_1').removeClass('display');
        jQuery('#picture_file_1').hide();
        
        jQuery('#picture_link_'+ max_items +'').addClass('display');
        jQuery('#picture_file_'+ max_items +'').show();

        pictureID = max_items;
    
    } else if( pictureID == max_items && direction == 'next' ) {
        jQuery('#picture_link_'+ max_items + '').removeClass('display');
        jQuery('#picture_file_'+ max_items + '').hide();
        
        jQuery('#picture_link_1').addClass('display');
        jQuery('#picture_file_1').show();
        
        pictureID = 1;
    
    } else {
        jQuery('#picture_link_'+ pictureID + '').removeClass('display');
        jQuery('#picture_file_'+ pictureID + '').hide();
                
        if( direction == 'prev' ) {
            pictureID = pictureID-1;
        } else {
            pictureID = pictureID+1;   
        }
        
        jQuery('#picture_link_'+ pictureID + '').addClass('display');
        jQuery('#picture_file_'+ pictureID + '').show();

    }
    
    jQuery("#gallery").attr({ 
        href: '/img/products/big/'+ pictures.detail[pictureID-1].src +''
    });
 
}


//----------------------------------------------------------------
// displayProduct
//----------------------------------------------------------------
function displayProduct() {
    if( jQuery('#product_id_search').val() != '' && jQuery('#product_id_search').val() != 0 ) {
        document.location.href = jQuery('#product_id_search').val();
    } else {
        jQuery('#product_id_search').attr('selectedIndex',0);
    }
}


//----------------------------------------------------------------
// getProducts
//----------------------------------------------------------------
function getProducts(type, section) {
    
    var product_area            = jQuery('#product_area_'+ section +'').val();
    var option_value_product    = false;
    var option_value_cat        = false;
    var cat_name                = false;

    if( product_area != 0 && product_area != '' ) {

        if( section == 'archive' || section == 'download' ) {
            jQuery('#downloads').removeClass('warning').empty();
        }
        
        if( MEVS.get('init_product_name') && MEVS.get('callback') ) {

            if( MEVS.get('callback_param') ) {
                jQuery.jGrowl(MEVS.getText('products') +' ...', {
                    beforeClose: function(e,m) {
                        eval(''+ MEVS.get('callback')+'(\''+ MEVS.get('callback_param') +'\');');
                    }
                });
            } else {
                jQuery.jGrowl(MEVS.getText('products') +' ...', {
                    beforeClose: function(e,m) {
                        eval(''+ MEVS.get('callback')+'();');
                    }
                });
            }
        } else {
            jQuery.jGrowl( MEVS.getText('products') +' ...');        
        }
        
        jQuery.ajax({
            url: '/procs/getProducts.asp',
            data: 'product_area='+ product_area +'&lang='+ MEVS.getLang() +'&product_type='+ section +'',
            success: function(j){
        
                if( j.error_code == 0 ) {
                
                    if( !MEVS.get('init_product_name')) {
                        var options = '<option value="0" selected="selected">&raquo; '+ j.select_default +'</option>';
                    } else {
                        var options = '<option value="0">&raquo; '+ j.select_default +'</option>';
                    }
                    
                    if( section != 'search' ) {
                        if( j.cat.length > 0 ) {

                            if( MEVS.getLang() == 'de' ) {
                                updateBreadcrumb('c', j.cat[0].href, j.cat[0].name, MEVS.get('base_href'));
                                updatePageLink(MEVS.get('treelevel'), j.cat[1].href, j.cat[1].name);
                            } else {
                                updateBreadcrumb('c', j.cat[1].href, j.cat[1].name, MEVS.get('base_href'));
                                updatePageLink(MEVS.get('treelevel'), j.cat[0].href, j.cat[0].name);
                            }
                            
                            jQuery('#product_id_'+ section +' option:selected').each(function () {
                                if( jQuery(this).val() != 0 ) {
                                    jQuery("#breadcrumb ul li:last").remove();
                                    jQuery("#breadcrumb ul li:last").remove();
                                    
                                    var pageURL = jQuery("#switchlang").attr('href').split('/');
                                    pageURL.pop();
                                    pageURL = pageURL.join("/");
                                    if(pageURL.indexOf('.html') < 0) {
                                        pageURL = pageURL + '.html';
                                    }
                                    jQuery("#switchlang").attr({ 
                                        href: pageURL
                                    });
                                    
                                }
                            });
                        }
                    }
                    
                    for (var i = 0; i < j.products.length; i++) {
                        if( type == 'url' ) {
                            option_value_product    = j.products[i].url;
                            option_value_cat        = j.products[i].cat_url;
                        } else {
                            option_value_product    = j.products[i].id;
                            option_value_cat        = j.products[i].cat_id;
                        }
                        
                        if( cat_name != j.products[i].cat_name && j.products[i].cat_name != '' && j.products[i].cat_count > 1 ) {
                        
                            if( i > 3 ) {
                                options += '<option value="0">&nbsp;</option>';
                            }
                            
                            options += '<option value="0">----------------------------------</option>';
                            options += '<option value="'+ option_value_cat +'">'+ j.products[i].cat_name +'</option>';
                            options += '<option value="0">----------------------------------</option>';
                            
                            cat_name = j.products[i].cat_name;
                        }
                        
                        if( MEVS.get('init_product_name') == j.products[i].name_url ) {
                            options += '<option value="' + option_value_product + '" selected="selected">'+ j.products[i].name +'</option>';
                        } else {
                            options += '<option value="' + option_value_product + '">'+ j.products[i].name +'</option>';
                        }
                    }
  
                    if( cat_name != false ) {
                        options += '<option value="0">&nbsp;</option>';
                    }
                    jQuery('select#product_id_'+ section +'').html(options);                   
                    
                    if( jQuery('#product_area_'+ section +'').val() != '0' ) {
                       jQuery('#product_id_'+ section +'').removeAttr('disabled');
                    }
                    
                    if( !MEVS.get('init_product_name')) {
                        jQuery('#product_id_'+ section +'').attr('selectedIndex',0);
                    }

                } else {
                    if( section == 'archive' || section == 'download' ) {
                        jQuery('#downloads').addClass('warning').html(MEVS.getText('error_form'));
                    }
                }
                
                jQuery.jGrowl('close');
            },
            error: function(o,e,k){
                if( section == 'archive' || section == 'download' ) {
                   jQuery('#downloads').addClass('warning').html(MEVS.getText('error_form'));
                }
                jQuery.jGrowl('close');
            }
        });
    } else {
        jQuery('#product_area_'+ section +'').attr('selectedIndex',0);
    }
}