var strKeywordSearch='country_search';

var intFadeOutProcess=0;
var intFadeOutColor=143;

var intFadeInProcess=0;
var intFadeInColor=255;

var FormHelper=Class.create({

	initialize:function(){
	
		this.strDefaultKeywordSearchText='e.g. United Kingdom';
	},
	toggleText:function(){
	
		if(($(strKeywordSearch).value==this.strDefaultKeywordSearchText)){
			
			intFadeOutProcess=setInterval("fadeOut()",60);
		}
		else{
		
			if(($(strKeywordSearch).value=='')){
				
				$(strKeywordSearch).style.color="rgb(255,255,255)";
				
				intFadeInProcess=setInterval("fadeIn()",60);
				
				$(strKeywordSearch).value=this.strDefaultKeywordSearchText;
			}
		}
	}
});

function fadeOut(){
	
	clearInterval(intFadeInProcess);
	
	if(intFadeOutColor<255) { //If color is not white yet
		
		intFadeOutColor+=51; // decrease color darkness
		
		$(strKeywordSearch).style.color="rgb("+intFadeOutColor+","+intFadeOutColor+","+intFadeOutColor+")";
	}
	else {
	
		intFadeOutColor=143; //reset hex value
		
		clearInterval(intFadeOutProcess);
		
		clearInterval(intFadeInProcess);
		
		$(strKeywordSearch).value='';
		
		$(strKeywordSearch).style.color="rgb(0,0,0)";
	}
}

function fadeIn(){
	
	clearInterval(intFadeOutProcess);
	
	if(intFadeInColor>143) { //If color is not black yet
		
		intFadeInColor-=51; // increase color darkness
		
		$(strKeywordSearch).style.color="rgb("+intFadeInColor+","+intFadeInColor+","+intFadeInColor+")";
	}
	else {
	
		intFadeInColor=255; //reset hex value
		
		clearInterval(intFadeInProcess);
		
		clearInterval(intFadeOutProcess);
	}
}

document.observe("dom:loaded", function() {

	if(undefined!=$(strKeywordSearch)){
	
		var objFormHelper=new FormHelper();
		
		$(strKeywordSearch).value=objFormHelper.strDefaultKeywordSearchText;
		
		$(strKeywordSearch).observe('focus',function(){objFormHelper.toggleText()});
		$(strKeywordSearch).observe('blur',function(){objFormHelper.toggleText()});
	}
});
