// return a command-line (GET URL Location.search) parameter
function getQueryParam(sName,sSearchLocation) {
    var sSearch=sSearchLocation; // copy value, just in case. i dont want to manipulate the real location.href by mistake...
    if (typeof(sSearch    )=='undefined') sSearch=document.location.search;
    if (typeof(sSearch.search)=='string') sSearch=sSearch.search;  // in case we got a Location object
    sSearch=sSearch.toString().replace(/^\?/,''); // remove first ?
    sSearch='&'+sSearch+'&';
    
    var res=sSearch.match(new RegExp('&'+sName+'=([^&]*)','i'));
    if (res && res.length>1) {
        return res[1];
    }else{
        return null;
    }
}

// return html content for the menu
function createHTMLMenu(aMenu) {
	var s,i,j,k;
	var myurl;
	var stext;
	var shref;
  var where = new Array();
  var myurl=location.href;
	var atarget;
  for (i=0;i<aMenu.length-1;i++) {
    if (aMenu[i].href==myurl) {
	    where[0]=i;
	  	break;
	  }
		if (typeof(aMenu[i].aLinks)!=="undefined") {
 	  	for (j=0;j<aMenu[i].aLinks.length-1;j++) {
   		  if (aMenu[i].aLinks[j].href==myurl) {
   		    where[0]=i;
   		    where[1]=j;
   				break;
   			}
				if (typeof(aMenu[i].aLinks[j].aLinks)!=="undefined") {
   			  for (k=0;k<aMenu[i].aLinks[j].aLinks.length-1;k++) {
   		      if (aMenu[i].aLinks[j].aLinks[k].href==myurl) {
   		        where[0]=i;
     		      where[1]=j;
     					where[2]=k;
     				  break;
     			  }
     	  	} // for k
				} // defined k
   		} // for j
		} // defined j
  } // for i

  s="<ul>";
    for (i=0;i<aMenu.length-1;i++) {
	    stext=aMenu[i].text;
		  shref=aMenu[i].href;
      if (typeof(aMenu[i].aLinks)=="undefined") {
				s+='<li><a href="' + shref + '"';
			  if (myurl==aMenu[i].href) s+=' class="current"';
	      if (typeof(aMenu[i].target)!="undefined") s+=' target="_blank"';
				s+='>' + stext + '</a></li>';
			}
			else {
			  s+= '<li class="open">';
				s+='<a href="' + shref + '"';
			  if (myurl==aMenu[i].href) s+=' class="current"';
	      if (typeof(aMenu[i].target)!="undefined") s+=' target="_blank"';
				s+='>' + stext + '</a><ul>';
  	  	for (j=0;j<aMenu[i].aLinks.length-1;j++) {
    		  stext=aMenu[i].aLinks[j].text;
    			shref=aMenu[i].aLinks[j].href;
          if (typeof(aMenu[i].aLinks[j].aLinks)=="undefined") {
    				s+='<li><a href="' + shref + '"';
    			  if (myurl==aMenu[i].aLinks[j].href) s+=' class="current"';
    	      if (typeof(aMenu[i].aLinks[j].target)!="undefined") s+=' target="_blank"';
    				s+='>' + stext + '</a></li>';
    			}
    			else {
    			  s+=((j==where[1]) && (i==where[0]))? '<li class="open">':'<li class="hidden">';
	  				s+='<a href="' + shref + '"';
	  		    if (myurl==aMenu[i].aLinks[j].href) s+=' class="current"';
	          if (typeof(aMenu[i].aLinks[j].target)!="undefined") s+=' target="_blank"';
		  		  s+='>' + stext + '</a><ul>';
    			  for (k=0;k<aMenu[i].aLinks[j].aLinks.length-1;k++) {
        		  stext=aMenu[i].aLinks[j].aLinks[k].text;
        			shref=aMenu[i].aLinks[j].aLinks[k].href;
     				  s+='<li><a href="' + shref + '"';
							if (myurl==aMenu[i].aLinks[j].aLinks[k].href) s+=' class="current"';
	            if (typeof(aMenu[i].aLinks[j].aLinks[k].target)!="undefined") s+=' target="_blank"';
						  s+='>' + stext + '</a></li>';
      	  	} // for 3
						s+="</ul></li>"
					} // defined 3
    		} // for 2
				s+="</ul></li>"
			} // defined 2
    } // for 1
	s+="</ul>";
	return s;
}

var aMenu = [
  { href: "http://www.free.org.il/english/movies/h.html",
    text: "Movies from Israel",
    aLinks: [
      { href: "http://www.free.org.il/english/movies/h/general.html",
        text: "General",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/h/general/endoftheworld.html",
				    text: "End of the World"},
				  { href: "http://www.free.org.il/english/movies/h/general/no_freedom.html",
  				  text: "Nature's illusion"},
  				{ href: "http://www.free.org.il/english/movies/h/general/animal_rights.html",
  				  text: "Animal rights"},
  				{ href: "http://www.free.org.il/english/movies/h/general/barbarim.html",
  				  text: "If they are barbarians, then what are we?"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/h/vegdiet.html",
        text: "The food industries",
				aLinks: [
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/cowmurder.html",
				    text: "Cows meat"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/sheepmurder.html",
  				  text: "Sheep meat"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/chickenmurder.html",
  				  text: "Chickens meat"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/fishmurder.html",
  				  text: "Fish meat"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/nuggets.html",
  				  text: "Nuggets"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/same-suffer.html",
  				  text: "Same suffer"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/pet-hurt.html",
  				  text: "One hand pet and the other one hurt"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/veals.html",
  				  text: "Veals"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/pitum.html",
  				  text: "Geese force feeding"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/eggs.html",
  				  text: "Eggs"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/milk.html",
  				  text: "Milk"},
  				{ href: "http://www.free.org.il/english/movies/h/vegdiet/difference.html",
  				  text: "What's the difference"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/h/activity.html",
        text: "Activity",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/h/activity/shan2007.html",
  				  text: "Shevi at 'Shantipi 2007'"},
				  { href: "http://www.free.org.il/english/movies/h/activity/act-shevi05.html",
  				  text: "Animal rights activity 2005"},
				  { href: "http://www.free.org.il/english/movies/h/activity/bombamela05.html",
  				  text: "Shevi at 'Boombamela 2005'"},
				  { href: "http://www.free.org.il/english/movies/h/activity/oct2nd05.html",
  				  text: "The 2.10 march 2005"},
          {end:"end of items"}
				]},
      {end:"end of items"}
  ]},
  { href: "http://www.free.org.il/english/movies/e.html",
    text: "Movies from abroad",
    aLinks: [
      { href: "http://www.free.org.il/english/movies/e/general.html",
        text: "General",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/general/world.html",
  				  text: "Paradise is here"},
				  { href: "http://www.free.org.il/english/movies/e/general/natural.html",
  				  text: "Are humans natural meat eaters?"},
  				{ href: "http://www.free.org.il/english/movies/e/general/freeme.html",
  				  text: "Free Me"},
  				{ href: "http://video.nbc4.com/player/?id=136474",
  				  text: "Veggie options - NBC",
						target: true},
  				{ href: "http://www.free.org.il/english/movies/e/general/ode.html",
  				  text: "Ode to the animals"},
				  { href: "http://www.free.org.il/english/movies/e/general/earthlings.html",
  				  text: "Earthlings"},
  				{ href: "http://www.free.org.il/english/movies/e/general/carl_lewis.html",
  				  text: "An interview with Carl Lewis"},
  				{ href: "http://www.free.org.il/english/movies/e/general/cruelty.html",
  				  text: "Cruelty"},
  				{ href: "http://www.peta2.com/alp/index.asp",
  				  text: "Animal rights presentation",
						target: true},
  				{ href: "http://www.free.org.il/english/movies/e/general/tom2.html",
  				  text: "the case for animal rights"},
  				{ href: "http://www.free.org.il/english/movies/e/general/tom.html",
  				  text: "Animal rights philosophy"},
  				{ href: "http://www.animalaid.org.uk/h/f/CAMPAIGNS/blog//4//?be_id=5",
  				  text: "Choose life - Go vegetarian",
						target: true},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/e/vegdiet.html",
        text: "The food industry",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/vegdiet/cow_murder.html",
  				  text: "Cows murder"},
				  { href: "http://www.free.org.il/english/movies/e/vegdiet/cow_murder2.html",
  				  text: "Cows murder2"},
				  { href: "http://www.free.org.il/english/movies/e/vegdiet/kosher_slaughter.html",
  				  text: "'kosher' slaughter"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/pig_murder.html",
  				  text: "Pigs murder"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/pig_abuse.html",
  				  text: "Hidden camera in pigs farm"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/meetmeat.html",
  				  text: "Meet your meat"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/prepared.html",
  				  text: "How meat is prepared"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/truthordairy.html",
  				  text: "Truth or dairy"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/meatfreemedia_nz.html",
  				  text: "Factory farming in New Zealand"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/chew.html",
  				  text: "Chew on this"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/transport2.html",
  				  text: "Some Lie Dying"},
  				{ href: "http://www.free.org.il/english/movies/e/vegdiet/meatrix.html",
  				  text: "The meatrix"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/e/wear.html",
        text: "The clothing industries",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/wear/leather.html",
  				  text: "Leather"},
				  { href: "http://www.free.org.il/english/movies/e/wear/wool.html",
  				  text: "Wool"},
  				{ href: "http://www.free.org.il/english/movies/e/wear/furfull.html",
  				  text: "Fur - full version"},
  				{ href: "http://www.free.org.il/english/movies/e/wear/furshort.html",
  				  text: "Fur - short version"},
  				{ href: "http://www.free.org.il/english/movies/e/wear/canada_seal.html",
  				  text: "Seals fur"},
  				{ href: "http://www.free.org.il/english/movies/e/wear/pam_fur.html",
  				  text: "Pamela Anderson against fur"},
  				{ href: "http://www.free.org.il/english/movies/e/wear/pam_leather.html",
  				  text: "Pamela Anderson against leather"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/e/activity.html",
        text: "Activity",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/activity/pigs_rescue.html",
  				  text: "Pigs rescue"},
				  { href: "http://www.free.org.il/english/movies/e/activity/chickens_rescue.html",
  				  text: "Chickens rescue"},
  				{ href: "http://www.free.org.il/english/movies/e/activity/shac_06_07.html",
  				  text: "SHAC: Close down HLS"},
  				{ href: "http://www.free.org.il/english/movies/e/activity/lb.html",
  				  text: "Liberation Now"},
  				{ href: "http://www.free.org.il/english/movies/e/activity/tfa3.html",
  				  text: "Time for Action"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/e/vivisection.html",
        text: "Vivisection",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/vivi/paradiselost.html",
  				  text: "Lost paradise"},
				  { href: "http://www.free.org.il/english/movies/e/vivi/cat.html",
  				  text: "And the cat enjoys this?"},
				  { href: "http://www.free.org.il/english/movies/e/vivi/animal_testing.html",
  				  text: "Vivisection"},
				  { href: "http://www.free.org.il/english/movies/e/vivi/bad_medicine.html",
  				  text: "Bad medicine"},
  				{ href: "http://www.free.org.il/english/movies/e/vivi/covance.html",
  				  text: "Hidden camera in COVANCE labs"},
  				{ href: "http://www.free.org.il/english/movies/e/vivi/professor.html",
  				  text: "Vivisection in the modern era"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/e/ad.html",
        text: "Commercials",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/ad/casey.html",
  				  text: "vegetarianism commercial with Casey Affleck"},
				  { href: "http://www.free.org.il/english/movies/e/ad/if_only_you_knew.html",
  				  text: "If only you knew..."},
				  { href: "http://www.free.org.il/english/movies/e/ad/fur.html",
  				  text: "What if you were killed for fur?"},
				  { href: "http://www.free.org.il/english/movies/e/ad/peta_biology.html",
  				  text: "Biology: The study of Life, not death"},
  				{ href: "http://www.free.org.il/english/movies/e/ad/ida.html",
  				  text: "Veganism commercial with Kenneth Williams"},
  				{ href: "http://www.free.org.il/english/movies/e/ad/apa.html",
  				  text: "Don't abandon dogs"},
          {end:"end of items"}
				]},
      { href: "http://www.free.org.il/english/movies/e/other.html",
        text: "Miscellaneous",
				aLinks: [
				  { href: "http://www.free.org.il/english/movies/e/other/pig_slaughter.html",
  				  text: "Laos pig slaughter"},
  				{ href: "http://www.free.org.il/english/movies/e/other/inyourhands.html",
  				  text: "Their future is in your hands"},
  				{ href: "http://www.free.org.il/english/movies/e/other/bull-fight.html",
  				  text: "Bull fight"},
          {end:"end of items"}
				]},
      {end:"end of items"}
  ]},
  { href: "http://www.free.org.il/english/movies/ark.html",
    text: "All the movies"},
  {end:"end of menus"}
];

// add the menu to screen
var oMenu=document.getElementById("left-nav");
if (oMenu) {
	oMenu.innerHTML = createHTMLMenu(aMenu);
}