function plansClear(td){
	$(td).parents(".t-plans").not(".t-plans_speed,.t-plans_hdd,.t-plans_ram,.t-plans_cpu")
		.find(".td-selcol").removeClass("td-selcol")
		.end()
		.find("TD.td-plan").removeClass().addClass("td-plan td-plan_dis")
	}
function plansHover(td,col){
	$(td).parents(".t-plans").not(".t-plans_speed,.t-plans_hdd,.t-plans_ram,.t-plans_cpu").find("TR").each(function(){
		var wcolspan = false
		var acolspan = []
		$(this).find("TD").each(function(){
			if ($(this).attr("colspan") != 1) {
				acolspan.push($(this).attr("colspan"))
				wcolspan = true
				}
			})
		if (wcolspan) {
			var a = $(this).find("TD").length
			var	b = 0
			var i = 0
			while ((b < col) && (i < acolspan.length)) {
				b += acolspan[i]
				i++
				}
			$(this).find("TD:eq("+(i-1)+")").addClass("td-selcol")
			}
		else {
			$(this).find("TD:eq("+(col-1)+")").addClass("td-selcol")
			$(this).find("TD.td-plan:eq("+(col-1)+")").removeClass("td-plan_dis")
			}
		})
	}

$(document).ready(function(){

	// easings
	jQuery.extend( jQuery.easing,
	{
		easeOutExpo: function (x, t, b, c, d) {
			return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
		}
	});


	// text inputs hints
	$(".text_hint[value!=]")
		.each(function(){this.hint=this.value})
		.bind("focus",function(){if(this.hint==this.value){$(this).attr("value","").removeClass("text_hint")}})
		.bind("blur",function(){if(this.value==""){	$(this).attr("value",this.hint).addClass("text_hint")}})


	// plans
	$(".t-plans TD").hover(function(){
		var wcolspan = false
		var acolspan = []
		$(this).parents("TR:eq(0)").find("TD").each(function(){
			if ($(this).attr("colspan") != 1) {
				acolspan.push($(this).attr("colspan"))
				wcolspan = true
				}
			})
		if (wcolspan) {
			var a = $(this).prevAll().length
			var	b = 0
			for (var i=0; i<a-1; i++) {
				b += acolspan[i]
				}
			plansClear(this)
			for (var i=b; i<b+acolspan[a-1]; i++) {
				plansHover(this,i+1,true)
				}
			}
		else {
			var a = $(this).prevAll().length
			if (a > 0) {
				plansClear(this)
				plansHover(this,a)
				}
			}
		},function(){})
			
	$(".t-plans TD").hover(function(){
		var wcolspan = false
		var acolspan = []
		$(this).parents("TR:eq(0)").find("TD").each(function(){
			if ($(this).attr("colspan") != 1) {
				acolspan.push($(this).attr("colspan"))
				wcolspan = true
				}
			})
		if (wcolspan) {
			$(this).parents(".t-plans").find("TR.tr-order TD").removeClass("td-selcol")
			}
		else {
			var a = $(this).prevAll().length
			if (a > 0) {
				$(this).parents(".t-plans").find("TR.tr-order")
					.find("TD:eq("+(a-1)+")").addClass("td-selcol")
						.siblings("TD").removeClass("td-selcol")
						.end()
					.end()
				}
			}
		})

	$(".t-plans .tr-hdd TH A").click(function(){
		$(this)
			.parents(".t-plans")
				.find(".td-selcol").removeClass("td-selcol")
				.end()
			.removeClass().addClass("t-plans t-plans_hdd")
				.find(".td-plan").removeClass().addClass("td-plan td-plan_hdd")
				.end()
			.end()
			.parents("TR:eq(0)").find("TD").addClass("td-selcol")
		$(this)	.blur()
		return false
		})
	$(".t-plans .tr-speed TH A").click(function(){
		$(this)
			.parents(".t-plans")
				.find(".td-selcol").removeClass("td-selcol")
				.end()
			.removeClass().addClass("t-plans t-plans_speed")
				.find(".td-plan").removeClass().addClass("td-plan td-plan_speed")
				.end()
			.end()
			.parents("TR:eq(0)").find("TD").addClass("td-selcol")
		$(this)	.blur()
		return false
		})
	$(".t-plans .tr-ram TH A").click(function(){
		$(this)
			.parents(".t-plans")
				.find(".td-selcol").removeClass("td-selcol")
				.end()
			.removeClass().addClass("t-plans t-plans_ram")
				.find(".td-plan").removeClass().addClass("td-plan td-plan_dis")
				.end()
			.end()
			.parents("TR:eq(0)").find("TD").addClass("td-selcol")
		$(this)	.blur()
		return false
		})
	$(".t-plans .tr-cpu TH A").click(function(){
		$(this)
			.parents(".t-plans")
				.find(".td-selcol").removeClass("td-selcol")
				.end()
			.removeClass().addClass("t-plans t-plans_cpu")
				.find(".td-plan").removeClass().addClass("td-plan td-plan_dis")
				.end()
			.end()
			.parents("TR:eq(0)").find("TD").addClass("td-selcol")
		$(this)	.blur()
		return false
		})
	$(".t-plans .td-plan A").click(function(){
		$(this)
			.parents(".t-plans")
				.find(".td-selcol").removeClass("td-selcol")
				.end()
			.removeClass().addClass("t-plans")
				.find(".td-plan").removeClass().addClass("td-plan td-plan_dis")
				.end()

		var a = $(this).parents("TD:eq(0)").prevAll().length
		if (a > 0) {
			plansHover(this,a)
			}		
		$(this)	.blur()
		return false
		})


	// special
	$(".b-special LI A SPAN").hide()
	$(".b-special LI A").hover(
		function(){
			$(this).stop().animate({top:'-10px'}, 200, "easeOutExpo")
			$(this).find("SPAN").fadeIn()
			$(this).parent().find(".sh").stop().animate({opacity:.4}, 200, "easeOutExpo")
			},
		function(){
			$(this).stop().animate({top:'0'}, 200, "easeOutExpo")
			$(this).find("SPAN").fadeOut()
			$(this).parent().find(".sh").stop().animate({opacity:1}, 200, "easeOutExpo")
			})
			
	// features
	$(".b-features__nav A").click(function(){
		$(this).blur().parent().addClass("cur").siblings().removeClass("cur")
		$("#"+this.href.split("#")[1]).show().siblings(".b-features__body").hide()
		return false
		})
    
    // tooltips
    $("#semimanaged-target-1").ezpz_tooltip();
    $("#managed-target-1").ezpz_tooltip();

});