$(document).ready(function() {
	
	addFormEvent();
	
	// Spoil message
	$(".spoil_head").each(function() {
		$(this).click(function(event) {
			event.preventDefault();
			var d = $(this).parent(".spoil").children(".spoil_frame");
			var h = $(d).children(".spoil_data").height();
			h += 8;
			
			if ($(this).hasClass("spoil_on")) {
				$(this).removeClass("spoil_on");
				$(this).addClass("spoil_off");
				$(this).text("Close Spoil");
				
				$(d).animate({ height: h+"px"}, "fast");
			} else {
				$(this).removeClass("spoil_off");
				$(this).addClass("spoil_on");
				$(this).text("View Spoil");
				
				$(d).animate({ height: "4px"}, "fast");
			}
		});
	});
	
	// Service menu
	$(".sv_inner").each(function() {
		$(this).hover(function() {
			$(this).stop(true, true).fadeTo(400, 1.0);
		}, function() {
			$(this).stop(true, true).fadeTo(400, 0.01);
		});
	});

	$(".tagList").each(function() {
		$(this).mouseover(function(event) {
			event.preventDefault();
			$(this).removeClass("tagList_normal");
			$(this).addClass("tagList_hover");
		});
		$(this).mouseout(function(event) {
			event.preventDefault();
			$(this).addClass("tagList_normal");
			$(this).removeClass("tagList_hover");
		});
	});
});

function addFormEvent() {
	// Form box
	$(".form_box").each(function() {
		$(this).focus(function(event) {
			event.preventDefault();
			$(this).removeClass("form_boxN");
			$(this).addClass("form_boxA");
		}).blur(function(event) {
			event.preventDefault();
			$(this).removeClass("form_boxA");
			$(this).addClass("form_boxN");
		});
	});
}

function visibleListFrame(frameState) {
	var timerID;
	var timerLen = 1;
	var minWidth = 0;
	var maxWidth = 450;
	
	document.getElementById('list_frame_open').style.display = 'none';		
	document.getElementById('list_frame_close').style.display = 'none';
	
	
	if (frameState == 1) {
		var frameWidth = minWidth;
		var frameScale = 1;
		document.getElementById('listTitle').style.display = '';
	} else {
		var frameWidth = maxWidth;
		var frameScale = -1;
	}

	var obj = document.getElementById('list_frame');
	obj.style.display = 'block';
	
	function setActiveFrame() {
		timerID = setInterval(scaleActiveFrame, timerLen);
	}

	function scaleActiveFrame() {
		obj.style.width = frameWidth + 'px';
		frameWidth = frameWidth + (frameScale * 50);
		
		if (frameWidth > maxWidth && frameState == 1) {
			clearInterval(timerID);
			document.getElementById('list_frame_open').style.display = 'none';		
			document.getElementById('list_frame_close').style.display = 'block';
		} else if (frameWidth < minWidth && frameState != 1) {
			clearInterval(timerID);
			obj.style.display = 'none';
			document.getElementById('list_frame_open').style.display = 'block';
			document.getElementById('list_frame_close').style.display = 'none';
			document.getElementById('listTitle').style.display = 'none';
		}
	}
	setActiveFrame();
}