var Site = {
	start: function(){
		if($('error')) Site.error();		
		if($('slider')) Site.slider();
		Site.confirm_actions();	
		Site.popups();
		if($('form-manage')) Site.calendar();
		if ($('forms')) Site.hover_buttons();
		if($('home_jobs')) Site.hoverJobs();
		if($('real_text')) Site.setFocus();
		if($('file_upload')) Site.changeInput();
		Site.titles();		
		Site.meniu();
		
		if($('crew_account_menu'))
			Site.crew_menu();
		if($('company_account_menu'))
			Site.company_menu();		
	},
	
	crew_menu: function(){
		var menu_hash = new Hash();
		$('crew_account_menu').getElements('a').each(function(link){
			menu_hash.include('link'+link.get('text').replace(' ',''),link.get('href'));
		})
		
		var obj = new Swiff(root_url+'/templates/images/crew-menu.swf', {
			id: 'crew-menu',
			width: 755,
			height: 23,
			container:$('crew_account_menu'),
			params: {
				wmode: 'transparent'
			},
			vars: menu_hash
		});	
	},	
	
	company_menu: function(){
		var menu_hash = new Hash();
		$('company_account_menu').getElements('a').each(function(link){
			menu_hash.include('link'+link.get('text').replace(' ',''),link.get('href'));
		})
		
		var obj = new Swiff(root_url+'/templates/images/company-menu.swf', {
			id: 'crew-menu',
			width: 567,
			height: 23,
			container:$('company_account_menu'),
			params: {
				wmode: 'transparent'
			},
			vars: menu_hash
		});			
	},
	
	meniu: function(){
		var menu_hash = new Hash();
		$('main-menu').getElements('a').each(function(link){
			menu_hash.include('link'+link.get('text'),link.get('href'));
		})
		
		var obj = new Swiff(root_url+'/templates/images/main_menu.swf', {
			id: 'top-menu',
			width: 452,
			height: 29,
			container:$('main-menu'),
			params: {
				wmode: 'transparent'
			},
			vars: menu_hash
		});		
	},
	
	titles: function(){
		var titles = $(document.body).getElements('h1');
		
		var valid_titles = titles.filter(function(elem){
			return elem.get('rel')!=='skip';
		});
		
		valid_titles.each(function(title){
			var text = title.get('text');			
			var obj = new Swiff(root_url+'/templates/images/page_titles.swf', {
				id: 'myBeautifulMovie',
				width: 300,
				height: 27,
				container:title,
				params: {
					wmode: 'transparent'
				},
				vars: {
					textColor: '0x11A2DB',
					hText: text,
					lineWidth:200,
					lineAlpha:1,
					textSize:24,
					orizTxtPadding:0,
					vertTxtPadding: '-8'
				}
			});
		})
	},
	
	changeInput: function(){
		var input = $('file_upload').getElement('input[type=file]');	
		var upload_btn = $('file_upload').getElement('input[type=submit]').remove();
		var container = new Element('span',{
			'class':'input_file_wrapper'
		});
		var fake_text = new Element('input',{
			'type':'text',
			'class':'fake-text',
			'value':'Choose file from your hard drive (press BROWSE)'
		});
		input.set({
			styles:{
				'opacity':0.0001,
				'width':376,
				'height':30,
				'margin':0,
				'padding':0,
				'font-size':24,
				'border':'none',
				'z-index':10000
			}		  
		})
		container.injectBefore(input).adopt([input,fake_text]);
		input.addEvents({
			'change':function(){
				fake_text.set({
					'value':input.get('value')
				});
				$('explain').set({
					'text':'... file is uploading. Please be pacient.'
				});
				$('file_upload').submit();
			}			
		})		
	},
	
	setFocus: function(){
		$('fake_text').addEvents({
			'click':function(){
				$('real_text').focus();
			}
		})
	},
	
	hoverJobs: function(){
		$('home_jobs').getElements('tr.entry, tr.entry1').each(function(elem){			
			var cls = elem.get('class');			
			elem.addEvents({
				mouseover:function(){
					elem.set({
						'class':'hover'
					})
				},
				mouseout:function(){
					elem.set({
						'class':cls
					})
				}
			})			
		})
	},
	
	hover_buttons: function(){
		$('forms').getElements('input[type=submit]').each(function(elem){
			elem.addEvents({
				'mouseover': function(){ elem.setStyle('background-position','bottom') },
				'mouseout': function(){ elem.setStyle('background-position','top') }
			})
		})
	},
	
	error: function(){
		var myEffect = new Fx.Morph('error', {duration: 1500, transition: Fx.Transitions.Bounce.easeOut}); 
		var size = $('error').getSize();
		$('error').setStyles({ 'overflow':'hidden', 'height':'0px' });
		myEffect.start({
			'background-color': ['#FFFFFF','#FF0000'],
			'color': ['#000000','#FFFFFF'],
			'opacity':[0,1],
			'height':[0,(size.y-20)]
		});
	},
	
	slider: function(){
		var toggler_container = new Element('div', { 'class': 'toggler-container'}).injectAfter('slider');		
		var mySlide = new Fx.Slide('slider');		
		var toggler = new Element('a',{
			'html':'Click to hide',
			'href':'#',
			'events':{
				'click': function(e){
					new Event(e).stop();
					mySlide.toggle().chain( function(){
						toggler.setHTML( mySlide.open ? 'Click to hide' : 'Your info is hidden. Click to show' );
					});					
				}
			}
		}).injectInside(toggler_container);	
	},
	
	confirm_actions:function(){
		$(document.body).getElements('.confirm_action').addEvents({
			'click': function(e){
				if(!confirm('Are you sure you want to delete this?'))
					new Event(e).stop();
			}
		});
	},
	
	popups: function(){
		$$('.popup').each(function(elem){
			elem.addEvents({
				'click':function(el){
					new Event(el).stop();
					var t = window.open( elem.get('href') , "newWin" , "height=500,width=900,scrollbars=1" );
					t.moveTo((self.screen.width-900)/2,(self.screen.height-500)/2);
					t.focus();					
				}
			})
		});
	},
	
	calendar: function(){
		$('form-manage').getElements('.DatePicker').each(function(elem){
			new DatePicker(elem);
		})
	}
}

window.addEvent('domready', Site.start);
