var range = 0;
var heightScroll = 0;

function preLoad()
{
	var viewportwidth;
	var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
 
	// older versions of IE
 
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	//alert('Your viewport width is '+viewportwidth+'x'+viewportheight);
	var wrapperTop = (viewportheight - $("#wrapper-home").height())/2;
	var wrapperLeft = (viewportwidth - $("#wrapper-home").width())/2;
	//alert('Your viewport width is '+wrapperTop+'x'+wrapperLeft);
	$("#wrapper-home").css("top",wrapperTop + "px");
	$("#wrapper-home").css("left",wrapperLeft + "px");
	
	if (document.getElementById){
		$("#pre-loader img").hide();
		$("#pre-loader").fadeOut(500);
	} 
	else {
		if (document.layers){ //NS4
			document.preloader.visibility = 'hidden';
		} else { //IE4
			document.all.preloader.style.visibility = 'hidden';
		}
	}    
}

function setPosition()
{
	var viewportwidth;
	var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
 
	// older versions of IE
 
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	//alert('Your viewport width is '+viewportwidth+'x'+viewportheight);
	var wrapperTop = (viewportheight - $("#wrapper-home").height())/2;
	var wrapperLeft = (viewportwidth - $("#wrapper-home").width())/2;
	$("#wrapper-home").css("top",wrapperTop + "px");
	$("#wrapper-home").css("left",wrapperLeft + "px");
}

window.onresize = setPosition;

function initializeHanoi() {
    if (document.getElementById("map_canvas")) {
        var latlng = new google.maps.LatLng(21.018568, 105.85472);
        var myOptions = {
          zoom: 19,
          center: latlng,
	      disableDefaultUI: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
		
	    var image = 'images/mark.png';
	    var shadow = 'images/logo_shadow.png';
	    var myLatLng = new google.maps.LatLng(21.018558, 105.85472);
	    var beachMarker = new google.maps.Marker({
          position: myLatLng,
	      map: map,
          icon: image,
	      shadow: shadow	  
	    });
	}
	preLoad();
}

function initializeHCM() {
    if (document.getElementById("map_canvas")) {
        var latlng = new google.maps.LatLng(10.776303, 106.685808);
        var myOptions = {
            zoom: 19,
            center: latlng,
            disableDefaultUI: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);

        var image = 'images/mark.png';
        var shadow = 'images/logo_shadow.png';
        var myLatLng = new google.maps.LatLng(10.776303, 106.685808);
        var beachMarker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            icon: image,
            shadow: shadow
        });
    }
    preLoad();
}

function setLocationContact() {
    if (document.getElementById("map_canvas")) {
        alert("dcm");
    }
}

function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
