// global variables used in the site
var g_country = "eng";
var hidePrintToolsIntervalId = 0;

//this function is not being used
//try to include the hide-print-tools.css instead
function hidePrintTools() {
	try
	{
		if (document.getElementById("printUtil"))
		{
			var printToolsContent = document.getElementById("printUtil").innerHTML;
			var newContent = printToolsContent.replace(/(<li class=add-to-basket>)(.*)(<\/li>)?/i, "");
			newContent = newContent.replace(/(<li class=manage-basket>)(.*)(<\/li>)?/i, "");
			newContent = newContent.replace(/(<li class=\"add-to-basket\">)(.*)(<\/li>)?/i, "");
			newContent = newContent.replace(/(<li class=\"manage-basket\">)(.*)(<\/li>)?/i, "");
			document.getElementById("printUtil").innerHTML = newContent;	
			clearInterval(hidePrintToolsIntervalId);
		}
	}
	catch (err)
	{
		//alert("@hidePrintTools Error");
	}
}

function showAudioGuide(audioFilePath)
{
	var audioPlayerFilePath = "/eng/images/audio-player.swf";
	var audioPlayerWidth = "250";
	var audioPlayerHeight = "23";
	var s = "<div class=\"audioguidetxt\">Hear Audio Guide</div><div id=\"audioguide\"></div>\n";
	s += "<script language=\"javascript\" type=\"text/javascript\">\n";
	s += "var fo = new FlashObject(\"" + audioPlayerFilePath + "\", \"fo\", \"" + audioPlayerWidth + "\", \"" + audioPlayerHeight + "\", \"8\", \"#ffffff\", true);\n";
	s += "fo.addParam(\"wmode\", \"transparent\");\n";
	s += "fo.addVariable(\"scriptPath\", \"" + audioFilePath + "\");\n";
	s += "fo.write(\"audioguide\");\n";
	s += "</script>\n";
	document.write(s);
}

function showShortAudioGuide(audioFilePath, id)
{
	var audioPlayerFilePath = "/eng/images/audio-player-short.swf";
	var audioPlayerWidth = "140";
	var audioPlayerHeight = "23";
	//var s = "<div class=\"audioguidetxt\">Hear Audio Guide</div><div id=\"audioguide\"></div>\n";
	var s = "<div id=\"audioguide"+id+"\"></div>\n";
	s += "<script language=\"javascript\" type=\"text/javascript\">\n";
	s += "var fo = new FlashObject(\"" + audioPlayerFilePath + "\", \"fo\", \"" + audioPlayerWidth + "\", \"" + audioPlayerHeight + "\", \"8\", \"#ffffff\", true);\n";
	s += "fo.addParam(\"wmode\", \"transparent\");\n";
	s += "fo.addVariable(\"scriptPath\", \"" + audioFilePath + "\");\n";
	s += "fo.write(\"audioguide"+id+"\");\n";
	s += "</script>\n";
	document.write(s);
}

function delegate( target, callback )
{
	var func;
	if(arguments.length > 2)
	{
		var _params = [];
		for(var n = 2; n < arguments.length; n++) _params.push(arguments[n]);
		func = function() { 
			var params = [];
			for(var n = 0; n < arguments.length; n++) params.push(arguments[n]);
			for(var n = 0; n < _params.length; n++) params.push(_params[n]);
			callback.apply(target,params); 
		}
	}
	else {
		func =  function() {
			callback.apply(target,arguments);
		}
	}
	
	return func;
}


function newwin(url, w, h) {
	/*
	var ie_fullscreen = "";
	if (detectBrowser() == "IE")
	{
		ie_fullscreen = "fullscreen=yes";
	}

	if (w<1)
	{
		w = screen.availWidth;
	}

	if (h<1)
	{
		h = screen.availHeight;
	}
	*/

	if (w<1)
	{
		var popWin = window.open(url, "popWin", "toolbar=yes,resizable=yes,menubar=yes,location=yes,scrollbars=yes,status=yes");
	}
	else
	{
		var popWin = window.open(url, "popWin", "width="+w+",height="+h+",toolbar=yes,resizable=yes,menubar=yes,location=yes,scrollbars=yes,status=yes");
	}

	popWin.focus();
}

function detectOS()
{
	if (navigator.userAgent.indexOf('Win') == -1) {
		OS = 'Macintosh';
	} else {
		OS = 'Windows';
	}
	return OS;
}

function detectBrowser()
{
	if (navigator.appName.indexOf('Netscape') == -1) {
		browser = 'IE';
	} else {
		browser = 'Netscape';
	}
	return browser;
}




/*
	Online survey related
*/
var expDays = 30;
var pageCount = 2;
var page = "http://210.245.160.228/questionnaire/index_en.html";
var windowprops = "width=650,height=350,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";

function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie(name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function DeleteCookie(name)
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function initSurvey()
{
	var exp = new Date();
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

	var count = GetCookie('count');
	if (count == null) count = 0;
	//alert(count);
	count++;
	//window.status="count:"+count;
	SetCookie('count', count, exp, "/");
	if (count == pageCount)
	{
		var surveyWin = window.open(page, "surveyWin", windowprops);
		surveyWin.focus();
	}
}

function onlineSurvey()
{
}

//initSurvey();

/*change fontsize*/

//Specify spectrum of different font sizes:
var szs = new Array('75%', '100%', '125%');
//var szs = new Array('x-small', 'small', 'medium');
//var szs = new Array('1em', '1.05em', '1.10em', '1.15em');
var startSz = sz = szs.length;

function getFontSize()
{	
	if (getCookie('fontSize') == null)
	{		
		startSz = 1;
	}
	else
	{ 
		startSz = getCookie('fontSize');
		if (startSz == "NaN")	startSz = 1;
	}	
	changeFontSize(startSz, true);
}

function changeFontSize(inc, start)
{
	var d = document;
	
	if (!d.getElementById) return;
	var cEl = null,sz = eval(startSz),i,j,cTags;
	
	sz = inc;
	
	cEl = d.getElementsByTagName('body')[0];
	cEl.style.fontSize = szs[ sz ];	
	
	//Highlight Btn
	var topTools = d.getElementById('fontSelect').getElementsByTagName('a');
	for (var i=0; i<topTools.length; i++)
	{
		topTools[i].className = topTools[i].className.replace('active ', '');
		topTools[i].clicked = false;
	}
	topTools[sz].className = topTools[sz].className.replace('', 'active ');
	topTools[sz].clicked = true;
	
	setCookie("fontSize", sz, nd, cpath, cdomain);
}

var nd= new Date();
nd.setTime(nd.getTime()+(60*24*60*60*1000));
var cdomain = (location.domain) ? location.domain : null;
var cpath = "/";

function setCookie(name, value, expires, path, domain, secure)
{
  var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

  d.cookie = curCookie;
}

function getCookie(name)
{
	if (d.cookie.indexOf(name) < 0)
	{		
		return null;
	}
	else
	{	
		var startStr = d.cookie.indexOf(name) + name.length + 1;
		var endStr = d.cookie.indexOf(";", startStr);
		if (endStr == -1)	endStr = d.cookie.length;
		return unescape(d.cookie.substring(startStr, endStr));
	}
}
/*end of change fontsize*/

function startFading(el)
{
//return;
  if (el.fadinTimeout)	clearTimeout(el.fadinTimeout);
  //el.style.visibility = 'visible';
  //el.style.zIndex = 2;
  setOpacity(el, 0);
  fadeImage(el, 0);
}

function fadeImage(el, currentOpacity)
{
  currentOpacity += 1;

  if (currentOpacity > 100)
  {
    setOpacity(el, 100);
    //el.style.zIndex = 1;
	if (el.fadinTimeout)	clearTimeout(el.fadinTimeout);
  }
  else
  {
    setOpacity(el, currentOpacity);
    el.fadinTimeout = setTimeout(function() { fadeImage(el, currentOpacity); }, 10);
  }
}

function startFadingOut(el)
{
  if (el.fadinTimeout)	clearTimeout(el.fadinTimeout);
  //el.style.visibility = 'visible';
  //el.style.zIndex = 2;
  setOpacity(el, 100);
  fadeImageOut(el, 100);
}

function fadeImageOut(el, currentOpacity)
{
  currentOpacity -= 1;

  if (currentOpacity <= 0)
  {
    setOpacity(el, 0);
    //el.style.zIndex = 1;
	el.style.display = 'none';
	if (el.fadinTimeout)	clearTimeout(el.fadinTimeout);
  }
  else
  {
    setOpacity(el, currentOpacity);
    el.fadinTimeout = setTimeout(function() { fadeImageOut(el, currentOpacity); }, 10);
  }
}

function setOpacity(el, opacity)
{
	opacity /= 100;
	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";
}

var setMenu = 
{
	init:	function (obj)

	{
		setMenu.index = 0;
		this.container = document.getElementById(obj);
		var img = this.container.getElementsByTagName('img');
		setMenu.total = img.length;
		this.loopStart();
		setMenu.changeA(img[0], true);
	},
	
	changeA:	function (obj, fadeIn)
	{
		//alert(d.getElementById(obj));
		for (var i=0; i<setMenu.total; i++) {
			setTimeout(function(){if (this.container)	this.container.getElementsByTagName('img')[i].style.display = 'none';}, 400);
		}
		obj.style.display = 'block';
		if (obj.parentNode)	obj.parentNode.appendChild(obj);
		if (fadeIn)	startFading(obj);
		//setMenu.index++;
		if (setMenu.index >= setMenu.total)  {setMenu.index = 0;}
		setMenu.img = this.container.getElementsByTagName('img')[setMenu.index];
	},

	loopStart:	function ()
	{
		loop = true;
		setMenu.setTime();
	},
	
	setTime:	function()
	{
		
		//clearInterval(timeOut);
		
		var timeCompleted = function()
		{
			setMenu.changeA(setMenu.img, true);
			
		}
		timeOut = setInterval(timeCompleted, 6000);
	}

}

function init()
{
	if (document.getElementById('loopImg'))	setMenu.init('loopImg');
	//if (d.getElementById('loopImg'))	alert(123);
}


 
// Google Analytics tracking 
  var _gaq = _gaq || [];

  _gaq.push(['_setAccount', 'UA-17665629-1']);

  _gaq.push(['_trackPageview']);

 

  (function() {

    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

  })();

 


