var newsletter_slider_flag = 0;

window.addEvent('domready', function(){
	
	/*
if ($('newsletter_slider') != null && $('btn_newsletter_tab') != null)
	{
		var openEffect = new Fx.Morph('newsletter_slider_inside', {duration: 'normal', transition: Fx.Transitions.Elastic.easeOut});
		var closeEffect = new Fx.Morph('newsletter_slider_inside', {duration: 'short', transition: Fx.Transitions.Elastic.linear});
		$('btn_newsletter_tab').addEvent('click', function(){
			if (newsletter_slider_flag == 1)
			{
				closeEffect.start({'height': 0});
				newsletter_slider_flag = 0;
			}
			else
			{
				openEffect.start({'height': 100});
				newsletter_slider_flag = 1;
			}
		});
	}
*/
	
	if ($('search_submit') != null)
	{
		$('search_submit').addEvent('click', function(){
			$('search_form').submit();
		});
	}
	
	if ($('newsletter_submit') != null)
	{
		$('input_text').set('value', 'כתובת אי-מייל');
		
		$('input_text').addEvent('focus', function(){
			if ($('input_text').get('value') == 'כתובת אי-מייל') $('input_text').set('value', '');
		});
		
		$('input_text').addEvent('blur', function(){
			if ($('input_text').get('value') == '') $('input_text').set('value', 'כתובת אי-מייל');
		});
				
		var myRequest = new Request.HTML({
			url: $('newsletter_form').getProperty('action'),
			method: $('newsletter_form').getProperty('method'),
			onRequest: function(){
				$('newsletter_result').innerHTML = 'שולח נתונים, אנא המתן...';
			},
			onComplete: function(){
				
				if (this.response.text == 1)
				{
					$('newsletter_result').innerHTML = 'הרשמתך נקלטה בהצלחה!<br/>להשלמת ההרשמה לניוזלטר, עליך ללחוץ על הקישור בהודעה שנשלחה לכתובת הדואר האלקטרוני שהזנת.';
					(function(){
						$('newsletter_result').innerHTML = '';
						$('newsletter_form').reset();
					}).delay(5000);
				}
				else
				{
					$('newsletter_result').innerHTML = this.response.text;
				}
			}
		});
		
		$('newsletter_submit').addEvent('click', function(){
			if ($('input_text').get('value') == 'כתובת אי-מייל') return;
			myRequest.post($('newsletter_form'));
		});
	}
	
	// build all buttons anim
	var buttons = $$('.btn_anim');
	buttons.each(function(e){
		
		var eChild = ((e.getElement('img') == null)? e.getElement('input'): e.getElement('img'));  
		
		e.addEvents({
			
			'mouseenter': function(){
				var height = eChild.getStyle('height').toInt();
				height = height - (height/2 + height);
				eChild.setStyle('margin-top', height);
			},
		
			'mouseleave': function(){
				eChild.setStyle('margin-top', '0px');
			}
			
		});
		
	});
	
	if ($('menu_bar'))
	{
	// adding menu mouseover effects
	var menuBar = $('menu_bar').getElements('img');
		
	menuBar.each(function(e){
		
		if (e.className == 'selected') return;
		
		e.addEvents({
					
			'mouseenter': function(){
				
				e.setProperty('src', e.src.replace('.png','_over.png'));
				
			},
			
			'mouseleave': function(){
				
				e.setProperty('src', e.src.replace('_over.png','.png'));
				
			}

		});
	});
	
	// catch mouse out the menu area
	$('menu_bar').addEvent('mouseleave',function(){
		
		menuBar.each(function(e){
		
			if (e.className == 'selected') return;
			
			e.setProperty('src', e.src.replace('_over.png','.png'));
			
		});
	
	});
	}
	
	//build categories animation
	var categories = $('cat_block').getElements('a');
	categories.each(function(e){
		
		e.addEvents({
			
			mouseenter: function(){
			
				var li = e.getParent();
				new Element('div', {'id': 'indicator'}).injectInside(li);
			
			},
			mouseleave: function(){
				
				if ($('indicator') != null) $('indicator').dispose();
			
			}
		})
		
	
	});
	
	
	if($$('.mb_alt').length > 0)//only triggered if 'mb' class found on page
	{
		var initMultiBox = new multiBox('mb_alt', {
			descClassName: false,//the class name of the description divs
			path: './Files/',//path to mp3 and flv players
			useOverlay: false,//use a semi-transparent background. default: false;
			maxWidth: 780,//max width (set to false to disable)
			maxHeight: 500,//max height (set to false to disable)
			addDownload: false,//do you want the files to be downloadable?
			pathToDownloadScript: '',//if above is true, specify download script
			addRollover: false,//add rollover fade to each multibox link
			addOverlayIcon: false,//adds overlay icons to images within multibox links
			addChain: false,//cycle through all images fading them out then in
			recalcTop: true	 //subtract the height of controls panel from top position
		});
	}
		
});
window.addEvent('load',function(){
		
	// fix png for IE
	pngfix('.pngfix');
	
	//new SmoothScroll();
	
});
