function CreateTab() {
    var i, btn, content;
    var args = CreateTab.arguments;
    for(i=0; i<args.length; i+=2) {
	btn = $('#'+args[i]);
	content = $('#'+args[i+1]);
	if( i!=0 )
	    content.css('display', 'none');
	btn.click( function() {
	    var j;
	    for(j=0; j<args.length; j+=2) {
		$('#'+args[j+1]).css('display', args[j]==$(this).attr('id') ? 'block' : 'none');
	    }
	    return false;
	} );
    }
}
function CreateTabButtonImage() {
    var i;
    var args = CreateTabButtonImage.arguments;
    var choose = 0;
    function create_one(i) {
	var img = $('#'+args[i]);
	var id = args[i];
	img.mouseover( function() { img.attr('src', i==choose ? args[i+1] : args[i+3]); } );
	img.mouseout( function() { img.attr('src', i==choose ? args[i+1] : args[i+2]); } );
	img.click( function() {
	    if( id == 'guild_new' || id == 'guild_pending' ){
            $('#listtop').css("background-image","url(//g.mwsrv.com/bigtwo/images/per_list_top.gif)");
            $('#listrepeat').css("background-image","url(//g.mwsrv.com/bigtwo/images/per_list_repeat.gif)");
            $('#listbottom').css("background-image","url(//g.mwsrv.com/bigtwo/images/per_list_bottom.gif)");
	    $('table tr[bgcolor=#dde8ff], table td[bgcolor=#dde8ff]').attr('bgcolor', '#d4f4df');
	    $('.tabletext').css('background-color','#8DD677');
	    }else{
            $('#listtop').css("background-image","url(//g.mwsrv.com/bigtwo/images/list_top.gif)");
            $('#listrepeat').css("background-image","url(//g.mwsrv.com/bigtwo/images/list_repeat.gif)");
            $('#listbottom').css("background-image","url(//g.mwsrv.com/bigtwo/images/list_bottom.gif)");
	    $('table tr[bgcolor=#dde8ff], table td[bgcolor=#d4f4df]').attr('bgcolor', '#dde8ff');
	    $('.tabletext').css('background-color','#88AEFF');
	    }
	    choose = i;
	    var j;
	    for(j=0; j<args.length; j+=4) {
		$('#'+args[j]).attr('src', j==choose ? args[j+1] : args[j+2]);
	    }
	} );
    }
    for(i=0; i<args.length; i+=4) {
	create_one(i);
    }
}
$(document).ready(function(){
var guild_prefix = '//g.mwsrv.com/bigtwo/images/';
$('#freezone'). unbind('click').click(function(){popup('/bigtwo/lobby.php?region=0' + _index_passin);return false;});
$('#newzone').unbind('click').click(function(){if( _index_logined ) { popup('/bigtwo/lobby.php?region=1' + _index_passin); } else { alert('需登入後才能進入'); } return false;});
$('#clubzone').unbind('click').click(function(){if( _index_logined ){ popup('/bigtwo/lobby.php?region=2' + _index_passin); } else { alert('需登入後才能進入'); } return false;});
$('#diamondzone').unbind('click').click(function(){if( _index_logined ){  popup('/bigtwo/lobby.php?region=3' + _index_passin); } else { alert('需登入後才能進入'); } return false;});
$('#heartzone').unbind('click').click(function(){if( _index_logined ){  popup('/bigtwo/lobby.php?region=5' + _index_passin); } else { alert('需登入後才能進入'); } return false;});
CreateTabButtonImage(
"userimg","http://gcd.mwsrv.com/bigtwo/images/tab_userimg_on.gif","http://gcd.mwsrv.com/bigtwo/images/tab_userimg_out.gif","http://gcd.mwsrv.com/bigtwo/images/tab_userimg_on.gif",
"player","http://gcd.mwsrv.com/bigtwo/images/tab_player_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_player_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_player_on.gif",
"article","http://gcd.mwsrv.com/bigtwo/images/tab_article_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_article_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_article_on.gif"
);
CreateTabButtonImage(
    "personal_award", "//g.mwsrv.com/bigtwo/images/personal_tab_3_on.gif", "//g.mwsrv.com/bigtwo/images/personal_tab_3_out.gif",
        "//g.mwsrv.com/bigtwo/images/personal_tab_3_on.gif",
    "total1", "http://gcd.mwsrv.com/bigtwo/images/personal_tab_1_on.gif", "http://gcd.mwsrv.com/bigtwo/images/personal_tab_1_out.gif", "http://gcd.mwsrv.com/bigtwo/images/personal_tab_1_on.gif",
    "daily1", "http://gcd.mwsrv.com/bigtwo/images/personal_tab_2_on.gif", "http://gcd.mwsrv.com/bigtwo/images/personal_tab_2_out.gif", "http://gcd.mwsrv.com/bigtwo/images/personal_tab_2_on.gif"
);
CreateTabButtonImage(
    "total3", "http://gcd.mwsrv.com/bigtwo/images/tab_map_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_map_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_map_on.gif",
    "total2", "http://gcd.mwsrv.com/bigtwo/images/tab_hunter_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_hunter_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_hunter_on.gif",
    "total4", "http://gcd.mwsrv.com/bigtwo/images/tab_achieve_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_achieve_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_achieve_on.gif"
);
CreateTabButtonImage(
    "announce_tab_button_img", "http://gcd.mwsrv.com/bigtwo/images/tab_post_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_post_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_post_on.gif",
    "banned_user_tab_button_img", "http://gcd.mwsrv.com/bigtwo/images/tab_banned_on.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_banned_out.gif", "http://gcd.mwsrv.com/bigtwo/images/tab_banned_on.gif"
);
CreateTabButtonImage(
    "item1_tab_button_img", "http://gcd.mwsrv.com/bigtwo/images/newitemtab1_on.gif", "http://gcd.mwsrv.com/bigtwo/images/newitemtab1_out.gif", "http://gcd.mwsrv.com/bigtwo/images/newitemtab1_on.gif",
    "item2_tab_button_img", "http://gcd.mwsrv.com/bigtwo/images/newitemtab2_on.gif", "http://gcd.mwsrv.com/bigtwo/images/newitemtab2_out.gif", "http://gcd.mwsrv.com/bigtwo/images/newitemtab2_on.gif"
);
CreateTab("map_task_tab_button", "map_task_tab", "hunter_tab_button", "hunter_tab","achieve_tab_button","achieve_tab");
CreateTab("announce_tab_button", "announce_tab","banned_user_tab_button", "banned_user_tab");
CreateTab("userimg_tab_button","userimg_tab","photo_tab_button","photo_tab","diary_tab_button","diary_tab");
//CreateTab('total1_tab_button', 'total1_tab', 'daily1_tab_button', 'daily1_tab');
// CreateTab("guild_tab_button", "guild_tab","newguild_tab_button","newguild_tab","mjrank_tab_button","mjrank_tab");
CreateTab("item1_tab_button","item1_tab","item2_tab_button","item2_tab");
/* guild */
CreateTab("personal_award_tab_button","personal_award_tab","mjrank_tab_button","mjrank_tab");
CreateTabButtonImage(
        "guild_award",guild_prefix+"rank_tab_1_on.gif",guild_prefix+"rank_tab_1_out.gif",guild_prefix+"rank_tab_1_over.gif",
        "guild_level",guild_prefix+"rank_tab_2_on.gif",guild_prefix+"rank_tab_2_out.gif",guild_prefix+"rank_tab_2_over.gif",
        "guild_man",guild_prefix+"rank_tab_3_on.gif",guild_prefix+"rank_tab_3_out.gif",guild_prefix+"rank_tab_3_over.gif",
        "guild_new",guild_prefix+"rank_tab_4_on.gif",guild_prefix+"rank_tab_4_out.gif",guild_prefix+"rank_tab_4_over.gif",
        "guild_pending",guild_prefix+"rank_tab_5_on.gif",guild_prefix+"rank_tab_5_out.gif",guild_prefix+"rank_tab_5_over.gif"
);
CreateTab("guild_award_tab_button","guild_award_tab","guild_level_tab_button","guild_level_tab","guild_man_tab_button","guild_man_tab","guild_new_tab_button","guild_new_tab","guild_pending_tab_button","guild_pending_tab");
$("#total1,#daily1").click(function(){
$("#personal_award_tab").css('display','none');
$("#mjrank_tab").css('display','block');
});

//XXX 用來判斷特殊版位要登入才能進去    
$("a[href*='Dmemverify']").click(function(){
  if( !_index_logined ){
    alert('需登入後才能進入');
    return false;
  }
});

$("#switch1").click(function(){
switchmode(1);
return false;
});

$("#switch2").click(function(){
switchmode(2);
return false;
});

});

function switchmode(num){
if( num == 1 ){
        close_num = 2;
        $('#mjrank_tab').hide();
}
else{
        close_num = 1;
        if( $('#personal_award_tab').css('display') != 'block' )
                $('#mjrank_tab').show();
}
$('.mode'+num).show();
$('.mode'+close_num).hide();
return false;
}

function get_origurl(){
    window.open("/logout.php?origurl="+window.location.href, "_self");
}
