// JavaScript Document

var maxpanel, maxTab;
var currMapDiv = 'map0';
maxpanel = 6;
maxTab = 6;




var showDiv = function(showDivID){
	var div = $(showDivID).setStyles({
		display:'block',
		opacity: 0
	});		
	new Fx.Style(div, 'opacity', {duration: 300} ).start(1.0);
};

var hideDiv = function(hideDivID){
	var div = $(hideDivID).setStyles({
		opacity: 0
	});		
	new Fx.Style(div, 'opacity', {duration: 300} ).start(0.0);
};

var hovershow = function(hovershow){
	var div = $(hovershow).setStyles({
		display:'block',
		opacity: 1
	});		
	new Fx.Style(div, 'opacity', {duration: 700} ).start(1);
};

var hoverhide = function(hovershow){
	var div = $(hovershow).setStyles({
		display:'none',
		opacity: 1
	});		
	new Fx.Style(div, 'opacity', {duration: 700} ).start(1);
};


function clearPanel (j){

	
			
if (j == 0){ 
//clear all
	for (i=1; i<= maxpanel; i++){
			panel = 'panel'+i; 
	        hideDiv(panel);
	        //document.getElementById(panel).style.visibility = 'hidden';			
	}

	
}else{
	//clear all except j
	for (i=1; i<= maxpanel; i++){
	     if (i == j){
		     //do nothing let the showhidepanel show i
         }else {
	        panel = 'panel'+i; 
	       hideDiv(panel);
	       // document.getElementById(panel).style.visibility = 'hidden';			
         }    	  
	}
	
}
}

function clearPhilMap(){
	for (i=1; i<= 6; i++){
			phmap = 'PHmap'+i; 
	        hideDiv(phmap);
  }
}

function clearRegionMap(j){

/*hide all regional Maps :) first things first*/
	        /* for (i=1; i<=maxpanel; i++){
				 map = 'map'+i;
				 hideDiv(map);
			 } */


	/*for (i=1; i<= maxpanel; i++){
	     if (i == j){
		     //do nothing let the showhidepanel show i
         }else {
	        map = 'map'+i; 
	        hideDiv(map);
         }    	  
	}*/
	
	
if (j == 0){
//clear all
	for (i=1; i<= maxpanel; i++){
			map = 'map'+i; 
	        hideDiv(map);
}
	

	

	
}else{
	//clear all except j
	for (i=1; i<= maxpanel; i++){
	     if (i == j){
		     //do nothing let the showhidepanel show i
         }else {
	        map = 'map'+i; 
	        hideDiv(map);
         }    	  
	}
	
}
	
		
	
}

	


function showHidePanel(i){
///alert('hellos');
// clearChurchMaps();
//clearRegionMap();


	
currMapDiv = 'map'+ i;

/*hide instruction and philippine map*/
hideDiv("panel0");
hideDiv("map0");


clearPanel(i);
clearRegionMap(i);
clearDetails('default', 'default' , 'default'); 
/*panel to show and map to hide*/
//panel = 'panel'+i;
//map = 'map'+i;
//showDiv(panel);
//showDiv(map); 


//manual clears 


panel = 'panel'+i;
map = 'map'+ i; 
showDiv(panel);
showDiv(map);

}

/*function determineRegion(r){
  if (r.indexOf('MM') != -1){ return 'MM';}
  if (r.indexOf('NL') != -1){ return 'NL';}
  if (r.indexOf('CL') != -1){ return 'CL';}
  if (r.indexOf('SL') != -1){ return 'SL';}
  if (r.indexOf('VS') != -1){ return 'VS';}
  if (r.indexOf('MN') != -1){ return 'MN';}
  if (r.indexOf('PH') != -1){ return 'PH';}
} */




function clearDetails(info, map, local){
var region  = new Array();
	region[0] = 'MM 13';
	region[1] = 'NL 13';
	region[2] = 'CL 5';
    region[3] = 'SL 14';
    region[4] = 'VS 6';
    region[5] = 'MN 6';
    region[6] = 'PH 6';
    
//	alert(info);
  
    
switch(info){
	
case 'default':
for (k=0 ; k <= maxpanel-1; k++){
	      
	
          details = region[k];
          details = details.split(' ');
          regionCode = details[0];
          
          //alert(regionCode);
          
          
		  maxCenters = Number(details[1]);
	          
          //alert(maxCenters);
		  
		  for (j=1; j<=maxCenters; j++){
		           cname = 'c_' + regionCode+j;
			       cinfo = regionCode+j;
		           cmap = regionCode + 'map' + j;
		           
		      
		      hideDiv(cinfo); 
		      hideDiv(cmap);
		      document.getElementById(cname).style.color = '#707070';
		           
		           
	      }  
} 

break;	
	
case 'forhover':
i = info;
c_map = map;
r = local;

//alert(i + c_map + r + currMapDiv);
/*k = 6 because of usemap PH*/

for (k=0 ; k<= 6; k++){
	details = region[k];
    details = details.split(' ');
    regionCode = details[0];
	maxCenters = Number(details[1]);
	
	
	if (regionCode == r){
	   //alert(regionCode + '=' + r);	
	   for (j=1; j<=maxCenters; j++){
		   
		   map = regionCode + 'map' + j;
		   hideDiv(map);
		  
		   
	   } 
	}
	
}

break;


	
	
default:
for (k=0 ; k<= maxpanel-1; k++){
          details = region[k];
          details = details.split(' ');
          regionCode = details[0];
		  maxCenters = Number(details[1]);
	          
         
		  
		  for (j=1; j<=maxCenters; j++){
		           cname = 'c_' + regionCode+j;
			       cinfo = regionCode+j;
		           cmap = regionCode + 'map' + j;
		           
		      
		     if (!(cinfo == info)) { hideDiv(cinfo); };
		     if (!(cmap == map)) { hideDiv(cmap); };
		     if (!(cname == local)) {  document.getElementById(cname).style.color = '#707070';	 };
		           
		           
	      }  
	} 
break;	
}  



  
}

/*church centric */
function showHideDetails(infoDiv, mapDiv, church){
		     //alert(church);
	         //clearDetails(m,infoDiv,mapDiv);
	         //clearChurchMaps();
			 /*show the info and the map of the church*/
			 //info = infoDiv+j;
			 //churchMap = mapDiv+j;
			 //showDiv(info);
			 //showDiv(churchMap);
			
			/*routine clears: clear all other church map and all other info*/ 
		    clearDetails(infoDiv, mapDiv, church); 
			
			currMapDiv = mapDiv;
			 
			/*hightlight the churh's color*/ 
	        document.getElementById(church).style.color = '#e8a71b';			 
			 
	       /*clears phil Maps*/
	       clearPhilMap();
	        
	        
			/*clear regions*/
			clearRegionMap(0);
						 
			
			/*show the info*/
			showDiv(infoDiv);
			showDiv(mapDiv);
			
			
			 
}

function toggleTab(showTabID){
	var i, tab, linkID;
	for (i=1; i<=maxTab; i++) {
                tab = "tab" + i;
                linkID = "link" + i;
		if (i!=showTabID) { 	
			offTab(tab, linkID);
		} else {
			onTab(tab, linkID);
		}
	}
	
	
	 /*clears phil Maps*/
	 clearPhilMap();
}

function onTab(tab, linkID) {
		document.getElementById(tab).style.background = "url(http://victory.org.ph/assets/templates/bluedots/images/dir-tab-on-r.gif) top right repeat-x";
		document.getElementById(linkID).style.background = "url(http://victory.org.ph/assets/templates/bluedots/images/dir-tab-on-l.gif) top left no-repeat";
}
function offTab(tab, linkID) {
		document.getElementById(tab).style.background = "url(http://victory.org.ph/assets/templates/bluedots/images/dir-tab-off-r.gif) top right repeat-x";
		document.getElementById(linkID).style.background = "url(http://victory.org.ph/assets/templates/bluedots/images/dir-tab-off-l.gif) top left no-repeat";
}



//hover only when region map is on top

function mouseover(map, region){
   //alert(currMapDiv);
    
    
  switch (currMapDiv){
	case 'map6':  
	case 'map5':   
	case 'map4':      
	case 'map3':   
	case 'map2':   
	case 'map1': 
	case 'map0':   
   
	clearDetails('forhover', map, region);
	if (!(map == currMapDiv)){hovershow(map);}
	break;
	
	default:
		//not region top but a local church
		
		//alert('here');
	
	break;
   }
	
}


function mouseout(){
	//alert(currMapDiv);
	
	switch (currMapDiv){
	case 'map6':  
	case 'map5':   
	case 'map4':      
	case 'map3':   
	case 'map2':   
	case 'map1':
	clearDetails('default', 'default' , 'default');
	break;
	
	case 'map0':
	
	clearPhilMap();
	
	default:
		//not region top but a local church
		
		//alert('here');
	
	break;
   } 
	
}