﻿/*

	my whole script

*/

(function($) { 	

  $(function() {	  	
	
	$("form textarea, form input").keyup( 
		function() {
			var textStr = $(this).val();
			// small
			textStr = textStr.replace(/а/g, "a");
			textStr = textStr.replace(/б/g, "b");
			textStr = textStr.replace(/в/g, "v");
			textStr = textStr.replace(/г/g, "g");
			textStr = textStr.replace(/д/g, "d");
			textStr = textStr.replace(/е/g, "e");
			textStr = textStr.replace(/ж/g, "j");
			textStr = textStr.replace(/з/g, "z");
			textStr = textStr.replace(/и/g, "i");
			textStr = textStr.replace(/й/g, "i");
			textStr = textStr.replace(/к/g, "k");
			textStr = textStr.replace(/л/g, "l");
			textStr = textStr.replace(/м/g, "m");
			textStr = textStr.replace(/н/g, "n");
			textStr = textStr.replace(/о/g, "o");
			textStr = textStr.replace(/п/g, "p");
			textStr = textStr.replace(/р/g, "r");
			textStr = textStr.replace(/с/g, "s");
			textStr = textStr.replace(/т/g, "t");
			textStr = textStr.replace(/у/g, "u");
			textStr = textStr.replace(/ф/g, "f");
			textStr = textStr.replace(/х/g, "h");
			textStr = textStr.replace(/ц/g, "c");
			textStr = textStr.replace(/ч/g, "ch");
			textStr = textStr.replace(/ш/g, "sh");
			textStr = textStr.replace(/щ/g, "sht");
			textStr = textStr.replace(/ъ/g, "y");
			textStr = textStr.replace(/ь/g, "io");
			textStr = textStr.replace(/ю/g, "ju");
			textStr = textStr.replace(/я/g, "ja");
			// big
			textStr = textStr.replace(/А/g, "A");
			textStr = textStr.replace(/Б/g, "B");
			textStr = textStr.replace(/В/g, "V");
			textStr = textStr.replace(/Г/g, "G");
			textStr = textStr.replace(/Д/g, "D");
			textStr = textStr.replace(/Е/g, "E");
			textStr = textStr.replace(/Ж/g, "J");
			textStr = textStr.replace(/З/g, "Z");
			textStr = textStr.replace(/И/g, "I");
			textStr = textStr.replace(/Й/g, "I");
			textStr = textStr.replace(/К/g, "K");
			textStr = textStr.replace(/Л/g, "L");
			textStr = textStr.replace(/М/g, "M");
			textStr = textStr.replace(/Н/g, "N");
			textStr = textStr.replace(/О/g, "O");
			textStr = textStr.replace(/П/g, "P");
			textStr = textStr.replace(/Р/g, "R");
			textStr = textStr.replace(/С/g, "S");
			textStr = textStr.replace(/Т/g, "T");
			textStr = textStr.replace(/У/g, "U");
			textStr = textStr.replace(/Ф/g, "F");
			textStr = textStr.replace(/Х/g, "H");
			textStr = textStr.replace(/Ц/g, "C");
			textStr = textStr.replace(/Ч/g, "Ch");
			textStr = textStr.replace(/Ш/g, "Sh");
			textStr = textStr.replace(/Щ/g, "Sht");
			textStr = textStr.replace(/Ъ/g, "Y");
			textStr = textStr.replace(/Ь/g, "Io");
			textStr = textStr.replace(/Ю/g, "Ju");
			textStr = textStr.replace(/Я/g, "Ja");
			$(this).val(textStr);
		}
	);
	
	$(".navigation a, a.hover").hover(
		function () {			
			var ImgSrc = $(this).find("img").attr("src");
			if ( ! ImgSrc.match("hover") ) {
				$(this).find("img").attr({ src : ImgSrc.replace(/trans.png/, "hover-trans.png") });			
			}
		},
		function () {
			var ImgSrc = $(this).find("img").attr("src");
			if ( ImgSrc.match("hover") ) {
				$(this).find("img").attr({ src : ImgSrc.replace(/hover-trans.png/, "trans.png") });			
			}
		}
	);
	
	$(".navigation a").not(".submit").click( 
		function () {
			var target = $(this).attr("class");
			target = target.replace(/right /,"");
			target = target.replace(/left /,"");				
			$.scrollTo("#"+target, 1000, {offset : { left:-((screen.width - 990)/2)}, easing:'easeOutQuint'});	
			return false;
		}
	)
	
	var postID = $("input#comment_post_ID").val();	
	
	$(".navigation a.submit").click ( 
		function () {
			$.scrollTo("#comments", 1000, {axis:'x', offset : { left:-((screen.width - 990)/2)}, easing:'easeOutQuint'});			
			$("#comments-loading").show().find("#info").html("posting...");
			$("#comments-wrapper").hide();						
			var values = $("form").serialize();
			var url = $("form").attr("action");
			$.ajax({
				type: "post",
				url: url,
				data: values,
				success: function () {
					$("#comments-loading #info").html("updating html...");
					$("#comments-wrapper").load("?comments_popup="+postID, 
						function () { 					
							$("#comments-wrapper").show(); 
							$("#comments-loading").hide(); 
							FLIR.auto(['h1','h2','h3','h4','h5']); 
							$("form textarea").val("");
						}
					);
				},
				error: function (request, errorText1, errorText2) {
					alert("error : you might be posting the same comment or you have missed to fill a field");
					$("#comments-wrapper").show(); 
					$("#comments-loading").hide(); 
				}
			});
			return false;
		}
	)	
	
	$("#loading").hide();
	$("#container").show();
	$.scrollTo("#main", 0, {offset : { left:-((screen.width - 990)/2)}});
			
  });  
})(jQuery);

/* etst */
