// 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+=(i==where[0])? '<li class="open">':'<li class="hidden">';
				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/articles/qa.html",
    text: "שאלות ותשובות"},
  { href: "http://www.free.org.il/articles/meat_indust/articles_meatindutries.html",
    text: "תעשיות המזון מהחי",
    aLinks: [
      { href: "http://www.free.org.il/articles/meat_indust/articles_fish_main.html",
        text: "דגים",
				aLinks: [
				  { href: "http://www.free.org.il/articles/meat_indust/articles_fish_1.html",
					  text: "נידוגים למוות"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_fish_2.html",
					  text: "אילוץ הטלה"},
          {end:"menu3"}
				]},
      { href: "http://www.free.org.il/articles/meat_indust/articles_chicken_main.html",
        text: "תרנגולים",
				aLinks: [
				  { href: "http://www.free.org.il/articles/meat_indust/articles_chicken_1.html",
					  text: "על כרעי התרנגולת"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_chicken_2.html",
					  text: "עדות ממשחטת תרנגולים"},
          {end:"menu3"}
				]},
      { href: "http://www.free.org.il/articles/meat_indust/articles_cattle_main.html",
        text: "פרות",
				aLinks: [
				  { href: "http://www.free.org.il/articles/meat_indust/articles_cattle_1.html",
					  text: "עדות ממשחטת פרות"},
          {end:"menu3"}
				]},
      { href: "http://www.free.org.il/articles/meat_indust/articles_sheep_main.html",
        text: "כבשים"},
      { href: "http://www.free.org.il/articles/meat_indust/articles_veal.html",
        text: "עגלי חלב"},
      { href: "http://www.free.org.il/articles/meat_indust/articles_gease.html",
        text: "אווזים"},
      { href: "http://www.free.org.il/articles/meat_indust/articles_pig.html",
        text: "חזירים"},
      { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_main.html",
        text: "תעשיית הביצים",
				aLinks: [
				  { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_6.html",
					  text: "כמה כואב לאבד ביצה?"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_1.html",
					  text: "התרנגולת קודמת לביצה"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_2.html",
					  text: "קטימת מקורים"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_3.html",
					  text: "העיוות הגנטי של תרנגולות בתעשיית הביצים"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_4.html",
					  text: "אפרוחים בתעשיית הביצים - מיון, קיטום והשמדה"},
				  { href: "http://www.free.org.il/articles/meat_indust/articles_eggs_5.html",
					  text: "ביצי &quot;חופש&quot; - האמנם זכויות בעלי-חיים?"},
          {end:"menu2"}
				]},
      { href: "http://www.free.org.il/articles/meat_indust/articles_milk_main.html",
        text: "תעשיית החלב",
				aLinks: [
				  { href: "http://www.free.org.il/articles/meat_indust/articles_milk_1.html",
					  text: "מיתוס מול מציאות"},
          {end:"menu3"}
				]},
      { href: "http://www.free.org.il/articles/meat_indust/articles_honey.html",
        text: "דבש",
				aLinks: [
				  { href: "http://www.free.org.il/articles/meat_indust/articles_honey_1.html",
					  text: "מתוק שמשאיר טעם מר - הדבש ונזקיו לבעלי חיים, לאדם ולסביבה"},
          {end:"menu3"}
				]},
      {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/animal_rights/animal_rights.html",
    text: "זכויות בעלי חיים",
		aLinks: [
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_19.html",
			  text: "על בשר, מוסר וחיות אחרות"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_2.html",
			  text: "ללא הבדל דת, גזע ומין... ביולוגי"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_12.html",
			  text: "מה ההבדל?"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_14.html",
			  text: "הרגלים אינם אליבי לרצח"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_16.html",
			  text: "חייהם של אחרים"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_21.html",
			  text: "ספישיסיזם"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_5.html",
			  text: "זכויות אדם זכויות בעלי חיים"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_20.html",
			  text: "הפילוסופיה של זכויות בעלי-חיים"},
		  { href: "http://www.free.org.il/articles/animal_rights/animal_rights_17.html",
			  text: "הטיעון לזכויות בעלי-חיים"},
		  { href: "http://www.nrg.co.il/online/35/ART1/678/055.html",
			  text: "למען מה צריך להילחם?",
				target: true},
		  { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition.html",
			  text: "זכויות לעומת רווחה",
				aLinks: [
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_24.html",
			      text: "החשיבות של להיות כנה"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_13.html",
			      text: "מיתוס: הרג יכול להיות נחמד"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_26.html",
			      text: "מדוע רווחה לא יכולה להוביל לזכויות?"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_25.html",
			      text: "לשרת את העוולה: קידום מוצרי מזון מהחי"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_23.html",
    			  text: "פלישתם של חוטפי התנועה"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_15.html",
    			  text: "רווחה לעומת זכויות"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_18.html",
    			  text: "ארבע הבעיות בפעילות לרווחת בעלי-חיים"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_19.html",
    			  text: "חמלה למכירה"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_20.html",
    			  text: "תשובות לטיעונים בעד רווחה"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_21.html",
    			  text: "השערורייה של התנועה המודרנית למען בעלי-חיים"},
		      { href: "http://www.free.org.il/articles/animal_rights/abolition/abolition_22.html",
    			  text: "ההגיון המוזר של גישת הרווחה"},
					{end:"menu3"}
				]},
        {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/other_indust/articles_otherindustries.html",
    text: "תעשיות אחרות",
		aLinks: [
		  { href: "http://www.free.org.il/articles/other_indust/articles_vivisection.html",
        text: "ניסויים בבעלי חיים",
		    aLinks: [
    		  { href: "http://www.free.org.il/articles/other_indust/articles_vivisection_3.html",
    			  text: "סבל הוא סבל, דיכוי הוא דיכוי"},
    		  { href: "http://www.free.org.il/articles/other_indust/articles_vivisection_2.html",
    			  text: "נתיחות בבעלי-חיים בבתי ספר"},
    		  { href: "http://www.free.org.il/articles/other_indust/articles_vivisection_1.html",
    			  text: "חינוך - מדע החיים"},
    		  { href: "http://www.free.org.il/files/Lousky96.pdf",
    			  text: "ניסויים בבע&quot;ח - דוגמה מיושנת",
						target: true},
    		  { href: "http://www.shevi.org.il/files/print/AltNews-may_06.pdf",
    			  text: "חלופות לניסויים בבעלי חיים2",
						target: true},
    		  { href: "http://www.shevi.org.il/files/print/AltNews-feb_05.pdf",
    			  text: "חלופות לניסויים בבעלי חיים1",
						target: true},
            {end:"menu3"}
    		]},
		  { href: "http://www.free.org.il/articles/other_indust/articles_clothing.html",
        text: "ניצול בעלי חיים ללבוש"},
		  { href: "http://www.free.org.il/articles/other_indust/articles_circus.html",
        text: "קרקסים"},
		  { href: "http://www.free.org.il/articles/other_indust/articles_bullfight.html",
        text: "מלחמות שוורים",
		    aLinks: [
    		  { href: "http://www.free.org.il/articles/other_indust/articles_bullfight2.html",
    			  text: "הרג מסוגנן וקהל מריע"},
            {end:"menu3"}
    		]},
        {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/ecology/articles_ecology.html",
    text: "אקולוגיה",
		aLinks: [
		  { href: "http://www.free.org.il/articles/ecology/articles_ecology_1.html",
			  text: "רעיה שמרעה"},
		  { href: "http://www.free.org.il/articles/ecology/articles_ecology_2.html",
			  text: "טבעונות, אקולוגיה ובעיית הרעב בעולם"},
		  { href: "http://www.free.org.il/articles/ecology/articles_ecology_3.html",
			  text: "אוכלים את העולם למוות"},
		  { href: "http://www.free.org.il/articles/ecology/articles_ecology_4.html",
			  text: "הפתרון לבעיות הבריאות המרכזיות של האנושות ושל כדור הארץ הוא אחד"},
		  { href: "http://www.nrg.co.il/online/35/ART1/680/441.html",
			  text: "תעשיית החיות - המזהם מספר אחת",
				target: true},
        {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/literature/articles_literature.html",
    text: "ספרות",
		aLinks: [
		  { href: "http://www.free.org.il/articles/literature/articles_literature_1.html",
			  text: "&quot;אך כפסע בין לא תרצח ללא תשחט&quot;"},
		  { href: "http://www.free.org.il/articles/literature/articles_literature_2.html",
			  text: "&quot;כל יום הוא טרבלינקה&quot;- ספרו של צ'רלס פטרסון",
				aLinks: [
				  { href: "http://www.free.org.il/articles/literature/articles_literature_2_2.html",
					  text: "&quot;כל יום הוא טרבלינקה&quot; - שיר"},
					{end:"menu2"}
			]},
		  { href: "http://www.free.org.il/articles/literature/articles_literature_3.html",
			  text: "השוחט הרע והשוחט הטוב ביצירות יצחק בשביס זינגר"},
		  { href: "http://www.free.org.il/articles/literature/articles_literature_4.html",
			  text: "שואת בעלי החיים בכתבי יצחק בשביס זינגר"},
		  { href: "http://www.free.org.il/articles/literature/articles_literature_5.html",
			  text: "איה המשרתים - סיפורו של חתול הנתפס ומועבר לניסויים"},
		  { href: "http://www.free.org.il/articles/literature/articles_literature_6.html",
			  text: "זכויות בעלי-חיים: מה שוועדת נובל נכשלה בלהבחין בו"},
        {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/inter/articles_inter.html",
    text: "ראיונות",
		aLinks: [
		  { href: "http://www.free.org.il/articles/inter/articles_inter1.html",
			  text: "להתדיין עם פראנציון (ולאהוב את זה)"},
		  { href: "http://www.free.org.il/articles/inter/articles_inter2.html",
			  text: "כתבה על קארל לואיס"},
		  { href: "http://www.free.org.il/articles/inter/articles_inter3.html",
			  text: "פטי מארק"},
		  { href: "http://www.shevi.org.il/xhtml/articles/interviews/07_slovenia.html",
			  text: "ד&quot;ר ייאנז דרנובסק, נשיא סלובניה",
				target: true},
		  { href: "http://www.shevi.org.il/xhtml/articles/interviews/01_newkirk.html",
			  text: "אינגריד ניוקירק מארגון פטה",
				target: true},
		  { href: "http://www.shevi.org.il/xhtml/articles/interviews/03_lauren-orelans.html",
			  text: "לורן אורנלס מארגון ויוה",
				target: true},
        {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/jewish/articles_jewish.html",
    text: "יהדות",
		aLinks: [
		  { href: "http://www.jewishveg.com/index.html",
			  text: "אתר היהדות הצמחוני",
				target: true},
		  { href: "http://www.free.org.il/articles/jewish/articles_jewish_1.html",
			  text: "יהדות וצמחונות"},
		  { href: "http://www.free.org.il/articles/jewish/articles_jewish_2.html",
			  text: "היחס לבעלי החיים בתורה"},
        {end:"menu2"}
		]},
  { href: "http://www.free.org.il/articles/general/articles_general.html",
    text: "כללי",
		aLinks: [
		  { href: "http://www.free.org.il/articles/general/articles_general_1.html",
			  text: "zoom in - דקה בחייה של תרנגולת"},
		  { href: "http://www.free.org.il/articles/general/articles_general_11.html",
			  text: "מעמד בעלי חיים במשפט"},
		  { href: "http://www.free.org.il/articles/general/articles_general_10.html",
			  text: "האם היטלר היה צמחוני?"},
		  { href: "http://www.free.org.il/articles/general/articles_general_9.html",
			  text: "האם בשר הוא מזון טבעי לאדם?"},
		  { href: "http://www.free.org.il/articles/general/articles_general_8.html",
			  text: "אנחנו לא מלאכים..."},
		  { href: "http://www.free.org.il/articles/general/articles_general_6.html",
			  text: "צמחונות וטבעונות בצבא"},
		  { href: "http://www.free.org.il/articles/general/articles_general_4.html",
			  text: "הרחקת אורחים בלתי רצויים"},
        {end:"menu2"}
		]},
  {end:"menu1"}
];

// add the menu to screen
var oMenu=document.getElementById("right-nav");
if (oMenu) {
	oMenu.innerHTML = createHTMLMenu(aMenu);
}