﻿$(document).ready(function() {
    $('#BG').show().css({ opacity: '0.8' }).hide();
    $('#logIn').show();
    $('#loginClose').click(function() { $('#logIn').slideUp(300); });
    $('#logIn').hide();
    $('#showLogin').click(function() { $('#logIn').slideDown(300); return false; });
    $('#menu > div').hover(function() {
        if ($(this).attr('jl') != 'memberLoginDiv') {
            $(this).children('p').show();
            if ($(this).attr('id') != 'LOCK') {
                $(this).children('a').css({ borderBottom: '7px solid #fdd000' });
            };
        };
    }, function() {
        if ($(this).attr('jl') != 'memberLoginDiv') {
            $(this).children('p').hide();
            if ($(this).attr('id') != 'LOCK') {
                $(this).children('a').css({ borderBottom: '0' });
            };
        };
    });
    $('#goTop').click(function() {
        $('#Box').animate({ scrollTop: '0px' }, 300);
        $(this).blur();
        return false;
    });
    $('#small').click(function() {
        fontSize(12, 15);
        $(this).addClass('ON');
        return false;
    });
    $('#medium').click(function() {
        fontSize(13, 18);
        $(this).addClass('ON');
        return false;
    });
    $('#big').click(function() {
        fontSize(15, 21);
        $(this).addClass('ON');
        return false;
    });
    if ($('.ptBody')) {
        $('.ptBody').each(function() {
            $(this).children('div:even').css({ backgroundImage: 'url(/images/bg-parat1.gif)' });
            $(this).children('div:odd').css({ backgroundImage: 'url(/images/bg-parat2.gif)' });
        });
    };
    if ($('#cEnglish')) {
        $('#langEN').hide();
        $('#cEnglish').click(function() {
            if ($('#langCN').css('display') == 'block') {
                $('#langCN').hide();
                $('#langEN').fadeIn(300);
                $('#cEnglish').removeClass().addClass('trChinese');
            } else {
                $('#langCN').fadeIn(300);
                $('#langEN').hide();
                $('#cEnglish').removeClass().addClass('trEnglish');
            };
            $(this).blur();
            return false;
        });
    };
    if ($('.aboutFiveList')) {
        $('.aboutFiveList').each(function(i) {
            $('a', this).each(function(i) {
                if (Math.floor(i / 2) % 2 == 1) {
                    $(this).css({ backgroundColor: '#e8e8e8' });
                }
            });
        });
    };
    if ($('#aTab2')) {
        $('.aboutTwoTabCon').hide().eq(0).show();
        $('#aTab2 > p').eq(0).addClass('ON');
        fxTab('#aTab2 > p', '.aboutTwoTabCon');
    };

    if ($('#mTab2')) {
        $('.aboutFiveList').hide().eq(0).show();
        $('#mTab2 > p').eq(0).addClass('ON');
        fxTab('#mTab2 > p', '.aboutFiveList');
    };

    $('.aboutThreeTD > div:odd, .eventFourTD > div:odd, .eventFiveTD > div:odd, .resourceTwoTD > div:odd, .eventOneTD > p:odd, .memberOneTD > div:odd, .memberThreeTD > div:odd, .memberFourTDy >div:odd').css({ backgroundColor: '#e8e8e8' });

    if ($('#aboutFivePic')) {
        $('#aboutFivePic i').css({ opacity: 0.5 }).hide();
        $('#aboutFivePic div').hover(function() {
            $('i, a', this).fadeIn(300);
        }, function() {
            $('i, a', this).fadeOut(200);
        });
    };

    $('.iSend, .iReset, .iApply').hover(function() {
        $(this).css({ backgroundPosition: 'left bottom' });
    }, function() {
        $(this).css({ backgroundPosition: 'left top' });
    });

    $('.contactFormRight input, .contactFormRight textarea, .memberFourFormZ span input').focus(function() {
        $(this).css({ borderColor: 'black' });
    }).blur(function() {
        $(this).css({ borderColor: 'white' });
    });
    $('#loginFirst').click(function() {
        $('#Box').animate({ scrollTop: '0px' }, 300, function() { $('#logIn').slideDown(300); });
        $(this).blur();
        return false;
    });
    $('.eventThreeBox > div, .shareTwoBox > div').hover(function() {
        $(this).css({ backgroundColor: '#e8e8e8' });
    }, function() {
        $(this).css({ backgroundColor: '' });
    });
    $('#jumpforgot').click(function() {
        $('#forgotImg').attr('src','/forgot.aspx?' + Math.random());
        $('#forgotpw').fadeIn(100).prev().hide();
    });
    
    if ($('.t5').attr('jl') == 'memberLoginDiv') {
        $('.t55').click(function() {
            popUp('#loginAsk');
            $('#forgotpw').hide().prev().show();

            return false;
        });
    }
    
    $('.REMOVE').click(function() {
        $(this).parent().remove();
        return false;
    });
    $('#addLi').click(function() {
        var _target = $(this).parent().parent().prev().children('span').find('ul');
        var vir = $('<li><input type="text" name="" /><a href="#" class="REMOVE">刪除</a></li>');
        $('a', vir).click(function() {
            $(this).parent().remove();
            return false;
        });
        vir.appendTo(_target);
        vir.find('input').focus(function() {
            $(this).css({ borderColor: 'black' });
        }).blur(function() {
            $(this).css({ borderColor: 'white' });
        }).focus();
    });
    $(document).pngFix();
	var secretCode = '';
	function keyUp(e) {
		var currKey=0,e=e||event;
		currKey=e.keyCode||e.which||e.charCode;
		var keyName = String.fromCharCode(currKey);
		if(keyName == "&"){
			secretCode += '上';
		} else if(keyName == "("){
			secretCode += '下';
		} else if(keyName == "%"){
			secretCode += '左';
		} else if(keyName == "'"){
			secretCode += '右';
		} else if(keyName == "A"){
			secretCode += 'A';
		} else if(keyName == "B"){
			secretCode += 'B';
		} else {
			secretCode = '';
		};
		if(secretCode == '上上下下左左右右ABBA'){
			forDiv.show();
			$(document).pngFix();
			alert('恭喜您搞壞了！');
		};
	
	}
	document.onkeyup = keyUp;
	var forDiv = $('<div style="position:absolute;top:0;left:0;z-index:99;"><img src="/images/break.png" width="674" height="549" /></div>');
	forDiv.appendTo('body').hide();
});
function fontSize(NUM, NUM2){
	$('#fSize a').removeClass('ON');
	$('.paraBody, .indexBody').css({fontSize:NUM + 'px'});
	$('.paraBody h2').css({fontSize:NUM2 + 'px'});
};

var banId = 0;
var banMax = 0;
var indexTimer;
$(window).load(function(){
	$('#indexChoke > i img').hide().eq(0).show();
	$('#ban > div').hide().eq(0).show();
	banMax = $('#ban > div').length;
	$('#indexChoke > i').click(function(){
		var _this = this;
		banId = $('#indexChoke > i').index(_this);
		indexBan(banId);
	});
	$('#ban').mousewheel(function(e, delta){
		if(delta < 0){banId ++;indexBan(banId); } else if(delta > 0){banId --;indexBan(banId);};
		return false;
	});
	indexTimer = setInterval(function(){banId++;indexBan(banId);}, 10000);
	eventSlideIdMax = $('#eventImgList img').length;
	$('#eventImgList img').click(function(){
		var _this = this;
		eventSlideId = $('#eventImgList img').index(_this);
		$('.eventPopSlideImg >span').hide().eq(eventSlideId).show();
		popUp('#eventPopSlide');
	});
	$('#eventPopSlide .aLeft img').click(function(){
		eventSlideId ++;
		runEventslide();
	});
	$('#eventPopSlide .aRight img').click(function(){
		eventSlideId --;
		runEventslide();
	});
	$('.popClose').click(function(){
		recall();
	});
	$('.eventPopSlideImg').mousewheel(function(ev, delta){
		if(delta > 0){
			eventSlideId--;
		} else if(delta < 0){
			eventSlideId++;
		};
		runEventslide();
		return false;
	});
	recall();
});
var eventSlideId = 0;
var eventSlideIdMax = 0;

function popUp(DOM){
	$('#dot').css({zIndex:'30'});
	$('#BG').fadeIn(500, function(){
		$(DOM).fadeIn(300);
	});
	if($.browser.msie && $.browser.version == '6.0'){
		$('#Box input, #Box select, #Box textarea').hide();
	};
};
function runEventslide (){
	if(eventSlideId < 0){
		eventSlideId = eventSlideIdMax - 1;
	} else if(eventSlideId == eventSlideIdMax){
		eventSlideId = 0;
	};
	$('.eventPopSlideImg >span').hide().eq(eventSlideId).fadeIn(300);
};
function recall (){
	$('#BG').hide();
	$('#dot').css({zIndex:'-1'}).children('div').hide();
	if($.browser.msie && $.browser.version == '6.0'){
		$('#Box input, #Box select, #Box textarea').show();
	};
};

function indexBan (ID){
	if(ID < 0 ){banId = banMax - 1;} else if(ID >= banMax){banId = 0;};
	$('#indexChoke > i img').hide().eq(banId).show();
	$('#ban > div').hide().eq(banId).fadeIn(300).find('img').attr({src: $('#ban img').eq(banId).attr('src') +'?'});
};

function fxTab (TAB, CON){
	$(TAB).click(function(){
		var _this = $(TAB).index(this);
		$(TAB).removeClass();
		$(this).addClass('ON');
		$(CON).hide().eq(_this).fadeIn(300);
	});

};
