﻿// JScript 파일

// float layer
// by guoo.net
var FL_divWrapper;
var FL_divFloat;
var FL_direction;
var FL_cx;
var FL_cy;
var FL_lx;
var FL_ly;
var FL_initX;
var FL_initY;
var FL_whichIt;
var FL_action;
var FL_isStart;
var FL_isActive;
var FL_dx;
var FL_dy;
var FL_NS = document.layers?1:0
var FL_IE = (!document.layers)?1:0

function FL_create(divWrapper, divFloat, direction, left, top) {
	FL_divWrapper = document.getElementById(divWrapper);
	FL_divFloat = document.getElementById(divFloat);
	FL_cx = FL_cy = 0;  
	FL_lx = FL_ly = 0;
	FL_whichIt = null;
	FL_direction = direction;
	if(!left) left = 0;
	if(!top) top = 0;
    if(FL_NS) {
		FL_initX = FL_divWrapper.pageXOffset + left;
		FL_initY = FL_divWrapper.pageYOffset + top;
	}
	if(FL_IE) {
		FL_initX = FL_divWrapper.offsetLeft + left;
		FL_initY = FL_divWrapper.offsetTop + top;
	}
	FL_isActive = true;

	addScrollEvent(new CustomEvent('float_layer', FL_start, 1));
}

function FL_start() {
	if(!FL_isStart) {
		if(FL_isActive) {
			FL_action = setInterval("FL_heartBeat()", 10);
			FL_isStart = true;
		}
	}//if
}

function FL_stop() {
	if(FL_isStart) {
		clearInterval(FL_action);
		FL_isStart = false;
	}//if
}


function FL_toggle() {
	if(FL_isActive) {
		FL_isActive = false;
	}else {
		FL_isActive = true;
	}
}

function FL_heartBeat() {
	var percent;

	if(FL_IE) {
		if(document.body.scrollTop > FL_initY)
			FL_dy = document.body.scrollTop - FL_initY;
		else
			FL_dy = 0;
		if(document.body.scrollLeft > FL_initX)
			FL_dx = document.body.scrollLeft - FL_initX;
		else
			FL_dx = 0;
	}
    if(FL_NS) {
		FL_dy = self.pageYOffset;
		FL_dx = self.pageXOffset;
	}
	if(FL_dy != FL_ly) {
		percent = .2 * (FL_dy - FL_ly);
		if(percent > 0) percent = Math.ceil(percent);
		else percent = Math.floor(percent);
		
		if(FL_direction=='both' || FL_direction=='y') {
		    if(FL_IE)
			    FL_divFloat.style.top = FL_divFloat.offsetTop + percent;
		    if(FL_NS)
			    FL_divFloat.top += percent;
		}
		FL_ly = FL_ly + percent;
	}
	if(FL_dx != FL_lx) {
		percent = .2 * (FL_dx - FL_lx);
		if(percent > 0) percent = Math.ceil(percent);
		else percent = Math.floor(percent);
		if(FL_direction=='both' || FL_direction=='x') {
		    if(FL_IE)
			    FL_divFloat.style.left = FL_divFloat.offsetLeft + percent;
		    if(FL_NS)
			    FL_divFloat.left += percent;
		}
		FL_lx = FL_lx + percent;
	}	

	if(FL_dy == FL_ly && FL_dx == FL_lx) {
		FL_stop();
	}
}	
