var manager = {
	
	start:function(){	
			
		if($('s')) manager.modules.search();
		if($('comment')) manager.modules.comment();
		if($('push')) manager.modules.push();
		if($('push-home')){
			manager.modules.login();
			manager.modules.practice.init();
		}
		if($('push-contact')) manager.modules.contact.init();
	
	},
	
	modules:{
	
		search:function(){
			$('s').text =  $('s').value;
			$('s').onfocus = function(){if(this.value == this.text) this.value = '';}
			$('s').onblur = function(){if(this.value == '') this.value = this.text;}
		},
	
		comment:function(){
			$('comment').text =  $('comment').value;
			$('comment').onfocus = function(){if(this.value == this.text) this.value = '';}
			$('comment').onblur = function(){if(this.value == '') this.value = this.text;}
			$('commentform').onsubmit = function(){$('checkcomment').value = 'http://';}
		},
	
		login:function(){
			
			var a = document.createElement('a');
			a.setAttribute('href','http://www.seoplayer.com/wp-login.php');
			a.setAttribute('id','login');
			var txt = document.createTextNode('login');
			a.appendChild(txt);
			//a.onclick = function(){window.location.replace('http://www.seoplayer.com/wp-login.php');}
			$('push-home').appendChild(a);
			
		},
	
		contact:{
		
			init:function(){
				var alias = 'hello';
				var domain = '@seoplayer.com';
				$$('#push-contact .mail')[0].innerHTML += alias+domain;
				$$('#push-contact .mail')[0].onclick = function(){window.location.replace('mailto:'+alias+domain);}
			
				$('message').text =  $('message').value;
				$('message').onfocus = function(){if(this.value == this.text) this.value = '';}
				$('message').onblur = function(){if(this.value == '') this.value = this.text;}
				
				$('contact-seb').onsubmit = function(){manager.modules.contact.submit();return false;}
				$('submit-msg').onclick = function(){manager.modules.contact.submit();return false;}
				
			},
			
			submit:function(){
				var submit;		
				if($('name').value == '' || $('email').value == '' || $('message').value == '' || $('message').value == 'Votre message...') submit = false;
				else submit = true;

				if($('name').value == '') $('name').style.border = '1px solid darkred';
				else $('name').style.border = '1px solid #DFDFDF';

				if($('email').value == '') $('email').style.border = '1px solid darkred';
				else $('email').style.border = '1px solid #DFDFDF';

				if($('message').value == '') $$('#contact-seb .textarea')[0].style.border = '1px solid darkred';
				else $$('#contact-seb .textarea')[0].style.border = '1px solid #DFDFDF';

				if($('message').value == 'Votre message...') $$('#contact-seb .textarea')[0].style.border = '1px solid darkred';
				else $$('#contact-seb .textarea')[0].style.border = '1px solid #DFDFDF';
				
				if(submit){
					var queryParam = $('contact-seb').toQueryString();
					queryParam += '&killcache=' + new Date().getTime();
					$('contact-seb').innerHTML = '';
					$('contact-seb').style.background = 'url(http://www.seoplayer.com/wp-content/themes/seoplayer_6/img/loader.gif) no-repeat center center';
					$('contact-seb').style.height = '165px';
					var htmlURL = 'http://www.seoplayer.com/wp-content/themes/seoplayer_6/pages/seb_contact.php?killcache=' + new Date().getTime();

					var myRequest = new Request({url:htmlURL,onSuccess:function(){
						$('contact-seb').style.background = '#FFFFFF';
						$('contact-seb').style.textAlign = 'center';
						$('contact-seb').innerHTML = this.response.text;
					}});
					
					myRequest.send({method:'post',data:queryParam});					
				}
			}
		
		},
	
		practice:{
		
			init:function(){
			
				var open = document.createElement('a');
				open.setAttribute('href','javascript:void(0);');
				open.setAttribute('id','practice');
				
				var txt = document.createTextNode('practice');
				open.appendChild(txt);
				open.onclick = function(){manager.modules.practice.open();}
				$('push-home').appendChild(open);
				
			},
			
			close:function(){
			
				$('the-practices').fx.start('opacity', '0');
				$('popin').fx.start('opacity', '0').chain(
					function(){$('the-practices').destroy();$('popin').destroy();}
				);
			
			},
			
			open:function(){
				
				var bodyCoord = $('home').getCoordinates();
				var sTop = (((bodyCoord.height/2)*-1)-247);
				
				var popin = document.createElement('div');
				popin.setAttribute('id','popin');
			
				var div = document.createElement('div');
				div.setAttribute('id','the-practices');
				div.setAttribute('style','margin-top:'+sTop+'px;');
				
				var img = document.createElement('img');
				img.setAttribute('src','http://www.seoplayer.com/wp-content/themes/seoplayer_6/img/tutorial.png');
				img.className='practice';
				
				var close = document.createElement('a');
				close.setAttribute('href','javascript:void(0);');
				close.className = 'close';
				close.onclick = function(){manager.modules.practice.close();}
				
				var closeTxt = document.createTextNode('Close');
				
				div.appendChild(img);
				div.appendChild(close);
				close.appendChild(closeTxt);
				$('home').appendChild(popin);
				$('home').appendChild(div);
				
				
				div.fx = new Fx.Tween(div,{transition: Fx.Transitions.Pow.easeInOut,duration:700});
				popin.fx = new Fx.Tween(popin,{transition: Fx.Transitions.Pow.easeInOut,duration:800});
				
				div.fx.start('margin-top', '-123');
				popin.fx.start('opacity', ['0','0.7']);
			}
		},
		
		push:function(){		
			$$('#push ul')[0].style.marginLeft = '0px';
			$$('#push ul')[0].fx = new Fx.Tween($$('#push ul')[0]);
			$$('#push .prev')[0].onclick = function(){
				var push = $$('#push ul')[0];
				var pushLeft = push.getStyle('margin-left').toInt();
				if(pushLeft == 0) return;
				var to = (pushLeft+230)+'px';
				push.fx.start('margin-left', to)
			}
			$$('#push .next')[0].onclick = function(){
				var push = $$('#push ul')[0];
				var pushLeft = push.getStyle('margin-left').toInt();
				if(pushLeft == '-1380') return;
				var to = (pushLeft-230)+'px';
				push.fx.start('margin-left', to)
				return false;
			}
		}
	
	}
};

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