$(document).ready(function()
{
	// messenger {
	$('.webmin-call u').click(function()
	{
		addr = '/webim'+
		'/client.php?locale=ru&theme=default&'+
		'opener='+
		encodeURIComponent(document.location.href) + 
		'&openertitle='+
		encodeURIComponent(document.title);

		$('#index').prepend("<div class='webmin-wrapper'><p><a href='#close'>закрыть</a></p><iframe style='width:600px;height:450px' src='"+addr+
		"'></iframe></div>");
		$('.webmin-wrapper').css('position','absolute').css('left',0).css('top','-455px').css('z-index',9999);
		$('iframe').css("border","none").css("background-color","#fff");
		$('iframe').css('background-image','url(/import/i/preloader.gif)').css('background-position','center');
		$('iframe').css('background-repeat','no-repeat');
		$('.webmin-wrapper').animate({top: 0},550);
		
		$('.webmin-wrapper').click(function(){
			$('.webmin-wrapper').animate({top: -455},550,function()
			{
				$(this).remove();
			});
		});
	});
	// messenger }
	
	// what is browser  ??
	 var blog_form_1 = 0;
	 var blog_form_2 = 0;
	 var blog_form_3 = 0;	
	 var ie = 0/*@cc_on+@_jscript_version*10@*/; 
	 if (($.browser.msie) && (jQuery.browser.version=="6.0")) { ie = 56 }

	 // foter naejaaet na img v portfolio
	 if (ie==56)
	 {
		var oob = document.getElementById("foot");
		$("#screenshots img").load(function()
		{			
			if ($("#index").attr("class")=="portfolio")
			{
				$("#foot").css("top",oob.parentNode.offsetHeight - oob.offsetHeight + 'px');
			}			
		});
	}
	// support
	$(".file-send-wrapper input").change(function()
	{
		supportFile($(this));
	});
	
	// index.htm - poyavlenie ssilok s kartinkami
	if (ie!=56)	$("#portfolio_links").animate({opacity: 'toggle'},1500);

	if (ie==56)
	{
		$(window).resize(function()
							  {
								  $("#foot").attr("style", "");
							  });
	}
	
	// blog - flash iconoc setei
	$("#out_blogs_ico a").hover(function()
										 {
											 $(this).animate({opacity: 0.2},150,"linear",function()
																								  {
																									  $(this).animate({opacity: 1},200);
																								  });
										 },
										 function()
										 {
										 });
										 
	
	// blog - sude linki next,prev		
	$("#prev_topic").hover(function()
									{
										
										wdg = 0.03*document.body.clientWidth;
										$("#prev_topic a").stop().animate({width: wdg},100);
									}
									,function()
									{
										$("#prev_topic a").stop().animate({width: 8},100);
									});
		
	$("#next_topic").hover(function()
									{
										
										wdg = 0.03*document.body.clientWidth;
										$("#next_topic a").stop().animate({width: wdg},100);
									}
									,function()
									{
										$("#next_topic a").stop().animate({width: 8},100);
									});	

	// 0index.htm linki na flash/html versii
	$("#enter_to_flash").hover(function()
								{
									$("#link_active").css("left","25px");
									
									$("#link_active").stop().animate({width: 81}, 200);
									$("#enter_to_flash").stop().animate({margintop: 10},100,"linear",function(){
										$("#enter_to_flash").css("background-position", "bottom");
																								   });
								},
								function()
								{
									$("#link_active").stop();
									$("#link_active").css("width", 0);
									$("#enter_to_flash").stop();
									$("#enter_to_flash").css("background-position", "top");
								});
	
	$("#enter_to_html").hover(function()
								{
									$("#link_active").css("left","121px");
									
									$("#link_active").stop().animate({width: 81}, 200);
									$("#enter_to_html").stop().animate({margintop: 10},100,"linear",function(){
										$("#enter_to_html").css("background-position", "bottom");
																								   });
								},
								function()
								{
									$("#link_active").stop();
									$("#link_active").css("width", 0);
									$("#enter_to_html").stop();
									$("#enter_to_html").css("background-position", "top");
								});
	
	// vhod clientov
	$("a.clients_enter").click(function()
										{
											$("#foot_down").css("display","none");
											$("div.enter_page #foot").css("display","none");
											$("#foot_down").css("height: 0")
											$("#authorisation").animate({opacity: 'toggle'},250);
											return false;
										});
	// zakritie okna avtorizacii clienta
	$("#authorisation #form img").click(function()
												 {
													 $("#authorisation").animate({opacity: 'toggle'},250);
												 });
	
	// pervay stranica - poyavlenie footera
	$("#foot_active").hover(function()
			{
					$("#foot_down").stop().animate({height: 164},300);
					$("div.enter_page #foot").stop().animate({height: 164},300);
			},
			function () {}
			);
	
	$("div.enter_page #main").hover(function()
			{
				if ($("#foot_down").css("height") != "0px")
				{
					$("#foot_down").stop().animate({height: 0},300, "linear", function()
																					   {
																						   $("#foot_down").css("display","none");
																					   });
					
					$("div.enter_page #foot").stop().animate({height: 0},300, "linear", function()
																								{
																									$("div.enter_page #foot").css("display","none");
																								});					
				};
			},
			function () {}
			);

	// index.htm - morganie ssilok shapki
	$("#site_menu_links li:not(.act) a").hover(function()
  									   	{
												// ie 8 ne animiryet "opacity" ((
												jQuery(this).animate({color: "#FFFFFF"},100);
												jQuery(this).animate({color: "#000000"},100);
										},
											function(){}
										);

	// krasni fon na menu shapki
	$("#site_menu_links li:not(.act) a").click(function()
										   {
												// kyda click												
												var lnk = this.href;
												xb = $("#site_header").offset().left;
												//alert(xb);
												x00 = jQuery(this).offset().left;
												index0 = $("#site_menu_links a").index(this);

												// korrectirovka shirini
												$("#site_menu_links li").css("border","none");
												$("#site_menu_links li").css("margin-left","55px");

												// gde bili
												x01 = $("#site_menu_links li.act a").offset().left;
												actv = $("#site_menu_links li.act").get(0);
												for (index1=0; index1<=4; index1++)
												{
													if ( $("#site_menu_links li").get(index1) == actv)
													{
														break;
													}												
												};

												$("#effect").css("display","block");												
												$("#effect").css("width","0");												
												if (x00 < x01)
												{
													$("#effect").css("left", x01-xb+"px");
													$("#effect").animate({width: x01-x00,  left: x00-xb},250,"linear",function(){
																											 document.location = lnk;
																											 });	
													for (i=index1-1;i>=index0;i--)
													{
														$("#site_menu_links a:eq("+i+")").animate({color: "#FFFFFF"},(1+(index1-i)*250/(index1-index0)));
													}

												}
												else
												{
													$("#effect").css("left", x01-xb+"px");
													$("#effect").animate({width: x00-x01},250,"linear",function(){
																											 document.location = lnk;
																											 });														
													for (i=index1;i<=index0-1;i++)
													{
														$("#site_menu_links a:eq("+i+")").animate({color: "#FFFFFF"},(1+(i-index1)*250/(index0-index1)));
													}
												};

												return false;
										   });

	// menushka s krasni pod4erkivaniem
	$("#content_menu a").hover(function()
									  {
										$("#content_menu li").removeClass("act");
										var index = $("#content_menu a").index(this)+1;
										$("#content_menu li:lt("+index+")").addClass("act");
									  },
									  function(){}
									  );

	$("#index:not(.portfolio) #content_menu a").click(function()
										{	
											var index = $("#content_menu a").index(this)+1;
											var lnk = this.href;
											// for Opera
											//$("#portfolio_links").css("display","none");
											$("#portfolio_links").animate({opacity: 0},500,"linear",function()
											{
												document.location = lnk;
											});
											return false; 
										});

	$("#content_menu").hover(function(){},
							 function()
							 {
								 $("#content_menu a.act").parents("li").addClass("act");
								 $("#content_menu a:not(.act)").parents("li").removeClass("act");
							 });

	// poyavlenie levogo menu (primer na clients.htm)
	if (ie!=56)
	{
		$("#left_menu").animate({opacity: 'toggle'}, 1500);
	}	
	$("#left_menu a").hover(function()
									  {
										  	jQuery(this).css("width","80px");
											jQuery(this).animate({width: "162px"}, 150);
									  },
									  function(){}
									  );

	// viezg pravogo menu
	
	$("div.clients #left_menu a").click(function()
									 {										 
										 $("#left_menu ul.right_menu").css("display","none");
										 $("#left_menu a").removeClass("act");
										 jQuery(this).addClass("act");
											
										 $("#left_menu").css("width","500px");
										// v ie6 poyzavyzetsya lishya stroka -- xerim ee
										 $("#left_menu li").css("margin","0 0 5px 0");
										 if (ie == 56)
										 {
											 jQuery(this).parent("li").css("margin","0 0 2px 0");
										 };

										jQuery(this).parent("li").children("ul").css("display","block");
										 jQuery(this).parent("li").children("ul").css("opacity","0");
										 jQuery(this).parent("li").children("ul").animate({opacity: 1},1000);
										 var hght = 25*(jQuery(this).parent("li").children("ul").children("li").length);

										// 4eb footer ne naezgal na pravoe  menu
										 if (hght > 200)
										 {
											$("#left_menu").css("height",hght+"px");
											 if (ie == 56 )
											 {
												 if ( $("ul.right_menu li:last").offset().top > $("#foot").offset().top)
												 {
													 fT = 400+hght-200;
													 $("#foot").css("top", fT + "px");
												 }
											 }
										 } else
										 {
												 $("#left_menu").css("height","200px");
										 }
									 });
									 $("div.clients #left_menu a:first").click();

	// efekti na contact.htm
	if (ie!=56)
	{
		$("#contact").animate({opacity: 'toggle'},500);
		$("#map").animate({opacity: 'toggle'},1000);	
	}

	//content
	if (ie!=56)	$("#content").animate({opacity: 'toggle'},500)

	// oindex.htm vhod na blog
	$("#enter_webrover_blog").hover(function()
									  {
										  $("#enter_webrover_blog").stop().animate({opacity: 0.2},125);
										  $("#enter_webrover_blog").animate({opacity: 1},250);
									  },
									function()
									  {
									  }); 
		
	// spisok tag-ov na blog.htm
	$("#other_tags_select #toggl_btn ").click(function()
												{
													$("#other_tags_select #select_list").toggleClass("hiden");
													$("#other_tags_select #toggl_btn").toggleClass("toggle_button");
												});
	$("#select_list a").click(function()
									{
										$("#other_tags_select #toggl_btn").click();									
										$("#select_value").html(jQuery(this).html());	
										
										
										//alert(this.id);
										$("#other_tags_value").attr("value",this.id);
										//return false;
									});	 	
	
	// topic - blink avatara 
	$("#avatar:not(.user_photo) img").hover(function()
													 {
														 $("#avatar img").stop().animate({opacity: 0.1},125);
														 $("#avatar img").animate({opacity: 1},250);
													 },
													 function(){}
													 );

	// avtorizaciya - submit form
	if ($('#user_authorisation') && ($("#authorisation").attr("class")=="blog"))
	{
		$('#user_authorisation').ajaxForm({
			beforeSubmit: function(a,f,o) {
				o.dataType = "json";
				//$('#log_res').addClass('loading');
				//$('#log_res').html("");
			},
			success: function(data) {
				//$('#log_res').removeClass('loading');
				if (data.auth[0] == 1)
					{
					//$('#log_res').html("Ok. Loading...");
					//$("#authorisation #form img").click();
					window.location.replace("/blog/");
					}
					else 
						{
						//$('#log_res').html(data.auth[1]);
						alert(data.auth[1]);
						}
			}
		});
	}
		
	var name0 = String($("#form_post #author_name").attr("value"));
	var text0 = String($("#form_post textarea").html());

	$("#form_post .buton").click(function()
										   {
											   var name = String($("#form_post #author_name").attr("value"));
											   var email = String($("#form_post #author_mail").attr("value"));
											   var text = String($("#form_post textarea").html());
											   
											   var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
											   
											   if (name==name0)
												{
													alert("Введете имя");
													$("#form_post #author_name").css("border-color","#ff0000");
												}
												else 
												{
													if (!email.match(reg)) 
													{
														$("#form_post #author_mail").css("border-color","#ff0000");
														alert("Пожалуйста, введите свой настоящий e-mail");
													}
													else
													{
														alert("OK");
													}
												}
										   });
});

// support
function supportFile(obj)
{
	var fname = String(obj.get(0).value);
	
	
	
	if (fname=="") return false;
	
	var i = fname.lastIndexOf("\\");
	if (i>0)
	{
		fname = fname.substr(i+1);
	}
	obj.parent().find("span").html(fname);
	obj.parent().find("span").css("text-decoration","none");
	
	var len = $(".file-send-wrapper").length;
	
	if ((obj.attr("name")!="file"+(len-1)) && (len>1)) return false;
	
	// add fileloiad
	$("#files-send-wrapper").append("<div class='file-send-wrapper'><input type='file' class='ifile' size='0' name='file"+len+"' /><span class='file-send-click'>" + 
	$("#attach-more").html()+"</span></div>");
		$(".file-send-wrapper").css("overflow","hidden");
		var obj = $(".file-send-wrapper input");
		obj.css("opacity","0");
		obj.css("font-size","20px");
		obj.css("left","-208px");
		$(".file-send-click").css("display","block");
		$(".file-send-wrapper input").change(function()
		{
			supportFile($(this));
		});
}