jQuery().ready(function()
{	
	$('.box.menu div').accordion({
		autoheight: false,
		alwaysOpen: false,
		active: '.selected',
		selectedClass: 'active',
		header: "span"
	});
	
	$('#bae').accordion({
		autoheight: false,
		alwaysOpen: false,
		active: '.selected',
		selectedClass: 'active',
		header: "table.clicktable"
	});
	
	$('.tabbed_information .tabs a').click(function() {
		$('.tabbed_information .tabs a').removeClass('active');
		$(this).addClass('active');
		
		if ($('.tabbed_information .tabs a:first').hasClass('active'))
		{
			$('#last_news').show();
			$('#most_view').hide();
		}
		else
		{
			$('#last_news').hide();
			$('#most_view').show();
		}
	});
	
	$('#header form input').click( function() {
		$(this).val('');
	});
});

/**
* LEFT MENU GENERATION
*/

var LeftMenu = function(node)
{
	this.node = node;
	this.m_NavPath = g_navNode_Path;
};

LeftMenu.prototype = {

	display: function()
	{


		for(var i = 0; i < this.node.m_subNodes.length; i++)
		document.write(this._generate_left_menu(this.node.m_subNodes[i]));
	},

	_generate_left_menu: function(node)
	{

		var menu_string = '';

		var is_node_selected = false;

		for(var i = 0; i < this.m_NavPath.length; i++)
		{
			if(node.m_id == this.m_NavPath[i]) {
				is_node_selected = true;
			}
		}

		var subnodes_length = node.m_subNodes.length;
		if(subnodes_length)
		{

			menu_string += '<span' + (is_node_selected ? ' class="selected"' : '') + '>' + node.m_label + '</span>';
			menu_string += '<div>';

			for(var i = 0; i < subnodes_length; i++) {
				var inner_node = node.m_subNodes[i];
				menu_string += this._generate_left_menu(inner_node);
			}

			menu_string += '</div>';
		}
		else {
			menu_string += '<a href="' + node.m_href + '"' + (is_node_selected ? ' class="active"' : '') + '>' + node.m_label + '</a>';
		}

		return menu_string;
	}
};



function BNB_Vertical_Menu_Bar_FindNode (node)
{
 var retNode = null;
 var m_StartLevel = 1;

 if (node.m_level == m_StartLevel && node.m_id == g_navNode_Path[m_StartLevel])
 {
  retNode = node;
 }
 else
 if (node.m_level < m_StartLevel)
 {
  for (var count = 0; count < node.m_subNodes.length; count++)
  {
   retNode = BNB_Vertical_Menu_Bar_FindNode (node.m_subNodes[count]);
   
   if (retNode != null)
    break;
  }
 }
 return retNode;
}


/**
 * BREADCRUMB GENERATION
 */
function Breadcrumb(g_navNode_Root)
{
	this.root_node = g_navNode_Root;
	this.m_NavPath = g_navNode_Path;
}

Breadcrumb.prototype = {

	display : function ()
	{
		this.display_node(this.root_node);
		//document.write ('<a href="javascript:window.print();" class="print_link">' + intPrintTitle + '</a>');

	},

	display_node : function(node)
	{
		var level = node.m_level;
		var bExpand = false;

		var ds = new Array();
		var di = 0;

		if (this.m_NavPath.length > 0 && node.m_level < this.m_NavPath.length)
		{
			if (this.m_NavPath[node.m_level] == node.m_id)
				bExpand = true;
		}

		if (bExpand)
		{
			if (this.m_NavPath.length > 0 && node.m_level < this.m_NavPath.length-1)
			{
				href = node.m_level < 2 ? node.m_href : 'javascript:;';
				ds[di++] = '<li><a href="' + href + '">' + node.m_label + '</a> <img src="/bnbweb/fragments/bnb_iclude_fragment/images/icons/breadcrumb_arrow_icon.gif" alt="" /></li>';
			}
			else {
				ds[di++] = '<li class="last">' + node.m_label + '</li>';
			}

			document.write(ds.join(''));	// Write out the "live" path only

			// expand sub-levels (if any)
			for (var i = 0; i < node.m_subNodes.length; i++){
				this.display_node(node.m_subNodes[i]);
			}
		}
	}
}


/**
 * BREADCRUMB GENERATION
 */
function Breadcrumb_Specific(g_navNode_Root, current_Node_ID)
{
	this.root_node = g_navNode_Root;
	this.my_Current_Node_ID=current_Node_ID;
}

Breadcrumb_Specific.prototype = {

	display : function ()
	{
		this.display_node(this.root_node, new Array());
	},

	display_node : function(node, labels)
	{
	
			if (this.my_Current_Node_ID == node.m_id) {
				var ds = new Array();
				var di = 0;
				for (var i = 0; i < labels.length; i++){
					ds[di++] = labels[i] + '&nbsp;&nbsp;<img src="/bnbweb/fragments/bnb_iclude_fragment/images/icons/breadcrumb_arrow_icon.gif" alt="" />&nbsp;&nbsp;';
				}
				ds[di++] = node.m_label;
				document.write(ds.join(''));
				
				return;
			}


		for (var i = 0; i < node.m_subNodes.length; i++){
				var appendedLabels = labels.slice();
				appendedLabels[appendedLabels.length ] = node.m_label;
				this.display_node(node.m_subNodes[i], appendedLabels);
		}

	}
}

$(function() {
 $('.table_scroll table').each(function(key, table) {
  if (table.offsetWidth <= 510) {
   table.parentNode.className = table.parentNode.className.replace('table_scroll', '');
  }
 });
 $('.extended .table_scroll table').each(function(key, table) {
  if (table.offsetWidth <= 720) {
   table.parentNode.className = table.parentNode.className.replace('table_scroll', '');
  }
 });
});
