// JavaScript Document

function positionFooter() {
	var windowH = $(window).height();
	var containerH = $("#container").height();
	var totalH;
	var yOffset;
	if(containerH > 660) {
		yOffset = 200;
		totalH = containerH + (380 - yOffset);
	}
	else {
		yOffset = 380 - ((460 + 380) - containerH);
		totalH = 460 + 380;
	}
	if(windowH > totalH) {
		$("#bodyBottomBG").css("position", "absolute");
		$("#bodyBottomBG").css("top", windowH - 398 + "px");
	}
	else {
		$("#bodyBottomBG").css("position", "absolute");
		$("#bodyBottomBG").css("top", containerH - yOffset + "px");
	}
}

$(window).load(function() {
	positionFooter();
	$("#bodyBottomBG").css("visibility", "visible");
});

$(document).ready(function(){ 
	positionFooter();
	$(window).resize(function() {
		positionFooter();
	});
	

	$(".submenuLink").hover(
		function(){
			$(this.parentNode).css("border-bottom", "1px dotted #45bde5");
		},
		function(){
			$(this.parentNode).css("border-bottom", "1px dotted #bfbfbf");
		}
	);
	
	$(".navi2Link").hover(
		 function(){
			 $("#" + this.id + " img").attr("src", "images/" + this.id + "H.png");
		 },
		 function(){
			 $("#" + this.id + " img").attr("src", "images/" + this.id + ".png");
		 }
	);

	$('.naviT').hover(
		function() {
			$(this).animate({height: '70px'}, 170);
			$('#' + this.id + ' img').attr('src', 'images/' + this.id +'H.png');
			$('#' + this.id + ' img').animate({top: '10px'}, 170);
			$('#' + this.id + 'TH').css('display', 'block');
			$('#' + this.id + 'TH').animate({top: '50px'}, 170);
		},
		function() {
			$('#' + this.id + ' img').attr('src', 'images/' + this.id +'T.png');
			$('#' + this.id + ' img').animate({top: '0px'}, 170);
			$('#' + this.id + 'TH').animate({top: '40px'}, 170, function() {
				$(this).css('display', 'none')
			});
			$(this).animate({height: '60px'}, 170);
	});
	
	//hover button
	$('.hoverBtn').hover(
		function() {
			$(this).attr('src', 'images/' + this.id + 'H.png');
		},
		function () {
			$(this).attr('src', 'images/' + this.id + '.png');
		}
	);

	//faq hover
	$(".FAQQ").hover(
		function(){
			$(this).css("cursor", "pointer");
			$(this).css("curosr", "handl");
			$(this).css("text-decoration", "none");
		},
		function(){
			$(this).css("cursor", "default");
			$(this).css("text-decoration", "underline");
		});

	//faq index toggle
	$(".faqUL li a").click(
		function(){
			var target = $(this).attr("href");
			if ($(this).next(".slideBx").css("display") != "block") {
				if ($(target).html().charAt(0) != ">" && $(target).html().charAt(0) != "&") {
					var FAQQStr = "> " + $(target).html();
					$(target).html(FAQQStr);
				}
				$(target).next(".slideBx").slideDown("medium", function() {
					positionFooter();
				});
			}
	});
	
	//faq toggle
	$(".FAQQ").click(
		function(){
			$(this).next(".slideBx").slideToggle("medium", function() {
				positionFooter();
			});
		});


	//FAQ exapnd or collapse all
	$("#expandAllBtn").click(
		function(){
			$(".slideBx").slideDown("medium", function() {
				positionFooter();
			});
	});
	
	$("#collapseAllBtn").click(
		function(){
			$(".slideBx").slideUp("medium", function() {
				positionFooter();
			});
	});

	//input field hover & focus
	$("input, textarea").focus(
		function() {
			$(this).css("opacity", "1");
			$(this).css("filter", "alpha(opacity=100)");
		});
	
	$("input, textarea").blur(
		function() {
			$(this).css("opacity", "0.7");
			$(this).css("filter", "alpha(opacity=70)");
		}
	);

	//summary table cell hover
	$(".summaryTR1 TD").hover(
		function(){
			$(this.parentNode).children("TD").css("opacity", "1");
			$(this.parentNode).children("TD").css("filter", "alpha(opacity=100)");
		},
		function() {
			$(this.parentNode).children("TD").css("opacity", "0.7");
			$(this.parentNode).children("TD").css("filter", "alpha(opacity=70)");
		}
	);
	
	$(".summaryTR2 TD").hover(
		function(){
			$(this.parentNode).children("TD").css("color", "white");
			$(this.parentNode).children("TD").css("background", "#002e40");
			$(this.parentNode).addClass("summaryTR2Hover");
			$(this.parentNode).removeClass("summaryTR2");
			$(this.parentNode).children("img").css("opacity", "1");
			$(this.parentNode).children("img").css("filter", "alpha(opacity=100)");
		},
		function() {
			$(this.parentNode).children("TD").css("color", "#a6a6a6");
			$(this.parentNode).children("TD").css("background", "url(images/blank.gif)");
			$(this.parentNode).addClass("summaryTR2");
			$(this.parentNode).removeClass("summaryTR2Hover");
			$(this.parentNode).children("img").css("opacity", "0.7");
			$(this.parentNode).children("img").css("filter", "alpha(opacity=70)");
		}
	);
	
	//reward navi2 hover
	$(".navi2Section13 img, .mainCategorySection6 img, .mainCategorySection7 img").hover(
		function(){
			$(this.parentNode).children(".rewardType").css("visibility", "visible");
		},
		function() {
			$(this.parentNode).children(".rewardType").css("visibility", "hidden");
		}
	);

	//popup bubbleInfo
    $(function () {
        $('.popBxItem').each(function () {
            var distance = 5;
            var time = 200;
            var hideDelay = 0;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.popBxTrg', this);
            var info = $('.popBx', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
            	$(this).children(".popBxTrg").css("text-decoration", "none");
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: -8,
                        left: 10,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
            	$(this).children(".popBxTrg").css("text-decoration", "underline");
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });

});