function StartAnimation(){
	$('#leftnav .menu_item:first').addClass('menu_first');
	$('#leftnav .menu_item:last').addClass('menu_last');
	$('#leftnav .submenu').find('.submenu_item:first').addClass('submenu_first');
	$('#leftnav .submenu').find('.submenu_item:last').addClass('submenu_last');
	$('#leftnav .menu_item.has_submenu').append('<div class="arrow"></div>').click(function() {
		var submenu = $(this).next('.submenu');
		var link = this;
		$('#leftnav .submenu').not(submenu).slideUp();
		$('#leftnav .menu_item.has_submenu').find('.arrow_down').removeClass('arrow_down').addClass('arrow');
		if ($(submenu).is(':visible')) {
			$(submenu).slideUp();
		} else {
			$(link).find('.arrow').removeClass('arrow').addClass('arrow_down');
			$(submenu).slideDown();
		}
	});
	$('#leftnav a').each(function() {
		if ($(this).hasClass('active')) {
			if ($(this).hasClass('menu_item'))
				$(this).addClass('menu_active');
			if ($(this).hasClass('submenu_item')) {
				$(this).addClass('submenu_active').parent('.submenu').prev('.menu_item').click();
			}
		}
	});
}

function SetupItemActive(hasActiveItem, link){
	var strHref = window.location.href;
	var strActiveClass = '';
	if(hasActiveItem == false){
		if(strHref.toLowerCase().indexOf(link.toLowerCase()) > -1){
			strActiveClass = ' active';
		}
	}
	return strActiveClass;
}

function BuildLeftNavigation(xmlurl){
	/*<h3>
	Support</h3>
	<a class="menu_item has_submenu" href="javascript:void(0)">Product Support</a>
	<div class="submenu">
	<a class="submenu_item" href="javascript:void(0)">What&#8217;s New</a> <a class="submenu_item"
		href="javascript:void(0)">Select Phone</a> <a class="submenu_item" href="javascript:void(0)">
		Select Phone</a>
	</div>
	<a class="menu_item has_submenu" href="javascript:void(0)">a b c d e f g h i j k l m
		n o p q r s t u v w x y z</a>
	<div class="submenu">
	<a class="submenu_item" href="javascript:void(0)">a b c d e f g h i j k l m n o p q
			r s</a> <a class="submenu_item" href="javascript:void(0)">Support via e-Mail</a>
	</div>
	<a class="menu_item active" href="javascript:void(0)">Warranty</a> <a class="menu_item"
		href="javascript:void(0)">Bulletin Board</a> <a class="menu_item has_submenu" href="javascript:void(0)">
		a b c d e f g h i j k l m n o p q r s t u v w x y z</a>
	<div class="submenu">
	<a class="submenu_item" href="javascript:void(0)">a b c d e f g h i j k l m n o p q
		r s</a> <a class="submenu_item" href="javascript:void(0)">Support via e-Mail</a>
	</div>
	<div class="end_cap">
	</div>*/
	var strLeftHtml = "";
	var blnHasActiveItem = false;
	
	$.ajax({  
		dataType:'xml',
		url: xmlurl,
		type:'get',  
		success: function(oXml) {
			
			var x = oXml.getElementsByTagName('root');
			//get title & bind title
			var strTitle = x[0].getAttribute('type')
			strLeftHtml += '<h3>' + strTitle + '</h3>';
			
			var intTotalItems = x[0].getElementsByTagName("images").length;
			if(x != null){
				for(i = 0; i < intTotalItems; i ++ )
				{  
					//alert(i);
					var tabItem = x[0].getElementsByTagName("images")[i];
					if(tabItem != null){
						var strTabName = tabItem.getAttribute('type');
						var strLink = 'javascript:void(0)';
						if(tabItem.getAttribute('link') != null){
							strLink = tabItem.getAttribute('link');
						}
						var blnHasSubItem = false;
						var intSubItemCount = tabItem.getElementsByTagName("Product").length;
						if(intSubItemCount > 0){
							blnHasSubItem = true;
						}
						
						var strActiveClass = SetupItemActive(blnHasActiveItem , strLink);
						if(strActiveClass != ''){
							blnHasActiveItem = true;
						}
						
						if(blnHasSubItem == true){
							strLeftHtml += '<a class="menu_item has_submenu" href="' + strLink + '">' + strTabName + '</a>';
							strLeftHtml +='<div class="submenu">';
							
							var tabSubItem = tabItem.getElementsByTagName("Product");
							for(j=0; j<intSubItemCount; j++){
								var strSubItemName = tabSubItem[j].getAttribute('name');
								var strSubItemLink = tabSubItem[j].getAttribute('link');
								var strSubActiveClass = SetupItemActive(blnHasActiveItem , strSubItemLink);
								if(strSubActiveClass != ''){
									blnHasActiveItem = true;
								}
								strLeftHtml += '<a class="submenu_item' + strSubActiveClass + '" href="' + strSubItemLink + '">';
								strLeftHtml += strSubItemName + '</a>';
							}
							strLeftHtml += '</div>';
						}else{							
							strLeftHtml += '<a class="menu_item' + strActiveClass + '" href="' + strLink + '">' + strTabName + '</a>';
						}
					}
				}
				
				strLeftHtml += '<div class="end_cap"></div>';
			}
			
			if(strLeftHtml != ''){
				$('#leftnav').html(strLeftHtml);
				$('#leftnav').css('background-image','url(images/leftnav_edge_bg.gif)');
				StartAnimation();
			}
		}
	});
}