﻿// placeholder
$(document).ready(function(){
function elementSupportsAttribute(element,attribute) {
	var test = document.createElement(element);
	if (attribute in test) {
		return true;
	} else {
		return false;
	}
}
if (!elementSupportsAttribute('input','placeholder')) {

	$('input[placeholder]').each(function(){
	
		var elm = $(this)
	
		if (elm.attr('placeholder') != '') {
			
			elm.data('placeholder',elm.attr('placeholder')).addClass('placeholder').val(elm.attr('placeholder'))
	
			var password = $(this).attr('type') == 'password';
			if (password) {
				var Cstyle = elm.attr('style');
				var Cclass = elm.attr('class');
				$('<input type="text" class="'+Cclass+' placeholderTemp" style="'+Cstyle+'" value="'+elm.data('placeholder')+'" />').insertAfter(elm).data('parent',elm)
				.width(elm.width()).height(elm.height());
				elm.val('').hide();
			}
			
		}
		
	})
	
	$('input.placeholder').live('focusin', function(){
	
		$(this).removeClass('placeholder').val('')
		
		if ($(this).hasClass('placeholderTemp')) {
			var parent = $(this).data('parent')
			parent.show().focus()
			$(this).remove()
			
		}
	
	});
	
	$('input.placeholder').bind('focusout', function(){
	
		if ($(this).val() == '' && $(this).data('placeholder') != '') {
			$(this).addClass('placeholder').val($(this).data('placeholder'))
			
			var elm = $(this)
			var password = $(this).attr('type') == 'password';
			if (password) {
				var Cstyle = elm.attr('style');
				var Cclass = elm.attr('class');
				$('<input type="text" class="'+Cclass+' placeholderTemp" style="'+Cstyle+'" value="'+elm.data('placeholder')+'" />').insertAfter(elm).data('parent',elm)
				.width(elm.width()).height(elm.height());
				elm.val('').hide();
			}
			
		} else {
			$(this).removeClass('placeholder')
		}
	
	})
	
}
})

//domains expand
$(document).ready(function(){
	$('.domain-zone a.expand').toggle(function(){
		$(this).text('Cвернуть')
		var displayType = $(this).parents('.domain-zone').find('li').first().css('display')
		var heightOld = $(this).parents('.domain-zone').height()
		$(this).parents('.domain-zone').find('.hidden').css({'display':displayType,opacity:0})
		.animate({
			opacity:1
		})
		var heightNew = $(this).parents('.domain-zone').height()
		$(this).parents('.domain-zone').height(heightOld)
		.animate({
			'height':heightNew
		},function(){
			$(this).css({height:'auto'})
		})
	},function(){
		$(this).text('Развернуть все зоны')
		var displayType = $(this).parents('.domain-zone').find('li').first().css('display')
		var heightOld = $(this).parents('.domain-zone').height()
		$(this).parents('.domain-zone').find('.hidden').css({'display':'none'})
		var heightNew = $(this).parents('.domain-zone').height()
		$(this).parents('.domain-zone').height(heightOld)
		.animate({
			height:heightNew
		},function(){
			$(this).find('.hidden').css({'display':'none'})
			$(this).css({height:'auto'})
		})
		$(this).parents('.domain-zone').find('.hidden').css({'display':displayType,opacity:1})
		.animate({
			opacity:0
		})
	
	})
})

$(document).ready(function(){
	$('ul.menu li:even').addClass('even');
	$('table.domains tr:even').addClass('even');
	$('table.services tr:even').addClass('even');	
})

