$(document).ready(documentReady);
var hover = false;

function documentReady(){
	hover = false;
	$(document).mousemove(mouseMovin);
	$('.dashed_thumb').mouseout(mouseOut);
	$('.dashed_thumb').mouseover(mouseOver);
	$('.dashed_thumb').click(mouseClick);
	
	$("#now_growing_scroll").makeSlider({left:"#arrow_left", right:"#arrow_right", pageTotal:$(".now_growing_page").length, pageWidth:266});
	styleGreenText();
}
function styleGreenText(){
	var theContent = $("#home_flash2").html();
	var arrContent = theContent.split(" ");
	theContent = "<span>";
	for(i = 0; i < arrContent.length; i++){
		if(i>0) theContent = theContent.concat(" </span><span>");
		theContent = theContent.concat(arrContent[i]);
	}
	theContent = theContent.replace(/fi/g, '&#64257;'); // ligature
	theContent = theContent.concat("</span>");
	$("#home_flash2").html(theContent);
	$.ajax({url: 'css/eksja.css', success:fontLoaded});
	$.ajax({url: 'css/main.css', success:mainCSSLoaded});
	$.ajax({url: 'css/pg_home.css', success:homeCSSLoaded});
}
var isFontLoaded = false;
var isHomeLoaded = false;
var isMainLoaded = false;
function fontLoaded(data){
	isFontLoaded = true;
	checkShowText();
}
function homeCSSLoaded(data){
	isHomeLoaded = true;
	checkShowText();
}
function mainCSSLoaded(data){
	isMainLoaded = true;
	checkShowText();
}
function checkShowText(){
	var tX = 16;
	var tY = 50;
	var toggler = false;
	if(isFontLoaded == true && isHomeLoaded == true && isMainLoaded == true) {
		$("#home_flash2 span").delay(100).queue(function(){
			var thisY = $(this).position().top;
			if(thisY != tY){
				toggler = (toggler) ? false : true;
				tY = thisY;
			}
			$(this).css("color", (toggler)? "#94BA28" : "#5B8A23");
		});
	}	
}
function mouseClick(){
	document.location.href = $(this).attr("link");
}
function mouseMovin(e) {
	var offset = $('#home_box2').offset();
	$('#box_hover').css("left", (e.pageX - offset.left + 30) + "px");
	$('#box_hover').css("top", (e.pageY - offset.top - 15) + "px");
}
function mouseOver(e){
	hover = true;
	$('#box_hover').css("display", "block");
	$('#hover_content').html($(this).attr("smn_content"));
	mouseMovin(e);
}
function mouseOut(e){
	hover = false;
	$('#box_hover').css("display", "none");
}
