$(document).ready(function() {

    $(".menu div").mouseover(function () {
       $(this).addClass("on");
    });
    $(".menu div").mouseout(function () {
       $(this).removeClass("on");
    });

//$('#slider1').anythingSlider(1);
    $('#slider1').anythingSlider({
            width           : 937,   // Override the default CSS width
            height          : 240,
	    hashTags        : false,
            buildNavigation : true,
            buildArrows     : false,
            autoPlay        : false,
            delay           : 2000,
            startText       : '',
            stopText       : '',
            animationTime   : 500,
            onSlideComplete : function(slider){
                    // alert('Welcome to Slide #' + slider.currentPage);
            }
    });

    $(".sl_cnt").each(function() {
        var cur_id = $(this).attr("id");
        var prev_html = $("#prev_"+cur_id).html();
        if (cur_id == 0)
        {
                $(this).addClass("act");
                $(this).css("backgroundImage", "url(images/act_arrow.jpg)");
                $(this).css("backgroundRepeat", "no-repeat");
                $(this).append(prev_html);
        }
        if (cur_id == 1)
        {
                $(this).append(prev_html);
        }
        if (cur_id == 2)
        {
                $(this).append(prev_html);
        }
        if (cur_id == 3)
        {
                $(this).append(prev_html);
        }
    });

    $("form.top_form .text_f").each(function(){
       if ($(this).val()) $(this).prev().hide();
     }).focus(function(){
        $(this).prev().hide();
     }).blur(function(){
       if (!$(this).val()) $(this).prev().show();
     });


     $(".select_style").selectBox();

     $("#1 > div.nav_cont").css('position', 'relative');
     $("#1 > div.nav_cont").append("<img src='/images/right_shadow.png' alt='' style='position:absolute;top:0;left:0;' id='right_shadow' />");

     $(".nav_cont").css('cursor', 'pointer');

     $("#slider1").css( 'cursor', 'pointer' );
     $(".menu").css('cursor', 'pointer');
     $(".sl_but_mid").css('cursor', 'pointer');
});

function isInt(n)
{
	return n % 1 == 0;
}

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function showInfo()
{
    $("#small_block").hide();
    $("#big_block").show();
}
function hideInfo()
{
    $("#small_block").show();
    $("#big_block").hide();
}
function showHideHeaderForm()
{
	if ($(".whois").is(':visible'))
	{
		$(".login").show();
		$(".whois").hide();
		$("#switch_text").html("Проверить домен");
	}
	else
	{
		$(".login").hide();
		$(".whois").show();
		$("#switch_text").html("Авторизоваться");
	}
}

function changeTime()
{
	var sel_time = $("#time").val();
	var cur_q = $("#currency").val();
	var cur_ind = 1;
	$(".tp_price").each(function() {
		var cur_price = $("#fix_price_"+cur_ind).html();
		if (cur_q == 'd')
			cur_price = cur_price/30;
		
		var time_price = 0;
		var minus_price = 0;
		if (sel_time == 12)
		{
			time_price = (cur_price * sel_time) - ( ((cur_price*sel_time)/100)*20);
			minus_price = ((cur_price*sel_time)/100)*20;
			$("#time_text_"+cur_ind).html("в год");
			$("#price_for_month_"+cur_ind).show();
			$("#disc_"+cur_ind).show();
		}
		else if (sel_time == 6)
		{
			time_price = (cur_price * sel_time) - ( ((cur_price*sel_time)/100)*10);
			minus_price = ((cur_price*sel_time)/100)*10;
			$("#time_text_"+cur_ind).html("за 6 мес.");
			$("#price_for_month_"+cur_ind).show();
			$("#disc_"+cur_ind).show();
		}
		else if (sel_time == 3)
		{
			time_price = (cur_price * sel_time) - ( ((cur_price*sel_time)/100)*5);
			minus_price = ((cur_price*sel_time)/100)*5;
			$("#time_text_"+cur_ind).html("за 3 мес.");
			$("#price_for_month_"+cur_ind).show();
			$("#disc_"+cur_ind).show();
		}
		else
		{
			time_price = cur_price;
			minus_price = 0;
			$("#time_text_"+cur_ind).html("за 1 месяц");
			$("#price_for_month_"+cur_ind).hide();
			$("#disc_"+cur_ind).hide();
		}

		if (!isInt(time_price))
		{
			time_price = parseFloat(time_price);
			time_price = time_price.toFixed(2);
		}
		else
			time_price = time_price;

		if (!isInt(minus_price))
		{
			minus_price = parseFloat(minus_price);
			minus_price = minus_price.toFixed(2);
		}
		else
			minus_price = minus_price;

		$("#time_price_"+cur_ind).html(time_price);
		$("#minus_price_"+cur_ind).html(minus_price);

		var month_price = time_price/sel_time;
		if (!isInt(month_price))
		{
			month_price = parseFloat(month_price);
			$("#cur_price_"+cur_ind).html(month_price.toFixed(2));
		}
		else
			$("#cur_price_"+cur_ind).html(month_price);

		cur_ind ++;
	});
	if ($("#special_fix").html())
	{
		var time_price = 0;
		var spec_price = $("#special_fix").html();
		if (sel_time == 12)
		{
			time_price = (spec_price * sel_time) - ( ((spec_price*sel_time)/100)*20);
			$("#spec_txt").html("в год");
			$("#spec_month_price").show();
		}
		else if (sel_time == 6)
		{
			time_price = (spec_price * sel_time) - ( ((spec_price*sel_time)/100)*10);
			$("#spec_txt").html("за 6 мес.");
			$("#spec_month_price").show();
		}
		else if (sel_time == 3)
		{
			time_price = (spec_price * sel_time) - ( ((spec_price*sel_time)/100)*5);
			$("#spec_txt").html("за 3 мес.");
			$("#spec_month_price").show();
		}
		else
		{
			time_price = spec_price;
			$("#spec_txt").html("за 1 месяц");
			$("#spec_month_price").hide();
		}
		if (!isInt(time_price))
		{
			time_price = parseFloat(time_price);
			$("#special_time").html(time_price.toFixed(2));
		}
		else
			$("#special_time").html(time_price);

		var month_price = time_price/sel_time;
		if (!isInt(month_price))
		{
			month_price = parseFloat(month_price);
			$("#special_month").html(month_price.toFixed(2));
		}
		else
			$("#special_month").html(month_price);
	}
}
function changeCurrency()
{
	var cur_q = $("#currency").val();
	var sel_time = $("#time").val();
	var cur_ind = 1;
	var cur_price = 0;
	$(".tp_price").each(function() {
		var fix_price = $("#fix_price_"+cur_ind).html();
		var time_price = 0;
		var minus_price = 0;
		if (cur_q == 'd')
		{
			cur_price = fix_price/30;
/*			$("#cur_char_"+cur_ind).html("$");
			$("#cur_char2_"+cur_ind).html("$");
			$("#cur_char3_"+cur_ind).html("$");*/
			$("#cur_char_"+cur_ind).html("");
			$("#cur_char2_"+cur_ind).html("");
			$("#cur_char3_"+cur_ind).html("");
			$(".dollar").each(function() {
				$(this).show();
			});
		}
		else
		{
			cur_price = fix_price;
			$(".dollar").each(function() {
				$(this).hide();
			});
			$("#cur_char_"+cur_ind).html("р");
			$("#cur_char2_"+cur_ind).html("р");
			$("#cur_char3_"+cur_ind).html("р");
		}

		if (sel_time == 12)
		{
			time_price = (cur_price * sel_time) - ( ((cur_price*sel_time)/100)*20);
			minus_price = ((cur_price*sel_time)/100)*20;
		}
		else if (sel_time == 6)
		{
			time_price = (cur_price * sel_time) - ( ((cur_price*sel_time)/100)*10);
			minus_price = ((cur_price*sel_time)/100)*10;
		}
		else if (sel_time == 3)
		{
			time_price = (cur_price * sel_time) - ( ((cur_price*sel_time)/100)*5);
			minus_price = ((cur_price*sel_time)/100)*5;
		}
		else
		{
			time_price = cur_price;
			minus_price = 0;
		}

		if (!isInt(time_price))
		{
			time_price = parseFloat(time_price);
			$("#time_price_"+cur_ind).html(time_price.toFixed(2));
		}
		else
			$("#time_price_"+cur_ind).html(time_price);

		if (!isInt(minus_price))
		{
			minus_price = parseFloat(minus_price);
			$("#minus_price_"+cur_ind).html(minus_price.toFixed(2));
		}
		else
			$("#minus_price_"+cur_ind).html(minus_price);


		var month_price = time_price/sel_time;
		if (!isInt(month_price))
		{
			month_price = parseFloat(month_price);
			$("#cur_price_"+cur_ind).html(month_price.toFixed(2));
		}
		else
			$("#cur_price_"+cur_ind).html(month_price);


/*		if (!isInt(cur_price))
		{
			cur_price = parseFloat(cur_price);
			$("#cur_price_"+cur_ind).html(cur_price.toFixed(2));
		}
		else
			$("#cur_price_"+cur_ind).html(cur_price);*/

		cur_ind ++;
	});

	if ($("#special_fix").html())
	{
		var sel_time = $("#time").val();
		var spec_price = $("#special_fix").html();
		var cp = 0;
		if (cur_q == 'd')
		{
			cp = spec_price/30;
			$("#spec_cur").html('$');
			$("#spec_cur2").html('$');
		}
		else
		{
			cp = spec_price;
/*			$("#spec_cur").html("<img src='/images/ruble.gif' class='ruble-img' />");
			$("#spec_cur2").html("<img src='/images/ruble.gif' class='ruble-img' />");*/
			$("#spec_cur").html("р");
			$("#spec_cur2").html("р");
		}

		if (sel_time == 12)
		{
			time_price = (cp * sel_time) - ( ((cp*sel_time)/100)*20);
		}
		else if (sel_time == 6)
		{
			time_price = (cp * sel_time) - ( ((cp*sel_time)/100)*10);
		}
		else if (sel_time == 3)
		{
			time_price = (cp * sel_time) - ( ((cp*sel_time)/100)*5);
		}
		else
		{
			time_price = cp;
		}

		if (!isInt(time_price))
		{
			time_price = parseFloat(time_price);
			$("#special_time").html(time_price.toFixed(2));
		}
		else
			$("#special_time").html(time_price);

		if (!isInt(cp))
		{
			cp = parseFloat(cp);
			$("#special_month").html(cp.toFixed(2));
		}
		else
			$("#special_time").html(cp);
	}
}

function showReq(prior_id)
{
	$.ajax({
	  type: "POST",
	  url: "/netcat/modules/ajax/show_req.php",
	  data: "req_id="+prior_id,
	}).done(function( res ) {
		$("#req").html(res);
	});

	return false;
}

function showTP(tp_ind)
{
	if ($("#tp_"+tp_ind).is(":visible"))
		$("#tp_"+tp_ind).hide();
	else
		$("#tp_"+tp_ind).show();
	return false;
}

