jsG = new Object();
jsG.map = null;
jsG.first = true;
jsG.hno = 0;
jsG.hname = '';
jsG.geo = new Array();

function initializeMap() {
    var myLatlng = new google.maps.LatLng(jsG.geo[0],jsG.geo[1]);
    var myOptions = {
      zoom: 17,
      center: myLatlng,
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
      zoomControl: true,
      zoomControlOptions: {
        style: google.maps.ZoomControlStyle.LARGE
      },
      mapTypeId: google.maps.MapTypeId.HYBRID
    }
    
    jsG.map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

    var contentString = ''+
        '<div id="infowin">'+
        '<img src="http://img1.siameservices.com/'+jsG.hno+'/logo.gif"/>'+
        '</div>'+
        '';    

    var infowindow = new google.maps.InfoWindow({
        content: contentString,
	     maxWidth: 240
    });

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: jsG.map,
        title:jsG.hname
    });

    jsG.map.resize = function() {
        if(jsG.first) {  
            google.maps.event.trigger(jsG.map, "resize");
            jsG.map.setZoom( jsG.map.getZoom() );
            jsG.map.setCenter(myLatlng);
            jsG.first = false; 
        } 
    }

    google.maps.event.addListener(marker, 'click', function() {
       infowindow.open(jsG.map,marker);
    });
}
 
function loadGoogleMap() { 
    p = document.getElementById('gvar_geo');
    if (p && p.title) jsG.geo = p.title.split('|');
    else return;

    p = document.getElementById('gvar_hno');
    if (p && p.title) jsG.hno = p.title;

    p = document.getElementById('gvar_hname');
    if (p && p.title) jsG.hname = p.title;

    p = document.getElementById('gvar_lang');
    if (p && p.title) jsG.lang = p.title;

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.google.com/maps/api/js?v=3.3&sensor=false&callback=initializeMap&language="+jsG.lang;
    document.body.appendChild(script);
}

function location_jump() {
    var w = document.locationsform.locationlist.selectedIndex;
    var url_add = document.locationsform.locationlist.options[w].value;
    window.location.href = url_add;
}

/* tabify */
(function($){ 
     $.fn.extend({  
         tabify: function( callback ) {
         	
			function getHref(el){
				hash = $(el).find('a').attr('href');
				hash = hash.substring(0,hash.length-4);
				return hash;
			}
			
		 	function setActive(el){
		 		
				$(el).addClass('active');
				$(getHref(el)).show();
				$(el).siblings('li').each(function(){
					$(this).removeClass('active');
					$(getHref(this)).hide();
				});
                		if(getHref(el) == '#themap'){
                    			if ((jsG.map != null) && jsG.first) {
                        			jsG.map.resize(); 
                    			} 
                		} 
			}
			
			return this.each(function() {
			
				var self = this;
				var	callbackArguments 	=	{'ul':$(self)};
					
				$(this).find('li a').each(function(){
					$(this).attr('href',$(this).attr('href') + '-tab');
				});
				
				function handleHash(){
					
					if(location.hash && $(self).find('a[href=' + location.hash + ']').length > 0){		
						setActive($(self).find('a[href=' + location.hash + ']').parent());
					}
				}
				
				if(location.hash){
					handleHash();
				}
					
				setInterval(handleHash,100);
				
				$(this).find('li').each(function(){
					if($(this).hasClass('active')){
						$(getHref(this)).show();
					} else {
						$(getHref(this)).hide();
					}
				});
				
				if(callback){
					callback(callbackArguments);
				}	
				
            }); 
        } 
    }); 
})(jQuery);

$(document).ready(function() {
  loadGoogleMap();
  $('#tabmenu').tabify();
});



