var NetTest = function(f, s, attempt) {
	var url = "/public/img/nettest/"+f+"kb.jpg";
	
	//var size = s;
	//alert(url);
	
	var testImage = new Image();
	
	testImage.onerror= function(){
		alert("error. "+this.src);
	};
	
	testImage.onload = function(){
		var finish = (new Date() ).getTime();
		
		var totalTime = finish-start;
		//alert(totalTime);
	 
	 
	 if(totalTime<1000 && f<576) {
	 	//if(f<576) {
			NetTest(f*2,s*2, attempt);
			
		
		
	 }
	 else {
	 	var kbps = s * 8 / 1024 / ( totalTime / 1000 );
	 	//alert(kbps);
		
		dpi_x = document.getElementById('testdiv').offsetWidth;		
		dpi_y = document.getElementById('testdiv').offsetHeight;
		
		document.cookie = "client_dpi="+dpi_x+"; domain=."+document.domain.replace("www.", "");
		
		document.cookie = "client_speed="+kbps+"; domain=."+document.domain.replace("www.", "");
		
		document.cookie = "fade=null; domain=."+document.domain.replace("www.", "");
    
	
	//go_to_site("");
		
		$("#dim").fadeOut();
		$("#loader-div").hide();
		if(!$.browser.msie){
			//fn_blinker();
		}
		
		run_animation();
	 }	
	};
		
	
	 
	 
	 
	
	var start = ( new Date() ).getTime();
	testImage.src = url + "?r=" + Math.random();
	
	
	
	
}; // nettest




var run_animation = function(w,h){
	$("div#content-wraper-div").animate({width:w}, 700, function(){
		
		//$("div#animation-div").hide();
		//$("div#content-wraper-div").css('display', 'block');
		
		//$("div#links-div").slideDown(1000);
		$("div#links-div").animate({height: h}, 700, function(){
			resizeFrame();
			$('div.link-div a span').show();
			
			$('#links').fadeIn();
			$('div#footer-div').fadeIn();
			
			$('div.link-div a.uc span.link-text-2').hide();
			
			
			

			
		});
			
	});
}


function resizeFrame(){
	var x = $('body').height();
	
	if($('body').height() < 745){
	
		if(x < 575){
			x = 575;
		}
	
	//	var x = $('body').height();
	
		$("#content-wraper-div").height(x);
		$("#links").width(x*1.05);
		$("#footer-content").width(x*1.05);
		
		
		
		$('div.link-div a').css('font-size', 0.0148*x+'px');
		
		$('div.text-div').css('font-size', 0.0195*x+'px');
		
		

		
		
		

		
	}	
}


$(document).ready(function(){

$('div.link-div a span').hide();
$('#links').hide();



jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);



// loading different css files according to the browser

if($.browser.safari || $.browser.chrome){
		$("head").append("<link>");
    	css = $("head").children(":last");
    	css.attr({
     		rel:  "stylesheet",
     		type: "text/css",
	    	href: "/public/css/chrome.safari.css",
	    	media: "screen"
        });	
}
else if($.browser.opera){
	//alert('fsdfsd');
		$("head").append("<link>");
    	css = $("head").children(":last");
    	css.attr({
     		rel:  "stylesheet",
     		type: "text/css",
	    	href: "/public/css/opera.css",
	    	media: "screen"
        });	
}





$('.link-div a').hover(function(){
	$('img', this).fadeOut();
	$('img.hover', this).fadeIn();
},
function(){
	$('img', this).fadeIn();
	$('img.hover', this).fadeOut();
});


run_animation('100%', '84.55%');

$("div.link-div a.uc").hover(
	function(){
		$("span.link-text", this).hide();
		$("span.link-text-2", this).show();
	},
	function(){
		$("span.link-text", this).show();
		$("span.link-text-2", this).hide();
	}
);



/*				
	if(getCookie("client_dpi")==false){
							
				
	   	$("#dim").css("height", $(document).height());
	  	
	  	$("#dim").fadeIn();
		$("#loader-div").show();
			
		NetTest(4.5, 4608, 1);

	}
	else{
		$("#dim").fadeOut();
		run_animation();
	}

*/			





    	





$("div.branch a.active").hover(
	function(){
		
		$("span.txt", this).addClass("active");
	},
	function(){
		$("span.txt", this).removeClass("active");
	}
);

//var uc = "<div class='uc'>Under Construction</div>";
//var uc = "<div class='uc'>раздел в разработке</div>";

$("div.branch a:not(.active)").hover(
	function(){
		//t = $("div.txt", this).html();
		$("span.txt", this).hide();
		$("span.uc", this).show();
	},
	function (){
		$("span.uc", this).hide();
		$("span.txt", this).show();
	}
);

// glowing images

//fn_blinker();



//$("div#content-wraper-div").css('display', 'block');








});	// end of document.ready










	//	$(window).bind("resize", function(){
	//	 	$("#dim").css("width", $(document).width());
	//	 	$("#dim").css("height", $(document).height());
	//	});





function getCookie(name)

{

	var cookies = document.cookie;

	if (cookies.indexOf(name) != -1)

	{

		var startpos = cookies.indexOf(name)+name.length+1;

		var endpos = cookies.indexOf(";",startpos)-1;

		if (endpos == -2) endpos = cookies.length;

		return unescape(cookies.substring(startpos,endpos));

	}

	else

	{

		return false; // the cookie couldn't be found! it was never set before, or it expired.

	}

}


