/*v1.0.2011.05.27*/

var plandLink = "http://www.pland.gov.hk";
var tpbLink = "http://www.info.gov.hk/tpb";

var locapath = document.location.href;

if (locapath.toString().search('http://')!=-1){
	base_path="http"+"://";
	sitepath = locapath.substring(7,locapath.length);
}else{
	base_path="";
	sitepath = locapath.substring(0,locapath.length);
}

function chgLang(lang1){
	switch(lang1){		
		case'tc':
			if (sitepath.indexOf("gallery_tc")!=-1){break;}
			if (sitepath.indexOf("gallery_en")!=-1){final_path = sitepath.replace("gallery_en","gallery_tc");}
			if (sitepath.indexOf("gallery_chs")!=-1){final_path = sitepath.replace("gallery_chs","gallery_tc");}
			window.location = base_path + final_path;
			break;
		case'chs':
			if (sitepath.indexOf("gallery_chs")!=-1){break;}		
			if (sitepath.indexOf("gallery_en")!=-1){final_path = sitepath.replace("gallery_en","gallery_chs");}
			if (sitepath.indexOf("gallery_tc")!=-1){final_path = sitepath.replace("gallery_tc","gallery_chs");}
			window.location = base_path + final_path;
			break;
		case'en':
			if (sitepath.indexOf("gallery_en")!=-1){break;}
			if (sitepath.indexOf("gallery_chs")!=-1){final_path = sitepath.replace("gallery_chs","gallery_en");}
			if (sitepath.indexOf("gallery_tc")!=-1){final_path = sitepath.replace("gallery_tc","gallery_en");}
			window.location = base_path + final_path;
			break;
	}
}

var org_path_start = locapath.indexOf("://") + 3;
var org_path_end = locapath.length;
var org_path_array = locapath.substring(org_path_start, org_path_end).split("/");
var domain = org_path_array[0];

var locDefaultPath = "";

function gallery_mobile(){

	var locpathnameArray = document.location.pathname.split("/");
	locDefaultPath = "";
	for (i=1; i<=locpathnameArray.length-2; i++){
		locDefaultPath = locDefaultPath + "/" + locpathnameArray[i];
	}
	var locpathname = document.location.host + locDefaultPath;

	basepland_path="http"+"://";

	sitepland_path= locpathname + "/mobile/gallery_tc/index.html";
	
	locahash = document.location.hash;
	if (locahash.indexOf("tc")!=-1){_lang = 'tc';}
	if (locahash.indexOf("sc")!=-1){_lang = 'chs';}
	if (locahash.indexOf("en")!=-1){_lang = 'en';}
	
	switch(_lang){
		case'tc':
			sitepland_path= locpathname + "/mobile/gallery_tc/index.html";
			break;
			case'chs':
			sitepland_path= locpathname + "/mobile/gallery_chs/index.html";
			break;
		case'en':
			sitepland_path= locpathname + "/mobile/gallery_en/index.html";
			break;
	}	
	
	window.location = basepland_path + sitepland_path;
}

function checkMobile()
{
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
	(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
	(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
	(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
	(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

	if (ua.match(/mobile/) != null || ua.match(/mobi/) != null) {
        Sys.mobile = true
    }
    else {
        Sys.mobile = false
    }
    
	if (Sys.mobile == true) {gallery_mobile()}

}


var _lang='';

var top_tc = "" +
"<table class='sitemap_table'> " + 
"  <tr> " + 
"    <td class=''>	 " + 
"		<table class='top_menu_logo'> " + 
"			<tr> " + 
"			  <td colspan='4' class='top_menu_logo' height='29'></td> " + 
"			  <td ><span class='top_menu_logo'>香港規劃及基建展覽館</div></td> " + 
"			</tr> " + 
"		</table>	 " + 
"	  <table> " + 
"		<tr> " + 
"			<td colspan='5'> " +
"			</td>" + 
"	    </tr>" + 
"        <tr id='menu'>" + 
"          <td class='top_menu_r1'><a class='top_menu_r1' href='../../gallery_tc/exhibit.html'>桌面版</a></td>" + 
"          <td class='top_menu_r7'><a class='top_menu_r7' href='javascript:chgLang(\"en\")'>English</a></td>" + 
"          <td class='top_menu_r4'><a class='top_menu_r4' href='javascript:chgLang(\"tc\")'>繁</a></td>" + 
"          <td class='top_menu_r5'><a class='top_menu_r5' href='javascript:chgLang(\"chs\")'>简</a></td>" + 
"          <td class='top_menu_r1'><a class='top_menu_r1' href='index.html'>首頁</a></td>" + 
"        </tr>" + 
"      </table></td>" + 
"  </tr>" + 
"</table>" ;

var top_sc = "" +
"<table class='sitemap_table'> " + 
"  <tr> " + 
"    <td class=''>	 " + 
"		<table class='top_menu_logo'> " + 
"			<tr> " + 
"			  <td colspan='4' class='top_menu_logo' height='29'></td> " + 
"			  <td ><span class='top_menu_logo'>香港规划及基建展览馆</div></td> " + 
"			</tr> " + 
"		</table>	 " + 
"	  <table> " + 
"		<tr> " + 
"			<td colspan='5'> " +
"			</td>" + 
"	    </tr>" + 
"        <tr id='menu'>" + 
"          <td class='top_menu_r1'><a class='top_menu_r1' href='../../gallery_chs/exhibit.html'>桌面版</a></td>" + 
"          <td class='top_menu_r7'><a class='top_menu_r7' href='javascript:chgLang(\"en\")'>English</a></td>" + 
"          <td class='top_menu_r3'><a class='top_menu_r3' href='javascript:chgLang(\"tc\")'>繁</a></td>" + 
"          <td class='top_menu_r6'><a class='top_menu_r6' href='javascript:chgLang(\"chs\")'>简</a></td>" + 
"          <td class='top_menu_r1'><a class='top_menu_r1' href='index.html'>首页</a></td>" + 
"        </tr>" + 
"      </table></td>" + 
"  </tr>" + 
"</table>" ;

var top_en = "" +
"<table class='sitemap_table'> " + 
"  <tr> " + 
"    <td class=''>	 " + 
"		<table class='top_menu_logo'> " + 
"			<tr> " + 
"			  <td colspan='4' class='top_menu_logo' height='29'></td> " + 
"			  <td ><span class='top_menu_logo'>The Hong Kong Planning <br>and Infrastructure Exhibition Gallery</span></td> " + 
"			</tr> " + 
"		</table>	 " + 
"	  <table> " + 
"		<tr> " + 
"			<td colspan='5'> " +
"			</td>" + 
"	    </tr>" + 
"        <tr id='menu'>" + 
"          <td class='top_menu_r1'><a class='top_menu_r1' href='../../gallery_en/exhibit.html'>Desktop Version</a></td>" + 
"          <td class='top_menu_r8'><a class='top_menu_r8' href='javascript:chgLang(\"en\")'>English</a></td>" + 
"          <td class='top_menu_r3'><a class='top_menu_r3' href='javascript:chgLang(\"tc\")'>繁</a></td>" + 
"          <td class='top_menu_r5'><a class='top_menu_r5' href='javascript:chgLang(\"chs\")'>简</a></td>" + 
"          <td class='top_menu_r1'><a class='top_menu_r1' href='index.html'>Home</a></td>" + 
"        </tr>" + 
"      </table></td>" + 
"  </tr>" + 
"</table>" ;

//========================================================================================
var menu_header = "" +
"<table class='sitemap_table'>  " + 
"  <tr>" + 
"    <td class=''>" + 
"  <table class='covePg'>" + 
"  <tr>" 
var menu_footer = "" +
"  </table> " + 
"	</td>" + 
"  </tr>" + 
"</table>" ;

//========================================================================================

function getLang() {
	var locapath = document.location.href;
		
	if (locapath.indexOf("gallery_tc")!=-1){_lang = 'tc'; document.body.className="body_m"}
	if (locapath.indexOf("gallery_chs")!=-1){_lang = 'chs'; document.body.className="body_m"}
	if (locapath.indexOf("gallery_en")!=-1){_lang = 'en'; document.body.className="body_m_en"}
}

function show_top_menu() {
	switch(_lang){
		case'tc':
			document.write(top_tc)			
			break;
		case'chs':
			document.write(top_sc)
			break;
		case'en':
			document.write(top_en)
			break;
	}	
}

//========================================================================================

function build_menu_gallery(i_lang) {	
	var locapath = document.location.href;
	var menu_item = new Array();
	var menu_item_dim = new Array();
	var str_menu = '';

	switch(i_lang){
		case'tc':
		
	menu_item['gallery_exhibit'] = "    <tr><td class='covePg_r1'><a class='covePg_r1' href='exhibit.html'>序言</a></td></tr>" ;	
	menu_item['gallery_news'] = "    <tr><td class='covePg_r2'><a class='covePg_r2' href='whatsnew.html'>最新消息</a></td></tr>" ;	
	menu_item['gallery_visit'] = "    <tr><td class='covePg_r1'><a class='covePg_r1' href='visit.html'>團體參觀</a></td></tr>" ;	
	menu_item['gallery_venue'] = "    <tr><td class='covePg_r2'><a class='covePg_r2' href='venue.html'>地址及開放時間</a></td></tr>" ;	
	menu_item['links'] = "    <tr><td class='covePg_link'>其他連結 ></tr>" ;		
	menu_item['pland'] = "    <tr><td class='covePg_r3'>> <a class='covePg_r3' href='" + plandLink + "/mobile/pland_tc/index.html'>規劃署</a></td></tr>" ;	
	menu_item['tpb'] = "    <tr><td class='covePg_r3'>> <a class='covePg_r3' href='" + tpbLink + "/mobile/tc/whats_new/index.html'>城市規劃委員會</a></td></tr>" ;	

	menu_item_dim['gallery_exhibit'] = "    <tr><td class='covePg_r0'>序言</td></tr>" ;
	menu_item_dim['gallery_news'] = "    <tr><td class='covePg_r0'>最新消息</td></tr>" ;	
	menu_item_dim['gallery_visit'] = "    <tr><td class='covePg_r0'>團體參觀</td></tr>" ;
	menu_item_dim['gallery_venue'] = "    <tr><td class='covePg_r0'>地址及開放時間</a></td></tr>" ;

			break;
		case'chs':
	
	menu_item['gallery_exhibit'] = "    <tr><td class='covePg_r1'><a class='covePg_r1' href='exhibit.html'>序言</a></td></tr>" ;	
	menu_item['gallery_news'] = "    <tr><td class='covePg_r2'><a class='covePg_r2' href='whatsnew.html'>最新消息</a></td></tr>" ;	
	menu_item['gallery_visit'] = "    <tr><td class='covePg_r1'><a class='covePg_r1' href='visit.html'>团体参观</a></td></tr>" ;	
	menu_item['gallery_venue'] = "    <tr><td class='covePg_r2'><a class='covePg_r2' href='venue.html'>地址及开放时间</a></td></tr>" ;	
	menu_item['links'] = "    <tr><td class='covePg_link'>其他连结 ></tr>" ;		
	menu_item['pland'] = "    <tr><td class='covePg_r3'>> <a class='covePg_r3' href='" + plandLink + "/mobile/pland_sc/index.html'>规划署</a></td></tr>" ;	
	menu_item['tpb'] = "    <tr><td class='covePg_r3'>> <a class='covePg_r3' href='" + tpbLink + "/mobile/sc/whats_new/index.html'>城市规划委员会</a></td></tr>" ;	

	menu_item_dim['gallery_exhibit'] = "    <tr><td class='covePg_r0'>序言</td></tr>" ;
	menu_item_dim['gallery_news'] = "    <tr><td class='covePg_r0'>最新消息</td></tr>" ;	
	menu_item_dim['gallery_visit'] = "    <tr><td class='covePg_r0'>团体参观</td></tr>" ;
	menu_item_dim['gallery_venue'] = "    <tr><td class='covePg_r0'>地址及开放时间</a></td></tr>" ;

			break;
		case'en':
	
	menu_item['gallery_exhibit'] = "    <tr><td class='covePg_r1'><a class='covePg_r1' href='exhibit.html'>Introduction</a></td></tr>" ;	
	menu_item['gallery_news'] = "    <tr><td class='covePg_r2'><a class='covePg_r2' href='whatsnew.html'>What's New</a></td></tr>" ;	
	menu_item['gallery_visit'] = "    <tr><td class='covePg_r1'><a class='covePg_r1' href='visit.html'>Group Visit</a></td></tr>" ;	
	menu_item['gallery_venue'] = "    <tr><td class='covePg_r2'><a class='covePg_r2' href='venue.html'>Address and Opening Hours</a></td></tr>" ;	
	menu_item['links'] = "    <tr><td class='covePg_link'>Other Links ></tr>" ;		
	menu_item['pland'] = "    <tr><td class='covePg_r3'>> <a class='covePg_r3' href='" + plandLink + "/mobile/pland_en/index.html'>Planning Department</a></td></tr>" ;	
	menu_item['tpb'] = "    <tr><td class='covePg_r3'>> <a class='covePg_r3' href='" + tpbLink + "/mobile/en/whats_new/index.html'>Town Planning Board</a></td></tr>" ;	

	menu_item_dim['gallery_exhibit'] = "    <tr><td class='covePg_r0'>Introduction</td></tr>" ;
	menu_item_dim['gallery_news'] = "    <tr><td class='covePg_r0'>What's New</td></tr>" ;	
	menu_item_dim['gallery_visit'] = "    <tr><td class='covePg_r0'>Group Visit</td></tr>" ;
	menu_item_dim['gallery_venue'] = "    <tr><td class='covePg_r0'>Address and Opening Hours</a></td></tr>" ;
	
			break;
	}	
	
	for (x in menu_item)
	{	
		if (document.body.id == x){
			menu_item[x] = menu_item_dim[x];			
		}
		str_menu = str_menu + menu_item[x];
	}

	return menu_header + str_menu + menu_footer;
}


function show_menu_gallery() {
	switch(_lang){
		case'tc':
			document.write(build_menu_gallery(_lang))
			break;
		case'chs':
			document.write(build_menu_gallery(_lang))
			break;
		case'en':
			document.write(build_menu_gallery(_lang))
			break;
	}	
}

