/*
 * Setup Yume Mypage Top menu  - Require jQuery 1.2+
 * Type:	file
 * Name: 	haym_topmenu.js
 * Date:	2008/06/03
 * @author:	Hien Nguyen [Hagin] <hiennh@von-inc.com>
 * @author:	Tuyen Cao <tuyenck@von-inc.com> 
 * @version:1.0
 * @copyright 2008 Timnhanh.com
 */
 var TopMenuID = "ymTopmenu_outer";
function TNLib_formatTopMenu(){
	// Add corner
	jQuery('#'+TopMenuID).prepend('<div id="left_menu_bar">'+
		'<div style="width:1px; height:22px; margin-top:4px"></div>'+
		'<div style="width:1px; height:22px; margin-top:2px; border-width:2px;"></div>'+
		'<div style="width:2px; height:26px; margin-top:1px; border-width:1px;"></div>'+
		'</div>');	
	jQuery('#left_menu_bar div').addClass('ymTopMenu_bgC ymTopMenu_borderC');
	jQuery('#left_menu_bar div:first').removeClass('ymTopMenu_bgC ymTopMenu_borderC').addClass('ymTopMenu_fakeBorderC');	
	jQuery('#'+TopMenuID+' div:last').after('<div id="right_menu_bar">'+
		'<div style="width:2px; height:26px; margin-top:1px; border-width:1px;"></div>'+
		'<div style="width:1px; height:22px; margin-top:2px;border-width:2px;"></div>'+	
		'<div style="width:1px; height:22px; margin-top:4px"></div>'+
		'</div>');
	jQuery('#right_menu_bar div').addClass('ymTopMenu_bgC ymTopMenu_borderC');
	jQuery('#right_menu_bar div:last').removeClass('ymTopMenu_bgC ymTopMenu_borderC').addClass('ymTopMenu_fakeBorderC');
	
	// Add vertical line
	jQuery('#ymTopmenu_bar a').not(':last').after('<span class="ymTopMenu_vline ymTopMenu_fakeBorderC"></span>');
	jQuery('a.ymTopMenu_selected').next().css('background','none');
	jQuery('a.ymTopMenu_selected').prev().css('background','none');
	
	// Change active color for corner
	jQuery('#ymTopmenu_bar a:first').css({'borderLeft':'none','width':'74px'});
	jQuery('#ymTopmenu_bar a:last').css({'borderRight':'none'});
	//jQuery('#ymTopmenu_bar a:last').css({'borderRight':'none','width':'74px'});
	//jQuery('#ymTopmenu_bar a:first').css({'borderLeft':'none','paddingLeft':'17px'});
	//jQuery('#ymTopmenu_bar a:last').css({'borderRight':'none','paddingRight':'17px'});	
	if ((jQuery('#ymTopmenu_bar a:first').attr('class') != null) && (jQuery('#ymTopmenu_bar a:first').attr('class').match("selected"))) {	
		jQuery('#left_menu_bar div').not(':first').addClass('ymTopMenu_selected');
	}
	else { jQuery('#left_menu_bar div').not(':first').removeClass('ymTopMenu_selected'); }	
	if ((jQuery('#ymTopmenu_bar a:last').attr('class') != null) && (jQuery('#ymTopmenu_bar a:last').attr('class').match("selected"))) 	{		
		jQuery('#right_menu_bar div').not(':last').addClass('ymTopMenu_selected');
	}
	else { jQuery('#right_menu_bar div').not(':last').removeClass('ymTopMenu_selected'); }

	// Setup arrow position
	if (jQuery('a.ymTopMenu_selected').attr('class') != null){
		jQuery('#ymTopmenu_bar').append('<div id="menu_arrow">'+
				'<div id="arrow"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div style="width:1px;"></div></div></div>');
		jQuery('#arrow div').addClass('ymTopMenu_selected ymTopMenu_borderC');
		jQuery('#arrow div:last').removeClass('ymTopMenu_selected ymTopMenu_borderC').addClass('ymTopMenu_fakeBorderC').css('border','none');
		jQuery('#arrow div:first').css('border','none');
		
		var widArrow = jQuery("#menu_arrow").innerWidth();
		var step = widArrow;
		jQuery('#arrow div').each(function(){
		   jQuery(this).width(step+'px');
		   step = step-2;
		});	
		left_width_actBtn =  jQuery('#ymTopmenu_bar').offset().left - jQuery('a.ymTopMenu_selected').offset().left;
		width_actBtn = Math.round((jQuery('a.ymTopMenu_selected').outerWidth() - widArrow) / 2 ) ;	
		jQuery('#menu_arrow').css('left',width_actBtn - left_width_actBtn );
	}
};
/*
* Setup Yume create tabcolor - Require jQuery 1.2+
* Type:	function
* Name: 	TNlib_creatColorTab.js
* Date:	13/11/2008
* @author:	tridn <tridn@von-inc.com> 
* @version:1.0
* @copyright 2008 Timnhanh.com
* update 27/11/08
*/
 function TNlib_creatColorTab(boundId){
	var arrCont=new Array();
	var arrowH=6;
	var arrowW=arrowH*2+1;
	var arrItem=$('#'+boundId+' li');
	$('#'+boundId+' .arrow').remove();
		$('#'+boundId).append('<div id="tempbox"></div>');
	var boxarrow	=document.createElement('div');
		boxarrow.className='arrow';
		$(boxarrow).width(arrowW);
		$(boxarrow).height(arrowH+1);
		$('#tempbox').append(boxarrow);
	// ve arrow
	var valColor;
	for(i=arrowH;i>=0;i--){
		var boxcontain	=document.createElement('div');
		if(i>0){
			$(boxcontain).css({'width':(i*2+1)-2+'px',
						  'height':'1px',
						  'margin':'auto',
						  'overflow':'hidden'});
			$(boxcontain).addClass("ymTopMenu_selected ymTab_borderC");
			valColor=$(boxcontain).css('border-left-color')||$('.ymTab_borderC').css('border-left-color');
		}
		else{
			$(boxcontain).css({'width':'1px',
						  'height':'1px',
						  'margin':'auto',
						  'border':'none',
						  'overflow':'hidden'});
			$(boxcontain).css('backgroundColor',valColor);
		}
		$('#'+boundId+' .arrow').append(boxcontain);	
	}
	$('#'+boundId+' li').addClass("ymTab_borderC ymTopMenu_bgC");
	$('#'+boundId+' .active').addClass("ymTopMenu_selected");
	$(arrItem).each(function(){
		$(this).append($('#tempbox').html());
		$(this).children('.arrow').css({'left':$(this).width()/2});
		if($(this).attr('forcontid')) arrCont.push($(this).attr('forcontid'));
		$(this).click(function(){
			$('#'+boundId+' .active').removeClass("active");
			$('#'+boundId+' li').removeClass("ymTopMenu_selected");
			$(this).addClass("active ymTopMenu_selected");
			for(i=0;i<arrCont.length;i++){
				if(arrCont[i]!=$(this).attr('forcontid')) $('#'+arrCont[i]).hide();
			}
			if($(this).attr('forcontid')) {
				if($('#'+$(this).attr('forcontid')).attr('id')){
					$('#'+$(this).attr('forcontid')).show();
				}
			}
			return false;
		})
	});
	for(i=0;i<arrCont.length;i++){
		if(arrCont[i]!=$('#'+boundId+' .active').attr('forcontid')) $('#'+arrCont[i]).hide();
	}
	$('#tempbox').remove();
}
$(document).ready(function(){
	TNLib_formatTopMenu();
	TNlib_creatColorTab('colortab1');
});