var sitename="http://kids.gov.il";

var url=location.href;

var base=url.substr(0,url.indexOf(sitename)+sitename.length)+"/";

document.font_sizes_arr=[{img:'acc_a4_off.png' ,size:-0.2},{img:'acc_a3_off.png' ,size:0},{img:'acc_a2_off.png' ,size:0.2},{img:'acc_a1_off.png' ,size:0.3}];
document.current_font_size=1;

function goHomepage()
{
	
	if(window.subbase==undefined) location.href=base;
	else  location.href=base+"/"+subbase;
	}

function goSitemap()
{
	
	location.href=base+"info/sitemap.html";
}



function writeBottomMenu()
{
	
		// <![CDATA[	
	//	alert(base+"flash/frame_bar/frame_bar.swf")
		//	alert(base+"xml/frame_bar.xml")
		var so1 = new SWFObject(base+"flash/frame_bar/frame_bar.swf", "bottom", "436", "50", "8", "#ffffff"); // military_scool6 //al_ha_gova33opt
		
		so1.addParam("wmode","transparent");
		so1.addVariable("xmlpath",base+"xml/frame_bar.xml");
		so1.addParam("allowScriptAccess","always");
		//so1.addVariable("specialOrder","border");
		//so1.addParam("salign","tl");	
		//so1.addParam("scale","noscale");	
		so1.write("bottom_menu");
		// ]]>
			
}

function detectBrowser()
{

	if(navigator.appName.indexOf("Microsoft")==-1)return;
	document.explorerVersion=parseInt(navigator.userAgent.substr(navigator.userAgent.indexOf("MSIE ")+5 , 1))
	if(document.explorerVersion<=6 )location.href=base+"browser/";
	//	alert(explorerVersion)
}

detectBrowser();

function getFlashMovie(movieName) 
{   
//	alert(movieName)
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	//alert((isIE) ? window[movieName] : document[movieName])
	return (isIE) ? window[movieName] : document[movieName];

}  

function setMute(flag) 
{   
	button=document.getElementById("button_mute");
	if(button.isMutedFlag==undefined) button.isMutedFlag=false;
	if(button.isMutedFlag){
		backgroundImage="url("+base+"images/mute.png)";		
		alt="השתק קול"
	}	
	else {
		backgroundImage="url("+base+"images/mute_on.png)";
		alt="נגן קול"
	}
	button.style.backgroundImage=backgroundImage;
	button.alt=button.title=alt;
	button.isMutedFlag=!(button.isMutedFlag)
	 //  alert(button.style.backgroundImage)

	if(flag==undefined)
	{
		gameFlash_obj=getFlashMovie("gameFlash");
		if(gameFlash_obj!=undefined)	{gameFlash_obj.setMute();}	
		gameFlash2_obj=getFlashMovie("flashbook");
		if(gameFlash2_obj!=undefined) gameFlash2_obj.setMute();
		gameFlash2_obj=getFlashMovie("flashbook");

		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		if(isIE)
		{
			ghettoPlayer=		document.Player
			if(ghettoPlayer!=undefined) ghettoPlayer.mute =!document.Player.mute;//.stop();//gameFlash2_obj.setMute();
		}
		else
		{
				ghettoPlayer=		document.getElementById("Player")
			//if(location.href.indexOf("/ghetto/")!=-1 && document.getElementsByTagName("Embed")[0]!=undefined  && //document.getElementsByTagName("Embed")[0].type=="application/x-mplayer2")
			{
			//	ghettoPlayer=		document.getElementsByTagName("Embed")[0]
				if(ghettoPlayer!=undefined) ghettoPlayer.mute=false; //!document.Player.mute;//.stop();//gameFlash2_obj.setMute();

			}	
			
//			Embed type="application/x-mplayer2"
		}
	//	ghettoPlayer=document.Player
	
	}
}    

function getTextFromFlash(str) 
{   
	document.htmlForm.receivedField.value = "From Flash: " + str;   
	return str + " received";  
} 

function initFooterStuff()
{
	$('#button_send , a[href="#contact"] ').click(function(e) { contact(e)  });

	$('img.share.print ').parent().attr("href","javascript:window.print();")

	_btn=document.getElementById("button_mute");
	if(_btn==undefined)return;
	if(window.audioFlag==undefined || window.audioFlag==false)
	{
		_btn.style.backgroundImage="url("+base+"images/mute_off.png)";
		_btn.style.cursor="none";
		_btn.alt=_btn.title="קול לא פעיל";
	}
	else
	{
		if(_btn.isMutedFlag==undefined) _btn.isMutedFlag=false;
		_btn.onmouseover=function(){this.style.backgroundImage="url("+base+"images/mute_on.png)"}
		_btn.onmouseout=function(){if(!_btn.isMutedFlag)this.style.backgroundImage="url("+base+"images/mute.png)"};
		_btn.onclick=function(){setMute();}
	}
	//button=document.getElementById("button_key");
	//button.onmouseover=function(){this.style.backgroundImage="url("+base+"images/key_on.png)"}
	//button.onmouseout=function(){this.style.backgroundImage="url("+base+"images/key.png)"}

	button=document.getElementById("button_home");
	button.onmouseover=function(){this.style.backgroundImage="url("+base+"images/home_on.png)"}
	button.onmouseout=function(){this.style.backgroundImage="url("+base+"images/home.png)"}

	button=document.getElementById("button_map");
	button.onmouseover=function(){this.style.backgroundImage="url("+base+"images/map_on.png)"}
	button.onmouseout=function(){this.style.backgroundImage="url("+base+"images/map.png)"}

	button=document.getElementById("button_send");
	button.onmouseover=function(){this.style.backgroundImage="url("+base+"images/send_on.png)"}
	button.onmouseout=function(){this.style.backgroundImage="url("+base+"images/send.png)"}

	button=document.getElementById("button_search");
	if(button==undefined){}
	else
	{
	button.onmouseover=function(){this.style.backgroundImage="url("+base+"images/find_on.png)"}
	button.onmouseout=function(){this.style.backgroundImage="url("+base+"images/find.png)"}
	}

	
	

	$('#size_up').click(function(){changeFontSize(true)});
	$('#size_down').click(function(){changeFontSize(false)});

}



function closeContact()
{
	 $('#mask').click();
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function accessibility()
{

if( $('#footer_acc_open').css("display")=="none")
	{
	if(navigator.appName.indexOf("Microsoft")==-1)
		{
			$('#footer_acc_close').fadeOut("slow")
			$('#footer_acc_open').fadeIn("slow");	
			$('#accessibility_box').fadeIn("slow");
			$('#button_about').animate({    "marginTop": 73  }, "slow", function() {    /* Animation complete. */ });
			$('#button_teachers').animate({    "marginTop": 73  }, "slow", function() {    /* Animation complete. */ });
			$('#button_parents').animate({    "marginTop": 73  }, "slow", function() {    /* Animation complete. */ });
			$('#bottom_menu').animate({    "marginTop": 6  }, "slow", function() {    /* Animation complete. */ });
		}
	else
		{
			$('#footer_acc_close').hide()
			$('#footer_acc_open').show();
			$('#accessibility_box').show();
			$('#button_about').css("marginTop",73);
			$('#button_teachers').css("marginTop",73);
			$('#button_parents').css("marginTop",73);
			$('#bottom_menu').css("marginTop",6);
		}

		
		$('#frame_bottom_right').css("background-image","url("+base+"images/frame_bottom_right_acc_open.png)")

	}
else {
		if(navigator.appName.indexOf("Microsoft")==-1)
		{
			$('#footer_acc_close').fadeIn("slow")
			$('#footer_acc_open').fadeOut("slow");
			$('#accessibility_box').fadeOut("slow");
			$('#button_about').animate({    "marginTop": 43  }, "slow", function() {    /* Animation complete. */ });
			$('#button_teachers').animate({    "marginTop": 43  }, "slow", function() {    /* Animation complete. */ });
			$('#button_parents').animate({    "marginTop": 43  }, "slow", function() {    /* Animation complete. */ });
			$('#bottom_menu').animate({    "marginTop": -14  }, "slow", function() {    /* Animation complete. */ });
		}
	else
		{
			$('#footer_acc_close').show()
			$('#footer_acc_open').hide();
			$('#accessibility_box').hide();
			$('#button_about').css("marginTop",43);
			$('#button_teachers').css("marginTop",43);
			$('#button_parents').css("marginTop",43);
			$('#bottom_menu').css("marginTop",-14);
		}

		
		$('#frame_bottom_right').css("background-image","url("+base+"images/frame_bottom_right_acc_close.png)")
	}
}

function changeFontSize(dir)
{
	/*
	var $headers=$(".acc_fontsize")
	$headers.each(function(i){
		var $curobj=$(this)
		$curobj.css("background-image","url("+base+"images/acc_a"+(i+1)+"_"+(((i+1)!=index)?"off":"on")+".png)")	 
	})
	*/
//alert(document.current_font_size)
	if(dir)
	{
		document.current_font_size++;
		$("#size_down").removeClass("fade");
		$("#size_down").removeAttr("disabled");
		if(document.current_font_size==document.font_sizes_arr.length-1)
		{
			$("#size_up").addClass("fade");
			$("#size_up").attr("disabled","disabled");		
		}
	}
	else
	{
		document.current_font_size--;
		$("#size_up").removeClass("fade");
		$("#size_up").removeAttr("disabled");
		if(document.current_font_size==0)
		{
			$("#size_down").addClass("fade");
			$("#size_down").attr("disabled","disabled");
		}
	}

	$("#size_letter").css("background-image","url("+base+"images/"+document.font_sizes_arr[document.current_font_size].img+")")

	size=document.font_sizes_arr[document.current_font_size].size;



	if(document.initFontSizeNum==undefined)
	{	
		cur_size=$('html *').css("font-size")	 
		initFontSizeNum=document.initFontSizeNum=currentFontSizeNum = parseFloat(cur_size, 10);
	}
	
	$('html *').css("font-size",document.initFontSizeNum+(document.initFontSizeNum*size))

	if($('.left_column iframe').length!=0)
		{	
			$('.left_column iframe').contents().find("*").css("font-size",document.initFontSizeNum+(document.initFontSizeNum*size));
			fixIframeHeight(document.getElementsByClassName("left_column")[0].getElementsByTagName("iframe")[0]);
		}

}

document.getElementsByClassName = document.getElementsByClassName || function(className) {
	className = className.replace(/\s+/g, ' ').replace(/^\s|![A-Za-z0-9-_\s]|\s$/g, '').split(' ');

	for (var i = 0, elements = this.getElementsByTagName('*'), elementsLength = elements.length, b = [], classNameLength = className.length, passed = true; i < elementsLength; i++, passed = true) {
		for (var j = 0; j < classNameLength && passed; j++) {
			passed = (new RegExp('(^|\\\s)' + className[j] + '(\\\s|$)', 'i')).test(elements[i].className);
		}

		if (passed) {
			b.push(elements[i]);
		}
	}

	return b;
};

function changeBackground(color)
{
	if(document.getElementById("central_block")!=undefined)document.getElementById("central_block").style.backgroundColor=color;
	if(document.getElementById("content")!=undefined)document.getElementById("content").style.backgroundColor=color;
}

function changeTextColor(color)
{
    $('html *').css('color', color);
}


url_str=location.href
tmp=url_str.substring(0,url_str.lastIndexOf("/"))
folder_str=tmp.substring(tmp.lastIndexOf("/")+1,tmp.length);
var newChannel=-1;

function searchForLink(attr)
{


//page_str=url_str.substring(url_str.lastIndexOf("/")+1,url_str.length);


if(subbase!="stories")	if(subbase==folder_str )folder_str="";		

if(url_str.indexOf("cgi-bin")==-1)
	{
		if(url_str.lastIndexOf("/")==url_str.length-1)
		{
			folder_str=url_str.substring(url_str.lastIndexOf("/",url_str.lastIndexOf("/")-1)+1,url_str.lastIndexOf("/"))
			page_str="";
		}
		else
		{

			//alert(url_str);

				if(url_str.indexOf("channel=")!=-1) 
				{
					newChannel=url_str.charAt(url_str.length-1);
					//alert(newChannel);
					//url_str=url_str.substr(0,url_str.indexOf("channel")-1);
				//	alert(url_str);
				}

			page_str=url_str.substring(url_str.lastIndexOf("/")+1,(url_str.indexOf("?")==-1)?url_str.length:(url_str.indexOf("?")));
			//alert(page_str)
		}
	}
	else
	{
		if(subbase=="stories")	if(subbase==folder_str )folder_str="";		

		end_index=(url_str.indexOf("&")==-1)?(url_str.length):(url_str.indexOf("&"))
		page_str=url_str.substring(url_str.lastIndexOf("/")+1,end_index);
	}




flag2=false;
for(var i=0; i<menu_links.length; i++)
{
	
	for(var j=0; j<menu_links[i].length; j++)
	{
		if(menu_links[i][j].href==undefined || menu_links[i][j].href==null)break;

		cur_link=	"";
		cur_folder="";
		if(	menu_links[i][j].href.indexOf("/")!=-1)
		{

			if(menu_links[i][j].href.indexOf("cgi-bin")==-1)
			{

					/// SPECIAL FOR MONEY PAGE income_outcome
					if(newChannel!=-1 && (menu_links[i][j].href.indexOf("channel=")!=-1 && menu_links[i][j].href.charAt(menu_links[i][j].href.length-1)==newChannel ))
					{					
						menu_links[i][j].href=menu_links[i][j].href.substring(0,menu_links[i][j].href.indexOf("channel=")-1)						
					}
					///

					s=menu_links[i][j].href.split("/");
					cur_folder=	s[s.length-2];

					if(menu_links[i][j].href.lastIndexOf("/")==menu_links[i][j].href.length-1)
					{
						cur_link=""						
					}

					else
					{					
						cur_link=	s[s.length-1];					
					}
			}
			else
			{
				
				end_index=(menu_links[i][j].href.indexOf("&")==-1)?(menu_links[i][j].href.length):(menu_links[i][j].href.indexOf("&"))
				cur_link=menu_links[i][j].href.substring(menu_links[i][j].href.lastIndexOf("/")+1,end_index);			
			}		
		}
		else
		{			
			cur_link=	menu_links[i][j].href;
		}

		if (cur_link==page_str && folder_str==cur_folder)
		{

				if(attr==undefined)	{linkLocated(i,j);return;}
				else
				{
					var obj=new Object();
					obj.i=i;
					obj.j=j;
					return (obj)
				}
				flag2=true
				return;
			}
		}
		
	}

	if( !flag2)
	{
		linkLocated(1,-1)
	}
}




function linkLocated(channel,link)
{
	if(link==-1)return;
	
	$("#channel"+channel).addClass("over" );
	$("#channel"+channel).attr("current","true");
	folder=getLink(menu_links,channel,0,false);

	if(subbase!="kidsnews")
		{	

			page_tmp=getLink(menu_links,channel,link);
		//	if(subbase!="stories")page_tmp=menu_links[channel][link].text;
			alagova_str=(subbase!="money_ar")?"על הגובה":"عال العال"
			$("#inner_content").prepend("<div id='path_ruler'><a href='../../../'>"+alagova_str+"</a> &gt; <a href='../../../"+subbase+"/'>"+hebrew_name+"</a> &gt; "+folder+((folder!=page_tmp)?("  &gt; "+page_tmp):"")+"</div>")
		}
}

function getLink(_arr,i,j,channelTitleFlag)
{

	if(_arr[i][j].text==undefined) return "";
	txt=_arr[i][j].text;
	img=_arr[i][j].icon;
	img=(img!=undefined)?"<div class='img' style='background-image: url("+img+")' ></div>":""

	x=_arr[i][j].href;	
	target=((_arr[i][j]["target"]==undefined)?(""):("target=_blank")); //+(x)
	href=((x.indexOf("http://")==-1)?(base+""+((x.indexOf("cgi-bin")!=-1)?"":subbase+"/")):(""))+(x);
	return '<a href="'+href+'"   title=\' '+txt+' \'  alt=\' '+txt+' \' ' + target +'>'+(( !channelTitleFlag)?(img+txt):'&nbsp;')+'</a>'
}

function fillMenu()
{
	var menu_str="";

	menu_str+=('<ul>');

	for(var i=1; i<menu_links.length; i++)
	{
		 menu_str+=('<li id="channel'+i+'">'+getLink(menu_links,i,0, true));
		 if(menu_links[i].length>0) // WAS >1
		{		
		  menu_str+=('<ul>');
			for(var j=1; j<menu_links[i].length; j++)
			{
				if(menu_links[i][j].menu!="false")
				menu_str+=('<li>'+getLink(menu_links,i,j , false)+'</li>');
			}				
		  menu_str+=('</ul>');
		}
		menu_str+=('</li>');
	}
	 
	menu_str+=('</ul>');

	$('#myslidemenu').html(menu_str)
}



function fixSpecialTextualFooterOrder()
{
	tmp_title1=$("#textual .title:eq("+($("#textual .col").length-1)+")")//.html();
	tmp_text1=$("#textual .col:eq("+($("#textual .col").length-1)+") .link:eq(0)");

	tmp_title2=$("#textual .col:eq("+($("#textual .col").length-1)+") .title:eq(0)")//.html();
	tmp_text2=$("#textual .col:eq("+($("#textual .col").length-1)+") .link:eq(1)")//.html();

	
	if ($(tmp_title1).html()=="יצירת קשר" && $(tmp_title2).html()=="שתפו")
	{
		$(tmp_title1).html("שתפו");
		$(tmp_title2).html("יצירת קשר")

		tmp=tmp_text1.html();
		tmp_text1.html(tmp_text2.html());
		tmp_text2.html(tmp)
	}

}

function writeEmbed()
{
	
	if((document.embed_str!=undefined))
	{
		footer_str="";
		if(document.height_str==undefined) document.height_str=520;
		if(document.width_str==undefined) document.width_str=910;
		//<span>לשיבוץ תוכן זה באתרכם</span>
		footer_str+='<div class="link"><div id="embed"><input id="embed_code" name="embed_code" type="text" size="25"  value="&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; codebase=&quot;http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0&quot; width=&quot;'+document.width_str+'&quot; height=&quot;'+document.height_str+'&quot; id=&quot;galim_game&quot; align=&quot;middle&quot;&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;sameDomain&quot; /&gt;&lt;param name=&quot;movie&quot; value=&quot;'+document.embed_str+'&quot; /&gt;&lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;&lt;param name=&quot;bgcolor&quot; value=&quot;#ffffff&quot; /&gt;&lt;embed src=&quot;'+document.embed_str+'&quot; quality=&quot;high&quot; bgcolor=&quot;#ffffff&quot; width=&quot;'+document.width_str+'&quot; height=&quot;'+document.height_str+'&quot; name=&quot;galim_game&quot; align=&quot;middle&quot; allowScriptAccess=&quot;sameDomain&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; /&gt;&lt;/object&gt;" onClick="javascipt:document.getElementById(\'embed_code\').focus();document.getElementById(\'embed_code\').select();" /></div></div>'

		tmp=$("#textual .title:eq("+($("#textual .col").length-1)+")").html();

		$("#textual .col:eq("+($("#textual .col").length-1)+")").prepend(footer_str+'<div class="title">'+tmp+'</div>');
		$("#textual .title:eq("+($("#textual .col").length-1)+")").html("לשיבוץ תוכן זה באתרכם");
	}
//document.write(footer_str);
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}





function goAbout(type)
{
	if(window.subbase!=undefined && subbase=="national" && (!isNaN(type)))
	{
		
		url=location.href
		if(url.indexOf(subbase) != url.length-(subbase).length-1)
			{
				subtypes=["על הערוץ", "מדריך למורים", "מדריך להורים"];
				tmp=url.indexOf(subbase)+subbase.length+1;
				tmp2=url.indexOf("/",tmp)
				if(tmp2==-1 && url.indexOf("talkback.pl")!=-1)tmp2=url.length;
				subsite=url.substring(tmp,tmp2 );
				subtype=subtypes[type];
				if(subsite=="holocaust") type="יום הזיכרון לשואה ולגבורה";
				if(subsite=="independence") type="יום העצמאות";
				if(subsite=="herzl" || subsite=="talkback.pl?Id=13") type="יום הרצל";
				if(subsite=="jerusalem") type="יום ירושלים";
				type+="#"+subtype+"#";
			//	alert(type)
				//	return
			}
	}

	if(location.href.indexOf("/info/")!=-1)
	{
		location.href="about.html?"+type;
	}
	else if((window.page!=undefined && page=="homepage") )
	{
		location.href="info/about.html?"+type;
	}
	else
	{
		location.href="../../../../"+subbase+"/about.html?"+type;
	}
}


function rollout(){
    var gameFlash_obj=getFlashMovie("bottom");
    gameFlash_obj.rollout(); 
}

function contact(e)
{

    e.preventDefault();
    var id = $("#writeus");
  
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
  
    $('#mask').css({'width':maskWidth,'height':maskHeight});
  

	$('#mask').show();

	$('#mask').css("opacity",0);

//alert("!")
	$('#mask').animate({    opacity: 0.6  }, 300, function() {     });
	  
	var winH = 100;
	var winW = $(window).width();
	  
	$(id).css('top',  100);
	$(id).css('left', winW/2-$(id).width()/2);
  
  //alert
	if(navigator.appName.indexOf("Microsoft")==-1)   $(id).fadeIn(1000); 
	else $(id).show();
	  
	$(id).html("<iframe src='"+base+"contact/' frameborder=0 ></iframe>")

  
  
//    $('.window .close').click(function (e) {e.preventDefault();    $('#mask, .window').hide();    }); 
 
    $('#mask').click(function () {
    $(this).hide();
    $('.window').hide();
    }); 


}










$(document).ready(function(){
	

	initFooterStuff();
	writeBottomMenu();
//	fixSpecialTextualFooterOrder();
	writeEmbed();
	if($('.jquerycssmenu').length != 0)
	{
	
		fillMenu()
		searchForLink()
	}

	$('body').append('<div id="writeus" class="window"></div><div id="mask"></div>')

	if(document.explorerVersion>=7 &&  document.explorerVersion<8)	fixIE7();

});

function fixIE7()
{
	len=$('.word.fw').length;
	if(len!=0)
	{
		//$('.word.fw').css("width","200px")
			//alert($('.word.fw').width())
			$('.word.fw').css("padding-right","30px")
			$('.word.fw').css("padding-left","10px")
			$('.word.back').css("padding-right","10px")
			$('.word.back').css("padding-left","30px")
	}
	//$('#game').css("margin-bottom","0px");

}

