$(document).ready(function(){
	$('#reg-domain .form-submit').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover active');
		
	}).mousedown(function(){
		$(this).addClass('active');
	}).mouseup(function(){
		$(this).removeClass('active');
	});
	

	$('.form input[type="text"]').blur(function() {
		if(this.value=='') this.value = this.defaultValue;
		$(this).removeClass('focus');
  	}).focus(function() {
		if(this.value == this.defaultValue) this.value = '';
		$(this).addClass('focus');
  	});
	
	$('.pop-wrap .close').click(function(){
		$(this).closest('.pop-wrap').hide();
	});
	
	//
	
	 
	$('a[rel="popup"]').click(function(e){
		stopEvent(e);
		$('.pop-wrap').hide();
		
		$(document).bind('click', function(event){
			var $target = $(event.target);
			if ($target.parents('.pop-wrap').html() == null) {
			  $('.pop-wrap').hide();
			}
		});
		
		var pid = $(this).attr('href');
		$(pid).show();
		
		return false;
	});
	
	$('#login .fake-pass').blur(function() {
		
  	}).focus(function() {
		$(this).hide();
		$('#login input.password').show().focus();
  	});
	
	$('#reg-domain li a').live('click', function(){
		var index = $('#reg-domain li').index($(this).parent());
		
		$('#reg-domain li, #reg-domain .form').removeClass('active');
		$('#reg-domain .form:eq('+index+'), #reg-domain li:eq('+index+')').addClass('active');
		
		$('#reg-domain li:not(.active)').each(function(){
			$(this).html('<a href="#">'+ $('span', this).html() +'</a>');
		});
		$('#reg-domain li.active').html('<span>'+ $('#reg-domain li.active a').html() +'</span>');
		
		
		return false;
	});
	
	$('#news a[rel="popup"]').mouseover(function(){
		$('#news .pop-wrap').hide();
		var pid = $(this).attr('href');
		$(pid).show();
	}).mouseout(function(){
		var pid = $(this).attr('href');
		$(pid).hide();
	});
	
	$('#news .pop-wrap').mouseover(function(){
		$(this).show();
		$(this).prev('a').addClass('hover');
	}).mouseout(function(){
		$(this).hide();
		$(this).prev('a').removeClass('hover');
	});
	
	$('#free-domains table tr').mouseover(function(){
		$(this).addClass('hover');
	}).mouseout(function(){
		$(this).removeClass('hover');
	});
	
});

function str_replace(search, replace, subject, count) {
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function stopEvent(e){if(e.preventDefault){e.preventDefault();e.stopPropagation();}else{e.returnValue=false;e.cancelBubble=true;}return false;}

