var busy = false;
$(document).ready(function() {
    $("#menu li").hover(
		function() {
		    if ($(this).find('ul').attr('class') == 'sub')
		        $(this).find('ul').addClass('hover'); //attr('class','hover');
		    //$(this).attr('class','active hover');
		},
		function() {
		    if ($(this).find('ul').attr('class') != 'active')
		        $(this).find('ul').removeClass('hover');
		    /*if($(this).find('div').attr('class')!='active')
		    $(this).find('div').attr('class','normal');
		    $(this).attr('class','');*/
		}
	);

    $('.newsNav a:not(.newsTitle a)').click(function() {
        if (!busy) {
            busy = true;
            $('.newsNav a:not(.newsTitle a)').removeClass("active");
            $(this).addClass("active");
            $('.newsNav ul').hide();
            $('#' + $(this).attr('longdesc')).show(500);
            busy = false;
        }
        return false;
    });

    $('#listFocus4u').hide();

    $('.member').click(function() {
        getMemberDetail(LANG, $(this).attr('longdesc'))
    });

//    $("#s").focus(function() {
//        $('#SEARCH').addClass('hover');
//    });
    $("#s").blur(function() {
        setTimeout(function() {
//            $('#SEARCH').removeClass('hover');
            $('#autoComplete').removeClass('hover');
        }, 500)
    });

    initSifr();

    //$('#infoContent_2').removeClass('active');
    //$('#infoContent_3').removeClass('active');
})
function showAutoComplete(flag)
{
	if(flag){
		$('#searchBar').addClass('active')
		$('#autoComplete').addClass('show')
		$.ajax({
		    type: "GET",
		    url: PATH_LANG + 'xml/Search?s=' + $('#s').val(),
		    data: {},
		    dataType: "html",
		    success: function(html) {
		        $('#autoComplete').html(html);
		        $('#loadingicon').css('display', 'none');
		    }
		});
	}
	else
	{
		$('#searchBar').removeClass('active')
		$('#autoComplete').removeClass('show')
	}
	
}
function showToolTip(hover, obj, flag)
{
	if(flag)
	{
		$('#'+obj).addClass('active');
		$('#'+hover).addClass('hover');
	}
	else
	{
		$('#'+obj).removeClass('active');
		$('#'+hover).removeClass('hover');
	}
}

function mOn(obj) {
	var ext = obj.src.slice(-3);
	if(obj.src.indexOf('-on.'+ ext)==-1){
		obj.src=obj.src.replace('.'+ ext,'_o.'+ ext);
	}
}
function mOut(obj) {
	var ext = obj.src.slice(-3)
	obj.src=obj.src.replace('_o.'+ext,'.'+ext)
}

function printme() {
	var objOut = document.getElementById("output");
	var out = objOut.innerHTML;

	var wh = window.open("","wh","width=640px,height=480px,scrollbars=yes");
	wh.document.open();
	var output = '<link href="' + PROJECT_URL + 'css/print.css" rel="stylesheet" type="text/css">';
	output = '<html><head>'+output+'</head><body>'+out.replace('<object','<!--object').replace('/object>','/object-->')+'</body></html>';
	output += '<'+'script type="text/javascript">';
	output += 'setTimeout("window.print()",2000);';	
	output += '</'+'script>';
	wh.document.writeln(output);
	wh.document.close();
}

function showTabContent(el,tabIndex, total) {
    for (var i = 1; i < total+1; i++) {
        $('#infoContent_' + i).removeClass('active');
        $('.tabButtons li a').removeClass('hover');
    }

    $('#infoContent_' + tabIndex).addClass('active');    
    $(el).find('a').addClass('hover');
}

function getMemberDetail(lang,perma) {
    $.ajax({
        type: "GET",
        url: PATH_LANG + 'xml/GetMemberDetail?langId=' + lang + '&perma=' + perma,
        data: {},
        dataType: "html",
        success: function(content) {
            $('#memberDetail').html(content);            
        }
    });
}