var ready = 0, next = 2, loaded = 0;
var mapSize = 1;
var available = 1;
function toggleTab(num, numelems, control) {
	if(ready == 0) {
		next = num;
    } else if($('tabHeader'+num) && $('tabHeader'+num).className != 'tabHeaderActive'){
    	if(num == 1 && control == 1 && available && mapSize == 0) {
	    	for(var i = 1; i <= numelems; i++) {
				if($('tabHeader'+i).className == 'tabHeaderActive') {
					$('tabHeader'+i).className = "tabHeaderInactive";
				}
				if($('tabContent'+i) && $('tabContent'+i).style.display != 'none'){
     			   toggleDisp('tabContent'+i);
    			}
			}
			$('tabHeader'+num).className = "tabHeaderActive";
			toggleDisp('tabContent'+control);
    		new Effect.Fade('news2', {duration: .5, afterFinish: function(obj) {
    			new Effect.Appear('homeHide', {duration: .5});
    		}});
    	} else if($('tabHeader1').className == "tabHeaderActive" && num != 1 && mapSize == 0) {
    		 new Effect.Fade('homeHide', {duration: .5, afterFinish: function(obj) {
    			new Effect.Appear('news2', {duration: .5, afterFinish: function(obj) {
		    		for(var i = 1; i <= numelems; i++) {
						if($('tabHeader'+i).className == 'tabHeaderActive') {
							$('tabHeader'+i).className = "tabHeaderInactive";
						}
						if($('tabContent'+i) && $('tabContent'+i).style.display != 'none'){
		     			   toggleDisp('tabContent'+i);
		    			}
					}
					$('tabHeader'+num).className = "tabHeaderActive";
					toggleDisp('tabContent'+control);
    			}});
    		}});
    	} else if(num != 1 || available){
	        for(var i = 1; i <= numelems; i++){
				var temph = 'tabHeader'+i;
				var h = $(temph);
				if (h.className == 'tabHeaderActive'){
					var h = $('tabHeader'+i);
					h.className = "tabHeaderInactive";
				}
				var tempc = 'tabContent' + i;
	            var c = $(tempc);
	            if(c && c.style.display != 'none'){
	                toggleDisp(tempc);
	            }
	        }
	        
	        var h = $('tabHeader'+num);
	        if (h)
	            h.className = 'tabHeaderActive';
	        h.blur();
	        var c = $('tabContent'+control);
	        toggleDisp('tabContent'+control);
	        
	        if(num != 1) {
	        	var addLoc = $("addrLoc");
	        	var llLoc = $("latlonLoc");
	        	if(num == 2) {
	        		addLoc.style.display = 'block';
	        		llLoc.style.display = 'none';
	        	} else {
	        		addLoc.style.display = 'none';
	        		llLoc.style.display = 'block';
	        	}
	        	if(loaded == 0) {
	        		validateMapPosition();
	        		loaded = 1;
	        	}
				resizeMap();
			}
		}	
	}
}
function toggleDisp(dispr) {
	var d = $(dispr);
	d.style.display = (d.style.display == 'none'? 'block' : 'none');
}
window.onload = function() {
	ready = 1;
	toggleTab(next, 3, (next == 1? 1:2));
};