// JavaScript Document
$(document).ready(function(){

	 	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
        var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
        isIe6 = (jQuery.browser.msie && (ie55 || ie6))

		if(isIe6){
			DD_belatedPNG.fix('*');
		}
			
		$('#test_domen_form').submit(function() {
			$("#checkdombut").trigger('click');
			return false;
		});

		$('table.krug tr:first').addClass('head');
		$('table.krug tr').each(function(){
			$(this).find('td:first, th:first').addClass('first');
			$(this).find('td:last, th:last').addClass('last');
		});
		$('table.krug tr:even:not(:first)').addClass('even');
		
		function in_array( needle, haystack) {
			for(var key in haystack){
				if (haystack[key] === needle){
				    return true;
				}
			}
			 return false;
		}
		function checkdomain(){
			var isNoZone = true;
			var table = $('#checkdomres table tbody');
			var i = 0;
			table.find('tr:gt(0)').remove();
			var domname = $('#test_domen .left input, #test_domen_lite .left input').val();
			$('#test_domen .checkbox input:checked, #test_domen_lite .checkbox input:checked').each(function(){
				isNoZone = false;
				var zone = $(this).next().html()
				var fuldomname = domname + zone;
				table.html(table.html() + '<tr id="trdom' + i +'"><td class="name">' + fuldomname + '</td><td class="res"><img src="/images/loader.gif"></td><td class="buy"><a href="https://shop.appletec.ru/manager/billmgr?func=register&amp;welcomfunc=domain.order&amp;welcomparam=price=' + $(this).next().attr('id') + '" style="display: none;"><img src="/images/tarif_buy.png"></a></td></tr>');
		
				var ruZones = [".рф", ".ру", ".орг", ".ком", ".нет", ".ком.рф", ".нет.рф", ".орг.рф"];
				if(in_array(zone, ruZones))
					var is_ru = 1;
				else
					var is_ru = 0;	
					
				var str = "$.post('/whois.php?domain=" + fuldomname + "', {i:'" + i + "', is_ru:'" + is_ru + "'}, function(obj){	var tr = $('#checkdomres table tbody tr#trdom' + obj.i);	if(obj.res == '1') {	tr.find('td.res').html('свободен');	tr.find('td.res').css('color','#669900');	tr.find('td.buy a').show();		}	else {	if(obj.res == '0')	tr.find('td.res').html('занят');	else	tr.find('td.res').html('ошибка');	tr.find('td.res').css('color','#cc0000');	}	}, 'json');";				
				setTimeout(str, i*1000);
				i++;	
			}		
			);
			table.find('tr:even').addClass('color');
			if(isNoZone){
				//$.fancybox.close;
				alert('Необходимо выбрать хотябы одну зону для проверки');				
			}
			//$.fancybox.resize;
		}
		$("#checkdombut").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				onComplete		: function(){checkdomain()}
			});

		$("a.highslide").fancybox({
					'opacity'		: true,
					'overlayShow'	: true,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic'
				});	
		$('#review').css('top',Math.round($(window).height()/2) + 'px');
		//для ие 6 :)
		$("#vacancy div.line:last").css({'padding':'0','margin':'0', 'background':'none'});
		$("#vacancy div.line:last").remove();
		$("#partner .wrapper").jCarouselLite({			
			auto: 10000, //задержка между слайдами при автопрокрутке NULL для отключения 
			visible: 6, //сколько показываем
			easing: "easeInOutSine",
			speed: 1000,
			scroll: 1,
			btnNext: "#partner .next", //id кнопки вперед
			btnPrev: "#partner .prev" //id кнопки назад
		});
			
		$('#main_menu>ul>li>ul').each(
			function(){
				$(this).html("<li class='first'><div></div></li>" + $(this).html() + "<li class='last'><div><div></div></div></li><div class='clear'></div>");
				$(this).find('li>a:last').addClass('last');
			});		
		$('#main_menu>ul>li>ul>li>ul').each(
			function(){
				$(this).html("<li class='first'><div><div></div></div></li>" + $(this).html() + "<li class='last'><div><div></div></div></li><div class='clear'></div>");
				$(this).find('li>a:last').addClass('last');
				$(this).find('li ul').each(
					function(){
						$(this).html("<li class='first'><div><div></div></div></li>" + $(this).html() + "<li class='last'><div><div></div></div></li><div class='clear'></div>");
						$(this).find('li>a:last').addClass('last');
					});
			});
			
		$('#main_menu>ul>li,#main_menu>ul>li>ul>li,#main_menu>ul>li>ul>li>ul>li').hover(
			function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');
			}
		);
		if(isIe6)
		{
			$("#main_menu ul li ul li.first, #main_menu ul li ul li.last").remove();
		}	
		
		$("#bottom_menu li:first").addClass('first');
		
		
		$("#tab_menu ul li a:first").trigger('click');
		$("#tab_menu ul li a").click(function() {
				if(!$(this).hasClass('active'))
				{
				    	$.ajax({
								url: $(this).attr('href'),
								cache: true,
								dataType: "html",   
								success: function(html){
									$("#tab_content").empty();
									$("#tab_content").html(html); 						
									return false;}
						      });
					$("#tab_menu ul li a.active").removeClass('active');				
					$(this).addClass('active');									
				}			
				return false;
		});
		if(isIe6){		
			/*
			$('table.tarif td a img').each(function() {
				$(this).parent().addClass('buyintariftoie6');
			});
			*/	
			DD_belatedPNG.fix('*');
		}
	})

