var arrowimages={down:['downarrowclass', 'images/arrow-down.gif', 25], right:['rightarrowclass', 'images/arrow-right.gif']}
var tvbHeader = {
	changeSearchSelection : function (id, name) {
		$("#global_topnav_selected_search_type").html(name);
		$("#selSS").attr("value", id);
		$("#global_topnav_selected_search_type_list").fadeOut(tvbHeaderMenu.fadesettings.outduration);
	}
}
var tvbHeaderMenu={
	fadesettings: {overduration: 350, outduration: 100}, //duration of fade in/ out animation, in milliseconds
	buildmenu:function(menuid, arrowsvar){
		jQuery(document).ready(function($){
			var $mainmenu=$("#"+menuid+">ul")
			var $headers=$mainmenu.find("ul").parent()
			$headers.each(function(i){
				var $curobj=$(this)
				var $subul=$(this).find('ul:eq(0)')
				this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
				this.istopheader=$curobj.parents("ul").length==1? true : false
				$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
				$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
					'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
					+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
					+ '" style="border:0;" />'
				)
				$curobj.hover(
					function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					$targetul.css({left:menuleft+"px"}).fadeIn(tvbHeaderMenu.fadesettings.overduration)
					},
					function(e){
					$(this).children("ul:eq(0)").fadeOut(tvbHeaderMenu.fadesettings.outduration)
					}
				)
			})
			$mainmenu.find("ul").css({display:'none', visibility:'visible'})
		})
	}
}

function clearBlank(what)
{
	if (what.value == '輸入搜尋字')
	{
		what.value = "";
	}
}

function fillBlank(what)
{
	if (what.value == '')
	{
		what.value = "輸入搜尋字";
	}
}

function validate(what)
{
	if (what.q.value == "輸入搜尋字")
	{
		alert("請輸入搜尋字");
		return false;
	}
}

function prefillQ(what)
{
	if (what) document.getElementById("global_topnav_search_text").value = what;
}

function preselectSS(what)
{
	if (what == 1) document.getElementById("selSS").selectedIndex = 0;
	else if (what == 2) document.getElementById("selSS").selectedIndex = 1;
	else if (what == 3) document.getElementById("selSS").selectedIndex = 2;
	else document.getElementById("selSS").selectedIndex = 3;
}
    
function selectChange (obj)
{
	var val = 0;
	$("#selSS").attr("value", obj[obj.selectedIndex].value);
}
    
function topnav_init ()
{
	try{
		if($.browser.msie && parseFloat($.browser.version) <= 6.0 )
		{
			$("#global_topnav_select").css("fontSize", "12px");
			$("#global_topnav_search_text").css("marginTop", "4px");
			$("#global_topnav_search_text").css("marginLeft", "0px");
			$("#global_topnav_search_text").css("height", "14px");
		}
		
		$("#global_topnav_select_container").css("display", "none");
		$("#global_topnav_search_ul").css("display", "block");
		
		tvbHeaderMenu.buildmenu("global_topnav_search_list", arrowimages);
		var select_value = $("#selSS").attr("value");
		
		$("#global_topnav_select").find("option").each(function(i){
			if(select_value == $(this).attr("value"))
			{
				$("#global_topnav_selected_search_type").html($(this).html());
			}
		});
		
		var selected_index = parseInt(select_value)-1;
		if(selected_index < 0)
			select_value = 3;
			
		document.getElementById("global_topnav_select").options[selected_index].selected;
		
		switch($.url.attr("host"))
		{
			case "forum.tvb.com":
				document.getElementById("global_topnav_select").options[2].selected;
				tvbHeader.changeSearchSelection(3, '討論區&nbsp;');
			break;
			case "blog.tvb.com":
				document.getElementById("global_topnav_select").options[1].selected;
				tvbHeader.changeSearchSelection(2, '藝人Blog');
			break;
		}
	}catch(e){}
} 