var LANG = 'en-GB' || 'de-AT'; // LANG || 'de';
//var LANG = LANG || 'en-GB'; // 'en-GB' = 'en'
// sanitizing LANG
LANG = LANG.toLowerCase();
var sepPosition = LANG.indexOf('-'); // changing from IETF long language code to short code (e.g. de-AT -> de OR en-UK -> en
if(sepPosition > -1) {
	LANG = LANG.substr(0, sepPosition);
}

//<Tooltip Funktionen
function showTooltip(id) {

	var off_top = jQuery("#" + id).prev().offset().top;
	var off_left = jQuery("#" + id).prev().offset().left;
	
	jQuery("#" + id).clone().appendTo("body").show().attr("id",id+"-clone");
	jQuery("#" + id+"-clone").css("top",(off_top-(jQuery("#" + id+"-clone").height()+5)));
	jQuery("#" + id+"-clone").css("left",off_left-(jQuery("#" + id+"-clone").width()/2));
	jQuery("#" + id+"-clone").css("z-index","9999");
	
}
//Tooltip Funktionen>

function hideTooltip(id) {
    jQuery("#" + id+"-clone").hide(0);
    jQuery("#" + id+"-clone").remove();
}

function showTooltipExtended(id,imgId) {
	var imgSrc = jQuery("#" + imgId).html();
	jQuery("#" + imgId).html("<img id='" + imgId + "Image' src='" + imgSrc + "'>");
	var off_top = jQuery("#" + id).prev().offset().top;
	var off_left = jQuery("#" + id).prev().offset().left;
	
	jQuery("#" + id).clone().appendTo("body").show().attr("id",id+"-clone");
	jQuery("#" + id+"-clone").css("top",(off_top-(jQuery("#" + id+"-clone").height()+5)));
	jQuery("#" + id+"-clone").css("left",off_left-(jQuery("#" + id+"-clone").width()/2));
	jQuery("#" + id+"-clone").css("z-index","9999");
	
}
//Tooltip Funktionen>

function hideTooltipExtended(id, imgId) {		
	var imgSrc = jQuery("#" + imgId + "Image").attr("src");
	jQuery("#" + imgId).html(imgSrc);
    jQuery("#" + id+"-clone").hide(0);
    jQuery("#" + id+"-clone").remove();
}

function showTooltipTerminal(id,imgId1, imgId2, imgId3) {
	var imgSrc1 = jQuery("#" + imgId1).html();
	var imgSrc2 = jQuery("#" + imgId2).html();
	var imgSrc3 = jQuery("#" + imgId3).html();
	
	jQuery("#" + imgId1).html("<img class='ap' id='" + imgId1 + "Image' src='" + imgSrc1 + "'>");
	jQuery("#" + imgId2).html("<img class='ap' id='" + imgId2 + "Image' src='" + imgSrc2 + "'>");
	jQuery("#" + imgId3).html("<img class='ap' id='" + imgId3 + "Image' src='" + imgSrc3 + "'>");
	var off_top = jQuery("#" + id).prev().offset().top;
	var off_left = jQuery("#" + id).prev().offset().left;
	
	jQuery("#" + id).clone().appendTo("body").show().attr("id",id+"-clone");
	jQuery("#" + id+"-clone").css("top",(off_top-(jQuery("#" + id+"-clone").height()+5)));
	jQuery("#" + id+"-clone").css("left",off_left-(jQuery("#" + id+"-clone").width()/2));
	jQuery("#" + id+"-clone").css("z-index","9999");
	
}
//Tooltip Funktionen>

function hideTooltipTerminal(id, imgId1, imgId2, imgId3) {	
	var imgSrc1 = jQuery("#" + imgId1 + "Image").attr("src");
	var imgSrc2 = jQuery("#" + imgId2 + "Image").attr("src");
	var imgSrc3 = jQuery("#" + imgId3 + "Image").attr("src");
	jQuery("#" + imgId1).html(imgSrc1);
	jQuery("#" + imgId2).html(imgSrc2);
	jQuery("#" + imgId3).html(imgSrc3);
	
    jQuery("#" + id+"-clone").hide(0);
    jQuery("#" + id+"-clone").remove();
}

var productnavigator = {}; // Productnavigator
(function($) {

    (function(pn) {

        (function() { // refinement tree methods
            pn.targetServerScript = '/banner/files/get.aspx'; // 'get.aspx'

            pn.refinementTree = {};

            pn.refinementTree.preselectedCategory = null;

            pn.refinementTree.preselectCategory = function(preselectedCategory) {
                pn.refinementTree.preselectedCategory = preselectedCategory;
                $(window).one("productfinder.categoryselection.load", function() {
                    pn.refinementTree.selectCategory(preselectedCategory);
                });
            }

            pn.refinementTree.selectCategory = function(selectedCategory) {
                if (selectedCategory !== null) {
                    $("#categorySelection .selectionForm .item .id").each(function() {
                        var id = parseInt($(this).text());
                        if (id === selectedCategory) {
                            var target = $(this).parent();
                            target.siblings().removeClass('selected');
                            target.addClass('selected');

                            pn.refinementTree.loadManufacturerSelection();
                        }
                    });
                }
            }

            pn.refinementTree.loadCategorySelection = function() {
                var categoryRenderer = pn.createDivRenderer('#categorySelection .selectionForm');
                var rendererFunc = categoryRenderer.render;

                if (typeof (pn.refinementTree.preselectedCategory) !== null) {
                    rendererFunc = function(data) {
                        categoryRenderer.render(data);
                        // select preselectedCategory
                        pn.refinementTree.selectCategory(pn.refinementTree.preselectedCategory);
                    };
                }

                $.getJSON(pn.targetServerScript, { jsonpcallback: '?', querysubject: 'categories', lang: LANG }, function() {
                    rendererFunc.apply(this, arguments);
                    $(window).trigger("productfinder.categoryselection.load");
                });
            };

            pn.refinementTree.loadManufacturerSelection = function() {
                var manufacturerRenderer = pn.createDivRenderer('#manufacturerSelection .selectionForm');
                var categoryValue = $('#categorySelection .selectionForm .selected .id').text();
                if (categoryValue !== "") {
                    $.getJSON(pn.targetServerScript,
				{
				    jsonpcallback: '?',
				    querysubject: 'manufacturers',
				    category: categoryValue
				},
				manufacturerRenderer.render);
                }

                $('#typeSelection .selectionForm').empty();
                pn.clearResultWindow();
                $('#manufacturerFilter').textFilterElements('#manufacturerSelection .selectionForm div');
            };

            pn.refinementTree.loadTypeSelection = function() {
                var typeRenderer = pn.createDivRenderer('#typeSelection .selectionForm');

                var categoryValue = $('#categorySelection .selectionForm .selected .id').text();
                var manufacturerValue = $('#manufacturerSelection .selectionForm .selected .id').text();

                if (categoryValue !== "" && manufacturerValue !== "") {
                    $.getJSON(pn.targetServerScript,
			{
			    jsonpcallback: '?',
			    querysubject: 'types',
			    category: categoryValue,
			    manufacturer: manufacturerValue
			},
			typeRenderer.render);
                }

                pn.clearResultWindow();
                $('#typeFilter').textFilterElements('#typeSelection .selectionForm div');
            };

            pn.refinementTree.loadResult = function() {
                var resultUpdater = pn.createResultTableRenderer('#result');
                var typeidValue = $('#typeSelection  .selectionForm .selected .id').text();
                if (typeidValue !== "") {
                    $.getJSON(pn.targetServerScript,
			{ jsonpcallback: '?', querysubject: 'batteries', typeid: typeidValue },
			resultUpdater.render);
                };
            }
        })();

        (function() { // refinement form methods
            pn.refinementForm = {};

            pn.refinementForm.loadAvailableOptionValuesFromBackend = function(targetId, parameterName) {
                var renderer = pn.createOptionRenderer(targetId, 'value');
                $.getJSON(pn.targetServerScript, { jsonpcallback: '?', querysubject: 'availablevalues', parameter: parameterName }, function(data) {
                    renderer.render(data);
                    $(targetId).prepend('<option></option>');
                });
            };

            pn.refinementForm.loadOptions = function() {
                $('#refinementForm select').each(function() {
                    pn.refinementForm.loadAvailableOptionValuesFromBackend('#' + this.id, this.name);
                });
            };

            pn.refinementForm.resetOptions = function() {
                $("#refinementForm option:empty").each(function() {
                    this.selected = 'selected';
                });
            };


            pn.refinementForm.loadResult = function() {
                var isOptionSelected = false;
                $('#refinementForm select').each(function() {
                    if ($(this).val() !== '') {
                        isOptionSelected = true;
                    }
                });
                if (isOptionSelected) {
                    var resultUpdater = pn.createResultTableRenderer('#result', 'battery');
                    $.getJSON(pn.targetServerScript + '?' + $('#refinementForm form').serialize(),
			{ jsonpcallback: '?', querysubject: 'batteries' },
			resultUpdater.render);
                }
            };

        })();

        (function() { // refinement search methods
            pn.refinementSearch = {};
            pn.refinementSearch.filteredCategoryId = "";
            pn.refinementSearch.loadResult = function(typeLabel) {
                if (typeof (typeLabel) === 'undefined') {
                    typeLabel = $('#termTextbox').val();
                }

                if (typeLabel.length > 0) {
                    var termResultUpdater = pn.createResultTableRenderer('#result', 'battery');
                    $.getJSON(pn.targetServerScript,
			{ jsonpcallback: '?', querysubject: 'batteries', typefragment: typeLabel, category: pn.refinementSearch.filteredCategoryId },
			termResultUpdater.render);
                }
            };

        })();

        (function() { // refinement custom methods
            pn.refinementCustom = {};

            pn.refinementCustom.hideFilter = function() {
                $('#refinements, #helpHint, #resultHeader').css('display', 'none');
            };

            pn.refinementCustom.preselectCategory = function(categoryId) {
                $("#refinements > ul").tabsClick(1);
                pn.refinementTree.loadCategorySelection(categoryId);
            };

            pn.refinementCustom.preselectType = pn.refinementSearch.loadResult;

            pn.refinementCustom.preselectVariation = function(variationLabel) {
                var resultUpdater = pn.createResultTableRenderer('#result', 'battery');
                $.getJSON(pn.targetServerScript,
		{ jsonpcallback: '?', querysubject: 'batteries', variation: variationLabel },
		resultUpdater.render);
            };

        })();

        (function() { // init data renderers
            pn.clearResultWindow = function() {
                $('#result').empty();
                $('#resultArea').hide();
            };

            pn.createRenderer = function(target) {
                var that = {};
                that.target = $(target);

                that.render = function(data) { };

                return that;
            };

            pn.createElementRenderer = function(target, elementType, isFormElement) {
                isFormElement = isFormElement || false;
                var that = pn.createRenderer(target);
                that.render = function(data) {
                    that.target.empty();
                    $(data).each(function(i) {
                        if (this.name !== "") {
                            var option = $(elementType);
                            option.text(this.name);
                            if (isFormElement) {
                                option.attr('value', this.id);
                            } else {
                                option.append('<span class="id" style="display: none">' + this.id + '</span>');
                                option.click(function(event) {
                                    var target = $(this);
                                    target.siblings().removeClass('selected');
                                    target.addClass('selected');
                                    var target_offset = $("#helpHint").offset();
                                    var target_top = target_offset.top;
                                    $('html, body').animate({ scrollTop: target_top }, 500);
                                });
                            }
                            that.target.append(option);
                        }
                    });
                    pn.refinementForm.resetOptions();
                };
                return that;
            };

            pn.createOptionRenderer = function(target) {
                return pn.createElementRenderer(target, '<option>', true);
            };

            pn.createDivRenderer = function(target) {
                return pn.createElementRenderer(target, '<div class="item" />');
            };

            pn.createResultTableRenderer = function(target) {
                var that = pn.createRenderer(target);

                that.render = function(data) {
                    var capacityDe = "Kapazität K20 (Ah)";
                    var capacityEn = "Capacity K20 (Ah)";
                    if (data[0]["variation"] !== undefined && data[0]["variation"].indexOf("Bike Bull") === 0) {
                        capacityDe = "Kapazität K10 (Ah)";
                        capacityEn = "Capacity K10 (Ah)";
                    }
                    var localNames = {};
                    localNames.de = {
                        'variation': 'Produktvariante',
                        'type': 'Type',
                        'voltage': 'Nennspannung',
                        'capacity': capacityDe,
                        'colddischarge': 'Kälteprüfstrom EN (A)',
                        'layout': 'Schaltung',
                        'terminal': 'Anschlußpol',
                        'maxlength': 'Max. Länge (mm)',
                        'maxwidth': 'Max. Breite (mm)',
                        'boxheight': 'Max. Kastenhöhe (mm)',
                        'totalheight': 'Max. Gesamthöhe (mm)',
                        'miscellaneous': 'Batteriemerkmale',
                        'baseholddown': 'Bodenleiste'
                    };
                    localNames.hu = {
                        'variation': 'Productvariation',
                        'type': 'Type',
                        'voltage': 'Voltage',
                        'capacity': capacityEn,
                        'colddischarge': 'Colddischarge EN (A)',
                        'layout': 'Layout',
                        'terminal': 'Terminal',
                        'maxlength': 'Max. length (mm)',
                        'maxwidth': 'Max. width (mm)',
                        'boxheight': 'Max. boxheight (mm)',
                        'totalheight': 'Total height (mm)',
                        'miscellaneous': 'Miscellaneous',
                        'baseholddown': 'Baseholddown'
                    };
                    localNames[LANG] = {
                        'variation': "Productvariation",
                        'type': "Type",
                        'voltage': "Voltage",
                        'capacity': "Capacity K20 (Ah)",
                        'capacitySpecial': "Capacity K10 (Ah)",
                        'colddischarge': "Colddischarge EN (A)",
                        'layout': "Layout",
                        'terminal': "Terminal",
                        'maxlength': "Max. length (mm)",
                        'maxwidth': "Max. width (mm)",
                        'boxheight': "Max. boxheight (mm)",
                        'totalheight': "Total height (mm)",
                        'miscellaneous': "Miscellaneous",
                        'baseholddown': "Baseholddown"
                    };

                    // convert xml to map										 
                    var batteryMap = {};
                    $(data).each(function() {
                        for (var key in this) if (this.hasOwnProperty(key)) {
                            batteryMap[key] = batteryMap[key] || [];
                            batteryMap[key].push(this[key]);
                        }
                    });

                    // init for table outputs
                    var rowCounter = 0;
                    var row;
                    var cell;

                    // output first label column
                    var fixedContent = $('<div />');
                    fixedContent.attr("id", "fixedContent");

                    var labelTable = $('<table />');
                    labelTable.addClass("labels");

                    for (var a in localNames[LANG]) if (batteryMap.hasOwnProperty(a) && batteryMap[a] !== undefined) {

                        row = $('<tr />');
                        cell = $('<td />');

                        if (data[0]["variation"].indexOf("Bike Bull") == 0 && a == 'capacity')
                            cell.text(localNames[LANG]['capacitySpecial']);
                        else
                            cell.text(localNames[LANG][a]);

                        cell.addClass('localname');
                        row.append(cell);
                        if (rowCounter % 2 === 0) {
                            row.addClass('evenRow');
                        } else {
                            row.addClass('oddRow');
                        }
                        row.addClass(a);
                        labelTable.append(row);
                        rowCounter++;
                    }

                    // convert map to html table
                    var scrollContent = $('<div />');
                    scrollContent.attr("id", "scrollContent");

                    var resultTable = $('<table />');
                    resultTable.addClass("contents");
                    // leads to strange column widths!!! -> removed
                    //		if(data[0]["variation"].indexOf("Power Bull") != -1)
                    //			resultTable.css('width','242em');
                    //		else if(data[0]["variation"].indexOf("Starting Bull") != -1)
                    //			resultTable.css('width','770em');
                    //		else if(data[0]["variation"].indexOf("Buffalo Bull") != -1)
                    //			resultTable.css('width','295em');
                    //		else if(data[0]["variation"].indexOf("Energy Bull") != -1)
                    //			resultTable.css('width','90em');
                   

                    //--------------------------------------------- NEW BEGIN -----------------------------------
                    var categorie;
                    $('#categorySelection .selectionForm').children().each(function() {
                        if ($(this).hasClass('selected')) {
                            categorie = $(this).find('.id').html();
                        }
                    });
                    //--------------------------------------------- NEW END -----------------------------------

                    rowCounter = 0;
                    for (var a in localNames[LANG]) if (batteryMap.hasOwnProperty(a) && batteryMap[a] !== undefined) {
                        row = $('<tr />');

                        cell = $('<td />');
                        cell.text(localNames[LANG][a]);
                        cell.addClass('localname');
                        //row.append(cell);

                        var columnCounter = 0;
                        for (var b in batteryMap[a]) if (batteryMap[a].hasOwnProperty(b)) {
                            var cellText1 = '<div class="tooltip"><a class="tooltipLink" onmouseout="hideTooltip(\'toolTipContent' + a + b + '\')" onmouseover="showTooltip(\'toolTipContent' + a + b + '\')" href="#toolTipContent' + a + b + '">' + batteryMap[a][b] + ' </a><div class="ttelement" style="display: none; position: absolute; background-color: white; border: 1px solid #ECECEC;" id="toolTipContent' + a + b + '">';
                            var cellText2 = '';
                            var cellText3 = '</div></div>';
                            var cellTextFinal = '';
                            cell = $('<td />');

                            if (columnCounter++ % 2 == 0) {
                                cell.addClass('evenColumn');
                            }
                            // check if its a backup battery and add custom class
                            var startStopImg = $('<span />');
                            if (batteryMap["isBackup"][b] == "1") {
                                startStopImg.addClass('startStopImg');
                                if (rowCounter == 0)
                                    startStopImg.html('<img src="/banner/images/products/finder/plus.png" />&nbsp;');
                                cell.addClass("isBackupBattery");
                            }

                            //only render layout image, if battery variation is "Bike Bull"
                            //check if elem to render is layout -> display layout-image
                            //layout image name = type name
                            //TODO: change == to equivalent "like"
                            if (batteryMap["variation"][b].indexOf("Bike Bull") === 0) {
                                if (a == "layout") {
                                    type = batteryMap["type"][b].replace(/ /, "");
                                    //cell.html('<div id="img-' + type + '" class="layoutImage"><img src="/banner/images/products/finder/layouts/small/' + type + '.jpg" alt="' + type + '" /></div>');
                                    cellTextFinal = '<div id="img-' + type + '" class="layoutImage"><img src="/banner/images/products/finder/layouts/small/' + type + '.jpg" alt="' + type + '" /></div>';
                                } else if (a == "baseholddown") {
                                    //Bodenleiste
                                    cellText2 = localNames[LANG][a] + '<br/><table>';
                                    var content = batteryMap[a][b].substring(1).split("/");
                                    for (i = 0; i < content.length; i++) {
                                        //cellText = cellText + content[i];
                                        cellText2 = cellText2 + '<tr><th class="tooltipHeader">B ' + content[i] + '</th></tr>';
                                        //cellText2 = cellText2 + '<tr><td id="tooltipImage'+a+b+'"><img src="/banner/images/products/finder/tooltips/b' + content[i] + '.jpg"></td></tr>';
                                        cellText2 = cellText2 + '<tr><td id="tooltipImage' + a + b + '">/banner/images/products/finder/tooltips/b' + content[i] + '.jpg</td></tr>';
                                    }
                                    cellText1 = '<div class="tooltip"><a class="tooltipLink" onmouseout="hideTooltipExtended(\'toolTipContent' + a + b + '\',\'tooltipImage' + a + b + '\')" onmouseover="showTooltipExtended(\'toolTipContent' + a + b + '\',\'tooltipImage' + a + b + '\')" href="#toolTipContent' + a + b + '">' + batteryMap[a][b] + ' </a><div class="ttelement" style="display: none; position: absolute; background-color: white; border: 1px solid #ECECEC;" id="toolTipContent' + a + b + '">';
                                    cellText2 = cellText2 + '</tr></table>';
                                    cellTextFinal = cellText1 + cellText2 + cellText3;
                                    //cell.html(cellText1 + cellText2 + cellText3);
                                } else if (a == "terminal") {
                                    //Anschlusspol
                                    cellText2 = localNames[LANG][a] + '<br/><table><tr>';
                                    var content = batteryMap[a][b].split("+");
                                    for (i = 0; i < content.length; i++) {
                                        cellText2 = cellText2 + '<th class="tooltipHeader">' + content[i] + ' front</th>';
                                        cellText2 = cellText2 + '<th class="tooltipHeader">' + content[i] + ' side</th>';
                                        cellText2 = cellText2 + '<th class="tooltipHeader">' + content[i] + ' top</th>';
                                    }
                                    cellText2 = cellText2 + '</tr><tr>'
                                    for (i = 0; i < content.length; i++) {
                                        cellText2 = cellText2 + '<td id="tooltipImage1' + a + b + '">/banner/images/products/finder/tooltips/bpap' + content[i] + 'f.jpg</td>';
                                        cellText2 = cellText2 + '<td id="tooltipImage2' + a + b + '">/banner/images/products/finder/tooltips/bpap' + content[i] + 's.jpg</td>';
                                        cellText2 = cellText2 + '<td id="tooltipImage3' + a + b + '">/banner/images/products/finder/tooltips/bpap' + content[i] + 't.jpg</td>';
                                    }
                                    cellText1 = '<div class="tooltip"><a class="tooltipLink" onmouseout="hideTooltipTerminal(\'toolTipContent' + a + b + '\',\'tooltipImage1' + a + b + '\',\'tooltipImage2' + a + b + '\',\'tooltipImage3' + a + b + '\')" onmouseover="showTooltipTerminal(\'toolTipContent' + a + b + '\',\'tooltipImage1' + a + b + '\',\'tooltipImage2' + a + b + '\',\'tooltipImage3' + a + b + '\')" href="#toolTipContent' + a + b + '">' + batteryMap[a][b] + ' </a><div class="ttelement" style="display: none; position: absolute; background-color: white; border: 1px solid #ECECEC;" id="toolTipContent' + a + b + '">';
                                    cellText2 = cellText2 + '</tr></table>';
                                    cellTextFinal = cellText1 + cellText2 + cellText3;
                                    //cell.html(cellText1 + cellText2 + cellText3);
                                } else if (a == "totalheight" && batteryMap["boxheight"][b] !== undefined) {
                                    //totalheight and boxheight are the same
                                    //cell.text(batteryMap["boxheight"][b]);
                                    cellTextFinal = batteryMap["boxheight"][b];
                                } else {
                                    //cell.text(batteryMap[a][b]);
                                    cellTextFinal = batteryMap[a][b];
                                }
                                cell.html(cellTextFinal);
                            }

                            //--------------------------------------------- NEW BEGIN -----------------------------------
                            else if ((batteryMap["variation"][b].indexOf("Buffalo Bull") === 0 || batteryMap["variation"][b].indexOf("Energy Bull") === 0 || batteryMap["variation"][b].indexOf("Running Bull") === 0 || batteryMap["variation"][b].indexOf("Power Bull") === 0 || batteryMap["variation"][b].indexOf("Uni Bull") === 0 || batteryMap["variation"][b].indexOf("Starting Bull") === 0) && ((a == 'layout') || (a == 'terminal') || (a == 'miscellaneous') || (a == 'baseholddown'))) {
                                var cellText = '<div class="tooltip"><a class="tooltipLink" onmouseout="hideTooltip(\'toolTipContent' + a + b + '\')" onmouseover="showTooltip(\'toolTipContent' + a + b + '\')" href="#toolTipContent' + a + b + '">' + batteryMap[a][b] + ' </a><div class="ttelement" style="display: none; position: absolute; background-color: white; border: 1px solid #ECECEC;" id="toolTipContent' + a + b + '">';
                                switch (a) {
                                    case "layout":
                                        cellText = cellText + localNames[LANG][a] + '<br/><table><tr>';
                                        var content = batteryMap[a][b].split("+");
                                        var voltage = batteryMap['voltage'][b];
                                        for (i = 0; i < content.length; i++) {
                                            switch (voltage) {
                                                case '12':
                                                    switch (content[i]) {
                                                        case '0':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>50/D</td>';
                                                            break;
                                                        case '1':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>51/G</td>';
                                                            break;
                                                        case '3':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>61/G</td>';
                                                            break;
                                                        case '4':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>60/D</td>';
                                                            break;
                                                        case '5':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>65</td>';
                                                            break;
                                                        case '6':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>70</td>';
                                                            break;
                                                        default:
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '</b></td>';
                                                            break;
                                                    }
                                                    break;
                                                case '6':
                                                    switch (content[i]) {
                                                        case '0':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>20/D</td>';
                                                            break;
                                                        case '1':
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '/</b>21/G</td>';
                                                            break;
                                                        default:
                                                            cellText = cellText + '<td class="tooltipHeaderVariant"><b>' + content[i] + '</b></td>';
                                                            break;
                                                    }
                                                    break;
                                            }
                                        }
                                        cellText = cellText + '</tr><tr>';
                                        for (i = 0; i < content.length; i++) {
                                            cellText = cellText + '<td><img src="/banner/images/products/finder/tooltips/sb' + content[i] + '_' + voltage + '.jpg"></td>';
                                        }
                                        cellText = cellText + '</tr></table>';
                                        break;
                                    case "terminal":
                                        cellText = cellText + localNames[LANG][a] + '<br/><table><tr>';
                                        var content = batteryMap[a][b].split("+");
                                        for (i = 0; i < content.length; i++) {
                                            cellText = cellText + '<th class="tooltipHeader">' + content[i] + '</th>';
                                            if ((i == 0) && (content.length > 1)) {
                                                cellText = cellText + '<th class="tooltipHeader" style="width:5px;">+</th>';
                                            }
                                        }
                                        cellText = cellText + '</tr><tr>'
                                        for (i = 0; i < content.length; i++) {
                                            cellText = cellText + '<td><img class="ap" src="/banner/images/products/finder/tooltips/ap_' + content[i] + '.jpg"></td>';
                                            if ((i == 0) && (content.length > 1)) {
                                                cellText = cellText + '<td style="width:5px;"></td>';
                                            }
                                        }
                                        cellText = cellText + '</tr></table>';
                                        break;
                                    case "miscellaneous":
                                        cellText = cellText + localNames[LANG][a] + '<br/><table><tr>';
                                        if (batteryMap[a][b].indexOf('mG') != -1) {
                                            cellText = cellText + '<th class="tooltipHeader">mG</th>';
                                        }
                                        /*
                                        if((batteryMap[a][b].indexOf('mG')!=-1)&&(batteryMap[a][b].indexOf('GA')!=-1)){
                                        cellText = cellText + '<th class="tooltipHeader">+</th>';
                                        }*/
                                        if (batteryMap[a][b].indexOf('GA') != -1) {
                                            cellText = cellText + '<th class="tooltipHeader">GA</th>';
                                        }
                                        cellText = cellText + '</tr>';
                                        if (batteryMap[a][b].indexOf('mG') != -1) {
                                            cellText = cellText + '<td><img class="ap" src="/banner/images/products/finder/tooltips/b_mG.jpg"></td>';
                                        }
                                        /*
                                        if((batteryMap[a][b].indexOf('mG')!=-1)&&(batteryMap[a][b].indexOf('GA')!=-1)){
                                        cellText = cellText + '<td></td>';
                                        }*/
                                        if (batteryMap[a][b].indexOf('GA') != -1) {
                                            cellText = cellText + '<td><img class="ap" src="/banner/images/products/finder/tooltips/b_GA.gif"></td>';
                                        }
                                        cellText = cellText + '</tr></table>';
                                        break;
                                    case "baseholddown":
                                        cellText = cellText + localNames[LANG][a] + '<br/><table>';
                                        var content = batteryMap[a][b].substring(1).split("/");
                                        for (i = 0; i < content.length; i++) {
                                            //cellText = cellText + content[i];
                                            cellText = cellText + '<tr><th class="tooltipHeader">B ' + content[i] + '</th></tr>';
                                            cellText = cellText + '<tr><td><img src="/banner/images/products/finder/tooltips/b' + content[i] + '.jpg"></td></tr>';
                                        }
                                        cellText = cellText + '</tr></table>';
                                        break;
                                }
                                cellText = cellText + '</div></div>';
                                cell.html(cellText);
                            }
                            //--------------------------------------------- NEW END -----------------------------------


                            else {
                                cell.text(batteryMap[a][b]);
                            }
                            cell.prepend(startStopImg);
                            row.append(cell);
                        }


                        if (rowCounter % 2 === 0) {
                            row.addClass('evenRow');
                        } else {
                            row.addClass('oddRow');
                        }
                        row.addClass(a);
                        resultTable.append(row);
                        rowCounter = rowCounter + 1;
                    }
					// count results and adjust table width
                    var resultTableWidth = 45;
                    if (columnCounter > 1)
                        resultTableWidth = columnCounter * 20;
                    resultTable.css('width', resultTableWidth + 'em');
					
                    scrollContent.append(resultTable);
                    fixedContent.append(labelTable);
                    that.target.empty().append(fixedContent);
                    that.target.append(scrollContent);

                    $('#resultArea').show();
                    /*
                    //set height for both tabels .labels / .contents
                    for (var i=0; i <= $('.contents tr').size(); i++) {
                    var height = $('.contents tr:nth-child(' + i + ')').height();
                    if (height < 26) {
                    height = 26;
                    //$('.contents tr:nth-child(' + i + ') td').height(height);
                    }
                    $('.labels tr:nth-child(' + i + ') td').height(height);
                    }  
                    */
                };
                return that;
            };
        })();

    })(productnavigator);

})(jQuery);
