﻿var Site = {

	Start: function(){
		
		if($('top')) Site.All.ScrollToTop();
		if($('s')) Site.Www.SearchForm();
		if($('page') && $('contact-seb')) Site.Www.SebContact();
		if($('article')) Site.Www.CommentForm();
				
	},
	  
	All:{
	  
		ScrollToTop:function(){
		  
			$('top').scroll = new Fx.Scroll(window,{duration:750});
    
			$('top').addEvent('click', function(event) {
				event = new Event(event).stop();
				this.scroll.toTop();
				return false;
			});
			  
		}
		  
	},
		 
	Www:{
	
		SearchForm: 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;}
		
		},
			
		CommentForm: 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;}
		
		},
			
		SebContact: function(){
      
			var check = false;
			$('submit').onclick = function(){
			
			if($('name').value == ''){
				$('name').style.border = '1px solid darkred';
				check = true;
			}else{
				$('name').style.border = '1px solid #999';
			}
			
			if($('email').value == ''){
				$('email').style.border = '1px solid darkred';
				check = true;
			}else{
				$('email').style.border = '1px solid #999';
			}
			
			if($('message').value == ''){
				$('message').style.border = '1px solid darkred';
				check = true;
			}else{
				$('message').style.border = '1px solid #999';
			}
			
			if(check) return false;
			  
			var queryParam = $('contact-seb').toQueryString();
			
			$('to-contact').innerHTML = '';
			$('to-contact').style.background = 'url(http://www.seoplayer.com/wp-content/themes/seoplayer/img/loader.gif) no-repeat center center';
			
			var htmlURL = 'http://www.seoplayer.com/wp-content/themes/seoplayer/pages/seb_contact.php?killcache=' + new Date().getTime();
			var postContact = new XHR({method:'post', 
									   async:true,
									   onSuccess:function(){
										$('to-contact').style.background = '#FFFFFF';
										$('to-contact').innerHTML = this.response.text;
									   }});
			
			postContact.send(htmlURL,queryParam);
			
			return false;
			
			}
      
		}
		
	}
	
};

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