//E-legance.org
	function closed(){
		$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
						$('regcontent').set('text', '');
		}}).start(0);	
	}
document.addEvent('domready',function(){
	//tips
	var myTips = new Tips('a.neg');
	myTips.attach('a.pos');
	
	var votedTips = new Tips('div.voted');
	$$('div.voted').store('tip:title', 'You have voted for this review');
	// test
	
	$$('a.pos, a.neg').addEvent('click', function(){						
		myTips.hide();
		var box=$("vote_"+this.name);
		//fadeout
		box.get('tween', {property: 'opacity', onComplete : function(){ 
		}}).start(0);
		
		var req = new Request({
		url: 'vote.php?id='+this.name+'&vote='+this.rel,
		onSuccess: function(txt){
			box.set('html', txt);	
			//fade in
			box.get('tween', {property: 'opacity', onComplete : function(){ 
			}}).start(1);
		},
		
		onFailure: function(){
			box.set('text', 'The request failed.');
		}

		});												
		req.send();
	});
	//

	
	
	//register box
	if($('regcontent')){
	$('regcontent').setStyle('opacity',0);
	}
		var req = new Request.HTML({url:'regform.php', 
		onSuccess: function(html) {
			$('regcontent').set('text', '');
			$('regcontent').adopt(html);
				// Ajax for preloading
				$('regform').addEvent('submit', function(e) {							 
					e.stop();
					var log = $('reginfo').empty().addClass('ajax-loading');
					this.set('send', {onComplete: function(response) { 
						log.removeClass('ajax-loading');
						if(response=="OKAY"){
							log.set('html', '<p><strong>Successful registration!</strong></p>');
							$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
									  window.location.reload(); 
							 }}).start(0);
						}else{
							log.set('html', response);
						}
					}});
					
					this.send();
					
												
					
				});
			
		}});
		var req2 = new Request.HTML({url:'regform.php?case=1', 
		onSuccess: function(html) {
			$('regcontent').set('text', '');
			$('regcontent').adopt(html);
				// Ajax for preloading
				$('regform').addEvent('submit', function(e) {							 
					e.stop();
					var log = $('reginfo').empty().addClass('ajax-loading');
					this.set('send', {onComplete: function(response) { 
						log.removeClass('ajax-loading');
						if(response=="OKAY"){
							log.set('html', '<p><strong>Successful registration!</strong></p>');
							$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
									  window.location.reload(); 
							 }}).start(0);
						}else{
							log.set('html', response);
						}
					}});
					
					this.send();
					
												
					
				});
			
		}});
		
		
	$$('.reglink').addEvent('click',function(){
			req.send();
			var form=$('regcontent');
				if(form.getStyle('opacity')==0 || form.getStyle("top")!='303px'){
				form.setStyle("display","block");
				form.setStyle("top",303);
				$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
					$$('.close').addEvent('click',function(){
								$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
									$('regcontent').set('text', '');
								}}).start(0);	
							});
					
				}}).start(1);
			}else{
				if(form.getStyle("top")=='303px'){
					$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
						$('regcontent').set('text', '');
					}}).start(0);
				}
			}
	});

	$$('.reglink2').addEvent('click',function(event){
			req2.send();
			var form=$('regcontent');
			var top = event.page.y - 152;
			if(form.getStyle('opacity')==0 || form.getStyle("top")!=top+'px'){
				form.setStyle("display","block");
				form.setStyle("top",top);
				$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
					$$('.close').addEvent('click',function(){
								$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
								$('regcontent').set('text', '');
								}}).start(0);	
							});
					
				}}).start(1);
			}else{
				if(form.getStyle("top")== top+'px'){
					$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
					$('regcontent').set('text', '');
					}}).start(0);
				}
			}
	});
	
	
	var passreq = new Request.HTML({url:'lostpass.php', 
		onSuccess: function(html) {
			$('regcontent').set('text', '');
			$('regcontent').adopt(html);
				// Ajax for preloading
				$('regform').addEvent('submit', function(e) {							 
					e.stop();
					var log = $('reginfo').empty().addClass('ajax-loading');
					this.set('send', {onComplete: function(response) { 
						log.removeClass('ajax-loading');
						if(response=="OKAY"){
							log.set('html', '<p><strong>Your new password was sent to your email!</strong></p>');
							/*$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
									  window.location.reload(); 
							 }}).start(0);*/
						}else{
							log.set('html', response);
						}
					}});
					
					this.send();
				});
			
		}});


	$$('.lostpass').addEvent('click',function(){
			passreq.send();
			var form=$('regcontent');
			if(form.getStyle('opacity')==0 || form.getStyle("top")!='288px'){
				form.setStyle("top",288);
				form.setStyle("display","block");
				$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
					$$('.close').addEvent('click',function(){
								$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
									$('regcontent').set('text', '');
								}}).start(0);	
							});
				}}).start(1);
			}else{
				if(form.getStyle("top")=='288px'){
					$('regcontent').get('tween', {property: 'opacity', onComplete : function(){
						$('regcontent').set('text', '');
					}}).start(0);
				}
			}
	});
		
		
	
	
	//Auto completer
	
	new Autocompleter.Ajax.Json('search', 'autocomplete.php', {
		//name the element containing the search term something suitable
		//otherwise defaults to 'value'
		'postVar': 'q'
	});
	
	//


	$('search').addEvent('focus',function(){
		if(this.value=='Find Forex Broker'){
			this.value='';
		}
	});
	
		$('search').addEvent('blur',function(){
		if(this.value==''){
			this.value='Find Forex Broker';
		}
	});

});
