function trim(string)
{
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

$(function(){
	//events leftbox
	nb = 0;
	$('div.special-bonus span').each(function(){
		nb++;
		shownb(nb);
	});

	if(jQuery('#clientsbot').jcarousel !== undefined) {
	    jQuery('#clientsbot').jcarousel({
	        scroll: 5
	    });
	}
	var currClientsHeight = $('ul#clientsbot').height();
	$('ul#clientsbot li').each(function(){
		var myClientsHeight = $(this).height();
		myClientsHeight = (currClientsHeight-myClientsHeight)/2;
		$(this).css('margin-top',myClientsHeight+'px');
	});

});

/* events leftbox */

function shownb(num) {
	num--;
	$('div.special-bonus span:eq('+num+')').fadeIn().css('display','block');
}

/* end events main */

(function($) {
	$.fn.equalHeight = function() {
		var group = this;
		$(window).bind('resize', function() {
			var tallest = 0;
			$(group).height('auto').each(function() {
				tallest = Math.max(tallest, $(this).height());
			}).height(tallest);
		}).triggerHandler('resize');
	}
})(jQuery)

/* popup window */

function getPopupWindow(title,data,width){
	if (title!=undefined && data!=undefined) {
		var content = '';
		content += '<div class="popup-window">';
			content += '<table cellspacing="0" cellpadding="0" border="0">';
				content += '<tbody>';
					content += '<tr>';
						content += '<td class="tl"><img src="/img/transp.gif" alt="" title="" width="39" height="39" /></td>';
						content += '<td class="t"><img src="/img/transp.gif" alt="" title="" width="1" height="39" /></td>';
						content += '<td class="tr"><img src="/img/transp.gif" alt="" title="" width="39" height="39" /></td>';
					content += '</tr>';
					content += '<tr>';
						content += '<td class="l"><img src="/img/transp.gif" alt="" title="" width="39" height="1" /></td>';
						content += '<td class="c" valign="top"><a href="javascript:" onclick="getPopupWindow()"><img src="/img/popup-close.gif" alt="Закрыть" title="Закрыть" class="popup-close" /></a><h1>'+title+'</h1><br /><br />'+data+'</td>';
						content += '<td class="r"><img src="/img/transp.gif" alt="" title="" width="39" height="1" /></td>';
					content += '</tr>';
					content += '<tr>';
						content += '<td class="bl"><img src="/img/transp.gif" alt="" title="" width="39" height="39" /></td>';
						content += '<td class="b"><img src="/img/transp.gif" alt="" title="" width="1" height="39" /></td>';
						content += '<td class="br"><img src="/img/transp.gif" alt="" title="" width="39" height="39" /></td>';
					content += '</tr>';
				content += '</tbody>';
			content += '</table>';
		content += '</div>';
		$('body').prepend(content);
		var top = ($('div.popup-window table').height())/2;
		var left = ($('div.popup-window table').width())/2;
		$('div.popup-window table').attr('style','margin-top:-'+top+'px;margin-left:-'+left+'px');
		if	(width!=undefined) {
			left = width/2;
			$('div.popup-window table').attr('style','width:'+width+'px;margin-left:-'+left+'px;margin-top:-'+top+'px');
		}
	} else {
		$('div.popup-window').remove();
	}
}

/* end popup window */

$(document).ready(function(){

/* imposition fixes */

	$('div.action>p').css('margin-top', function(){
		$(this).css('margin-top','-'+$(this).height()/2+'px');
	});
	//$("div.autoheight").equalHeight();
	$("div.tariffs").equalHeight();
	$("div.services").equalHeight();
	$("div.nextstep").equalHeight();

/* end imposition fixes */

/* input mod */

	$('[name=domainname],[name=q],[name=register_new_domain]').focus(function(){
		if($(this).val()=='Введите имя домена'||$(this).val()=='Введите поисковый запрос'||$(this).val()=='Зарегистрировать новый домен') {
			$(this).val('').css({'color':'#000'});
		} 
	}).blur(function(){
		if($(this).val()=='') {
			if($(this).attr('name')=='login') {
				$(this).val('логин');
			} else if($(this).attr('name')=='domainname') {
				$(this).val('Введите имя домена');
			} else if($(this).attr('name')=='q') {
				$(this).val('Введите поисковый запрос');
			} else if($(this).attr('name')=='register_new_domain') {
				$(this).val('Введите имя домена');
			}
			$(this).css({'color':'#bebebe'});
		}
	});

/* end input mod */

});

function getPopup(name,height,path,width) {
	if(name=='') {
		$('div.popup').fadeOut('slow', function(){
			$(this).html('');
		});
	} else {
		var thisImg = "<a href=\"javascript:\" onclick=\"getPopup('')\"><img src=\"";
		if(path==null) {
			thisImg += "/img/"+name+"_big";
		} else {
			thisImg += path+name;
		}
		thisImg += ".jpg\" border=\"0\" alt=\"Закрыть\" title=\"Закрыть\" /></a>";
		$('div.popup').html(thisImg);
		var thisheight = parseInt(height)/2;
		if(width==null) {
			$('div.popup').css('margin-top','-'+thisheight+'px')
		} else {
			var thiswidth = parseInt(width)/2;
			$('div.popup').css({'margin-top':'-'+thisheight+'px','margin-left':'-'+thiswidth+'px'});
		}
		$('div.popup').fadeIn('slow');
	}
}
