// Constants, override in calling HTML file after including tabs.js
var HIDE_TAB_BUTTON_TEXT = true;
var tab_click_callback = {};
var tab_buttons_initialised = {};
var tab_replace_anchor = {};
$(function(){
/*
if(tab_buttons_initialised){
return;
}
*/
initialise_tabs();
});
function initialise_tabs(){
var tab_button_text, tab_to_show;
var tab_containers = $('.tabs');
tab_containers.each(function(i, el){
//			console.debug(tab_buttons_initialised[el.id], el.id)
if(tab_buttons_initialised[el.id]){
return;
}
// Build the tab button list
$(this).prepend('<ul class="tab-buttons" id="tab-buttons-' + i + '"></ul>');
if($(this).hasClass('compare')){
}
var tab_content_elements = $(this).find('.tab-content');
if(tab_content_elements.length == 0){
return;
}
tab_content_elements.each(function(){
// Get tab button text & hide the originals
if(HIDE_TAB_BUTTON_TEXT){
tab_button_text = $(this).find('.tab-button-text').text();
$(this).find('.tab-button-text').remove();
}
$('#tab-buttons-' + i).append('<li id="tab-buttons-' + $(this)[0].id + '"><a href="#' + tab_text_to_id(tab_button_text) + '">' + tab_button_text + '</a></li>');
$('#tab-buttons-' + $(this)[0].id).click(tab_button_click);
// Hide the tab contents
$(this).hide();
// Assign a new ID to the tab contents so that it doesn't jump down
$(this)[0].id = 'tab-' + $(this)[0].id;
});
tab_to_show = null;
// Choose which tab to show
if(location.hash != '' ){
var hash_id = location.hash.replace('#', '');
}
if(location.hash != '' && $('#tab-' + hash_id).hasClass('tab-content')){
// Show the tab specified in the location
tab_to_show = 'tab-' + hash_id;
}else if($(this).find('.tab-content.tab-visible').length > 0){
// Show first tab with tab-visible class
tab_to_show = $(this).children('.tab-content.tab-visible')[0].id;
}else{
// Show the first tab
tab_to_show = $(this).children('.tab-content')[0].id;
}
if(tab_to_show != null){
show_tab(tab_to_show);
}
});
}
function tab_button_click(e){;
var tab_id = $(this)[0].id.replace('tab-buttons-', '');
show_tab('tab-' + tab_id);
var tab_content = $('#tab-' + tab_id);
var container = tab_content.parent('.tabs');
if(tab_replace_anchor[container[0].id]){
location.href = '#' + tab_id;
}
if (document.getElementById('RangeSlider')){
checkForSlider();
}
return false;
}
function show_tab(id){
var tab_content = $('#' + id);
var container = tab_content.parent('.tabs');
container.children('.tab-content:visible').each(function(){
$(this).hide();
});
tab_content.show();
container.children('.tab-buttons').find('li.current').each(function(){
$(this).removeClass('current');
});
$('#tab-buttons-' + id.replace('tab-', '')).addClass('current');
$('#tab-buttons-' + id.replace('tab-', '')).find('a')[0].blur();
if(tab_click_callback[container[0].id] != null){
tab_click_callback[container[0].id].call(this, id);
}
//For MQC 2363
populate();
}
function tab_text_to_id(text){
return text.replace(/[^a-z0-9]+/gi, '-').replace(/-{2,}/gi, '-').toLowerCase();
}

