//=============================================================================
//	Display Header
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var displayHeader = function() {
	var header;
	
	if(lang == "en"){
		header = "<h1><a href='index.html' title='Liberty Life' name='page_top'><img src='img/header/logo.gif' border='0' width='140' height='60' alt='Australia Liberty Life' /></a></h1>";
		header += "<p class='catchCopy'>Australia Liberty Life Japanese Gardeners on the Gold Coast</p>";
		header += "<p class='langBtn'><a href='jp/index.html' title='Japanese'>Japanese</a></p>";
		header += "<p class='hidden'><a href='#' onClick='movetoMenu(); return false' title='Go to Menu'>Go to Menu</a></p>";
	}
	else {
		header = "<h1><a href='index.html' title='Liberty Life' name='page_top'><img src='../img/header/logo.gif' border='0' width='140' height='60' alt='Australia Liberty Life' /></a></h1>";
		header += "<p class='catchCopy_jp'>ゴールドコーストのお庭のお手入れの専門会社</p>";
		header += "<p class='langBtn_jp'><a href='../index.html' title='English'>English</a></p>";
		header += "<p class='hidden'><a href='#' onClick='movetoMenu(); return false' title='メニューへ'>▼メニューへ</a></p>";
	}
	
	header +="<hr />";
	
	document.write(header);
}



//=============================================================================
//	Display Global Menu
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var displayGlobalMenu = function() {
	var menuList;
	var link_str = getPath(lang);
	
	if(lang == "en") {
		var menu_str = new Array("Home", "Our Business", "Our Works", "Company Profile", "News","Contact Us");
		var menu_id_str = new Array("home", "business", "works", "profile", "news","contact");
	}
	else {
		var menu_str = new Array("ホーム", "事業内容", "案件事例", "会社概要", "新着情報","お問合せ");
		var menu_id_str = new Array("home_jp", "business_jp", "works_jp", "profile_jp", "news_jp","contact_jp");
	}
	
	
	menuList ="<hr />";
	
	menuList += "<ul>";
	//---------- Home
	menuList += "<li><a href='index.html' id='" + menu_id_str[0] + "' title='" + menu_str[0] + "'>" + menu_str[0] + "</a></li>";
	//---------- Our Business
	menuList += "<li><a href='business.html' id='" + menu_id_str[1] + "' title='" + menu_str[1] + "'>" + menu_str[1] + "</a></li>";
	//---------- Our Works
	menuList += "<li><a href='works.html' id='" + menu_id_str[2] + "' title='" + menu_str[2] + "'>" + menu_str[2] + "</a></li>";
	//---------- Company Profile
	menuList += "<li><a href='profile.html' id='" + menu_id_str[3] + "' title='" + menu_str[3] + "'>" + menu_str[3] + "</a></li>";
	//---------- News
	menuList += "<li><a href='news.html' id='" + menu_id_str[4] + "' title='" + menu_str[4] + "'>" + menu_str[4] + "</a></li>";
	//---------- Contact Us
	menuList += "<li><a href='contact.html' id='" + menu_id_str[5] + "' title='" + menu_str[5] + "'>" + menu_str[5] + "</a></li>";
	menuList += "</ul>";
	
	
	menuList += "<ul class='banners'>";
	//---------- TEL
	if(lang == "en") {
		menuList += "<li><img src='" + link_str + "img/menu/freequote.jpg' width='165' height='70' border='0' alt='free quote' /></li>";
	}
	else {
		menuList += "<li><img src='" + link_str + "img/menu/freequote_jp.jpg' width='165' height='70' border='0' alt='無料お見積り' /></li>";
	}
	if(lang == "en") {
		menuList += "<li><img src='" + link_str + "img/menu/promotion.jpg' width='165' height='70' border='0' alt='Special First Service 20% Off (Labour Fee)' /></li>";
	}
	else {
		menuList += "<li><img src='" + link_str + "img/menu/promotion_jp.jpg' width='165' height='70' border='0' alt='新規お客様　初回20％OFF（作業代）' /></li>";
	}
	//---------- Blog
	menuList += "<li><a href='http://liberty-life.com.au/blog/' target='_blank' title='Australia Liberty Life Blog'><img src='" + link_str + "img/menu/blog.jpg' width='165' height='91' border='0' alt='Australia Liberty Life Blog' /></a></li>";
	menuList += "</ul>";
	
	
	menuList +="<hr />";
	
	document.write(menuList);
}

var switchBtn = function(page) {
	var link_str = getPath(lang);
	
	
	if(page == "index") {
		page = page.replace("index", "home");
	}
	else if(page == "") {
		page = "home";
	}
	
	if(page == "sitemap") {
		return;
	}
	
	// If lang is NOT english, insert _jp at the end for element ID. 
	if(lang != "en") {
		page = page + "_jp";
	}

	var globalMenu = document.getElementById(page);
	
	// After store the element ID, take off the _jp.
	page = page.replace("_jp", "");
	
	globalMenu.style.backgroundImage = "url('" + link_str + "img/menu/" + lang + "/" + page + "_on.gif')";
}



//=============================================================================
//	Display Footer
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var displayFooter = function() {
	var footer;
	
	footer = "<div>";
	footer += "<ul class='clearfix'>";
	footer += "<li><a href='sitemap.html' title='Sitemap'>Sitemap</a></li>";
	footer += "</ul>";
	footer += "<address>Copyright &copy 2009 Australia Liberty Life, All Rights Reserved.</address>";
	footer += "</div>";
	
	document.write(footer);
}



//=============================================================================
//	Display Back to Page Top
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var displayPageTop = function() {
	var pageTop;

	if(lang == "en"){
		pageTop = "<p class='pageTop'><a href='#' onClick='movePageTop(); return false' title='Back to Page Top'>Back to Page Top</a></p>";
	}
	else{
		pageTop = "<p class='pageTop_jp'><a href='#' onClick='movePageTop(); return false' title='ページの先頭へ'>▲ページの先頭へ</a></p>";
	}
	
	document.write(pageTop);
}



//=============================================================================
//	Move to Page Top Function
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var movePageTop = function() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	
	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	
	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;
	
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	
	window.scrollTo(Math.floor(x / 2 * 1.5), Math.floor(y / 2 * 1.5));
	
	if (x > 0 || y > 0) {
		window.setTimeout("movePageTop()", 25);
	}
}



//=============================================================================
//	Move to Menu Function
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var movetoMenu = function() {
	var num = getPosition("globalMenu");
	//var y = window.scrollY;
	//alert(y);
	
	/*if(y == 0) {
		y = Math.floor(num / 4);
	}
	else {
		y = Math.floor(y + y / 4);
	}*/

	window.scrollTo(0, num);
	
	
	/*if (document.body.scrollTop || y < num) {
		window.setTimeout("movetoMenu()", 25);
	}*/
}



//=============================================================================
//	OS & Browser Check関数
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var lang;
var osCheck = function(obj) {
	var link_str = getPath(obj);
	
	//Set Language
	if(obj == "en") {
		lang = obj;
	}
	else {
		lang = "jp";
	}
	
	var Agent = navigator.userAgent;

	if (Agent.indexOf("Safari") != -1) {
		document.write("<link rel=\"stylesheet\" href=\""+ link_str + "css/safari.css\" type=\"text/css\" media=\"screen\" />");
		return;
	}
	else if (Agent.indexOf("Opera") != -1) {
		document.write("<link rel=\"stylesheet\" href=\""+ link_str + "css/opera.css\" type=\"text/css\" media=\"screen\" />");
		return;
	}
	else if (Agent.indexOf("Firefox") != -1) {
		if (Agent.indexOf("Windows NT 5.1") != -1) {
			document.write("<link rel=\"stylesheet\" href=\""+ link_str + "css/xp_ff.css\" type=\"text/css\" media=\"screen\" />");
			return;
		}
		else if (Agent.indexOf("Windows NT 6.0") != -1) {
			document.write("<link rel=\"stylesheet\" href=\""+ link_str + "css/vista_ff.css\" type=\"text/css\" media=\"screen\" />");
			return;
		}
	}
	else if (Agent.indexOf("MSIE 7") != -1) {
		document.write("<link rel=\"stylesheet\" href=\""+ link_str + "css/ie7.css\" type=\"text/css\" media=\"screen\" />");
		return;
	}
	else if (Agent.indexOf("MSIE 6.0") != -1) {
		document.write("<link rel=\"stylesheet\" href=\""+ link_str + "css/ie6.css\" type=\"text/css\" media=\"screen\" />");
		return;
	}
}



//=============================================================================
//	Set Event Handler
//=============================================================================
//function $(e) {
//    return document.getElementById(e);
//}

function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false); // Firefox等
	}
	catch(e){
		elm.attachEvent("on"+listener,fn); // IE用
	}
}

function currentPage() {
	var page = location.href;
	var temp = page.lastIndexOf("/");
	
	temp = page.substring(temp);
	temp = temp.split("/");
	
	temp = temp[1].split(".");
	temp = temp[0];

	temp = temp.split("_");
	page = temp[0];
//alert(page);
	switchBtn(page);
}

// Get Current Page Name
addEvent(window,"load",currentPage);
// Get and Set Footer Height
addEvent(window,"load",setFooterHeight);


onresize = function() {
	setFooterHeight();
};



//=============================================================================
//	Compare & Set Top Page Contents Height Function
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
function compareSetHeight() {
	var h1 = document.getElementById('topContents');
	var h2 = document.getElementById('news');
	
	if(h1.offsetHeight > h2.offsetHeight){
		h2.style.height = h1.offsetHeight + "px";
	}
	else {
		h1.style.height = h2.offsetHeight + "px";
	}
}



//=============================================================================
//	Get and Set Footer Height Function
//	Takahashi Toshiya
//	2009/2/16
//=============================================================================
function setFooterHeight() {
	var agent = navigator.appName;
	var h = document.getElementById('footer');
	var browserHeight; //Current Browser Height
	var pos = getPosition('footer'); //Actual Position of Content
	var temp_height;
	
	//Select Browser
	switch (agent) {
	case "Microsoft Internet Explorer":
		//alert(agent);
		browserHeight = document.documentElement.clientHeight;
		//browserHeight = document.body.clientHeight;
		break;
	default:
		browserHeight = window.innerHeight;
		break;
	}

	temp_height = browserHeight - pos;
//alert(temp_height + "=" + screenHeight + "-" + pos);

	if(temp_height < 150) {
		h.style.height = "150px";
	}
	else {
		h.style.height = temp_height + "px";
	}
}



//=============================================================================
//	Get Position Function
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
var getPosition = function(obj) {
	var pos = document.getElementById(obj);

	return pos.offsetTop;
}



//=============================================================================
//	Get Path Function
//	Takahashi Toshiya
//	2009/1/13
//=============================================================================
function getPath(obj) {
	if(obj=="en") {
		return "./";
	}
	else {
		return "../";
	}
}