// JavaScript Document

function submitMap()
{
	if($('country').value == '')
	{
		alert('Selecteer aub een land voor deze zoekopdracht.');
	}
	else
	{
		if(!$('groepsreis_check').checked && !$('prive_check').checked)
		{
			alert('Selecteer aub een categorie voor deze zoekopdracht.');
		}
		else
		{
			
			
			//alert($('searchmap').action)
			window.location.href = $('searchmap').action+='?country='+$('country').value + '&category=' + ($('groepsreis_check').checked ? 'groep,' : '') + ($('prive_check').checked ? 'prive,' : '');
			//+($('groepsreis_check').checked ? 'groep,' : '')+($('prive_check').checked ? 'prive,' : '')+($('single_check').checked ? 'single,' : '')
			//.checked && !$('singlereis_check').checked && !$('prive_check').checked'&category=groep,prive,single';
			//$('searchmap').submit();
		}
	}
	//document.searchmap.submit()
}


var Maps = Class.create(
{
   initialize: function()
   {
	this.preloadedImg = false;
      //
	//this.map = $('map');
   },
   
  
  //	mouse over continents
  continent_mo: function(continent)
  {
    //alert(continent);
    switch(continent)
    {
	   case "LA":
	     topposition = -210;
		  break;
	   case "Afrika":
		  topposition = -420;
		  break;
	   case "Azie":
		  topposition = -630;
		  break;
    }
    
    $('map').style.backgroundPosition = '0 '+topposition+'px';
  
  },

  country_mo: function(country)
  {
    //alert(country + this.continent);
    switch(this.continent)
    {
	case "LA":
	  switch(country)
	  {
	    case "back":		topposition = -210;	break;
	    case "Brazilie":	topposition = -420;	break;
	    case "Argentinie":	topposition = -630;	break;
	    case "Bolivia":	topposition = -840;	break;
	    case "Peru": 		topposition = -1050;	break;
	    case "Ecuador": 	topposition = -1260;	break;
	    case "Panama": 	topposition = -1470;	break;
	    case "CostaRica": 	topposition = -1680;	break;
	    case "Nicaragua": 	topposition = -1890;	break;
	    case "Honduras": 	topposition = -2100;	break;
	    case "Guatamala": 	topposition = -2310;	break;
	    case "Belize": 	topposition = -2520;	break;
	    case "Mexico":	topposition = -2730;	break;
	  }
	  break;
	case "Afrika":
	  switch(country)
	  {
	    case "back":		topposition = -210;	break;
	    case "Marokko":	topposition = -420;	break;
	    case "Egypte":	topposition = -630;	break;
	    case "Jordanie":	topposition = -840;	break;
	    case "Kenia": 	topposition = -1050;	break;
	    case "Tanzania": 	topposition = -1260;	break;
	    case "Zambia": 	topposition = -1470;	break;
	    case "Botswana": 	topposition = -1680;	break;
	    case "Namibie": 	topposition = -1890;	break;
	    case "ZuidAfrika": 	topposition = -2100;	break;
	  }
	  break;
	case "Azie":
	  switch(country)
	  {
	    case "back":		topposition = -210;	break;
	    case "China":		topposition = -420;	break;
	    case "Tibet":		topposition = -630;	break;
	    case "Nepal":		topposition = -840;	break;
	    case "India": 	topposition = -1050;	break;
	    case "SriLanka": 	topposition = -1260;	break;
	    case "Vietnam": 	topposition = -1470;	break;
	    case "Laos": 		topposition = -1680;	break;
	    case "Cambodja": 	topposition = -1890;	break;
	    case "Thailand": 	topposition = -2100;	break;
	    case "Indonesie": 	topposition = -2310;	break;	    
	  }
	  break;
    }
    $('map').style.backgroundPosition = '0 '+topposition+'px';
  },
  
  swapContinent: function(continent,area)
  {
	// alert(area)
	if(area) area.blur();
    
    this.continent = continent;
    
    switch(continent)
    {
    case "LA":
	   src = 'homepage-latijnsamerika.gif';
	   break;
	case "Azie":
	  src = 'homepage-azie.gif';
	  break;
	case "Afrika":
	  src = 'homepage-afrika.gif';
	  break;
    }
    img = 'url(/images/'+src+')';
    //alert(img);
    $('map').style.backgroundImage = img;
    //this.mapReset(); 
    this.setImageMap(continent);
    
    return false;
    
  },
  
  goBack: function(area)
  {
    area.blur();
    
    $('mapSprite').removeAttribute('useMap');
    this.setImageMap('world');
    //alert(1);
    this.mapReset();
    //alert(2);
    this.continent = '';
    //alert(3);
    img = 'url(/images/homepage-wereldkaart.gif)';
   
    $('map').style.backgroundImage = img;
    //alert(4);
    
    
    return false;
  },
  
  mapReset: function()
  {
    $('map').style.backgroundPosition = '0 0';
  },
  
  preloadImages: function()
  {
    if(!this.preloadedImg)
    {
	var imgLa = new Image;
	imgLa.src = '/images/homepage-latijnsamerika.gif';
	
	var imgAzie = new Image;
	imgAzie.src = '/images/homepage-azie.gif';
	
	var imgAfrika = new Image;
	imgAfrika.src = '/images/homepage-afrika.gif';
	
	this.preloadedImg = true;
    }
  },
  
  setImageMap: function(map)
  {
    $('mapSprite').setAttribute("useMap", "#"+map);
  },
  selectCountry: function(country)
  {
    //	add value to hidden input
    $('country').value = country;
	//!$('singlereis_check').checked && 
	if(!$('groepsreis_check').checked && !$('prive_check').checked)
	{
		alert('Selecteer aub een categorie voor deze zoekopdracht.');
	}
	else
	{
		window.location.href = $('searchmap').action+='?country='+$('country').value + '&category=' + ($('groepsreis_check').checked ? 'groep,' : '') + ($('prive_check').checked ? 'prive,' : '');
		//($('singlereis_check').checked ? 'single,' : '')
    	//$('searchmap').submit();
	}
  }
});

//	on window load -> start map navigation
//Event.observe(window, 'load', function() {

  var maps = new Maps();

//});

Event.observe(window, 'load', function() {
  
  //	add behaviours to all subitems of world-imagemap
//  $('world').childElements().each(function(area){
//    
//    areaName = '';
//    areaArray = area.id.split('_');
//    areaName = areaArray[1];
//    
//    alert(area.id);
//    
//    Event.observe(area.id, 'mouseover', function() {
//	
//	maps.continent_mo(areaName);
//    });
//
//    Event.observe(area.id, 'mouseout', function() {
//	maps.mapReset();
//    });
//    
//    Event.observe(area.id, 'click', function() {
//	maps.swapContinent(areaName,area);
//    });
//    
//  });
});
