this.slideshow = function(obj) {	
		//var obj = $("#templates");
		var s = $("li", obj).length;
		var w = obj.width(); 		
		var ts = s-1;
		var t = 0;
		$("ul", obj).css("width",s*w);
		$(obj).parent().append("<span class=\"prev\"><a href=\"javascript:void(0);\"></a></span> <span class=\"next\"><a href=\"javascript:void(0);\"></a></span>");
		
		$(".prev a", obj.parent()).hide();
		$(".next a", obj.parent()).click(function(){		
			animate("next");
			if (t>=ts) $(this).fadeOut();
			$(".prev a", obj.parent()).fadeIn();
		});
		$(".prev a", obj.parent()).click(function(){		
			animate("prev");
			if (t<=0) $(this).fadeOut();
			$(".next a", obj.parent()).fadeIn();
		});	
		this.animate = function(dir){
			if(dir == "next"){
				t = (t>=ts) ? ts : t+1;	
			} else {
				t = (t<=0) ? 0 : t-1;
			};		
			p = (t*w*-1);		
			$("ul",obj).animate(
				{ marginLeft: p }, 
				800
			);	
		};
		animate("next");
		$(".prev a", obj.parent()).fadeIn();
};


this.pngfix = 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);
	if (jQuery.browser.msie && (ie55 || ie6)) {		
		$("*").each(function(){
			var bgIMG = $(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				$(this).css('background-image', 'none');
				$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			};
		});
	};		
};

this.init = function() {
	pngfix();
	//nav();	
	$("#walls").each(function(){	
		slideshow($(this));	
	});		
preview();
};

$(document).ready(function(){	
init();
});


// определяем общую переменную, которая будет содержать
// выделенный текст
var txt_quote="";
var user="";
var num="";

function copy_txt(id) {
// Если переменная txt_quote не пустая, то очищаем её
   txt_quote="";
   user="";
   num="";
  if (window.getSelection) {
     txt_quote = window.getSelection().toString();
	 user = document.getElementById('user' + id).value;
	 num = document.getElementById('num' + id).value;
  } else if (document.getSelection) {
    txt_quote = document.getSelection();
	user = document.getElementById('user' + id).value;
	 num = document.getElementById('num' + id).value;
  } else if (document.selection) {
    txt_quote = document.selection.createRange().text;
	user = document.getElementById('user' + id).value;
	num = document.getElementById('num' + id).value;
  }  
}

function paste_txt(id) {
// \n - перевод на новую строку
   if (txt_quote=="") {
//Когда будете копировать скрипт, не забудьте объеденить две нижние строчки в одну
    alert("Для вставки цитаты в новое сообщение \nвыделите нужный текст и нажмите - Вставить цитату");
    } else {
  document.getElementById('text').value += "[quote]" + document.getElementById('user' + id).innerHTML + ", " + document.getElementById('num' + id).innerHTML  + "\n\n";
  document.getElementById('text').value += txt_quote + "[/quote]\n";
    }
}


function text_bold(){ text_add_tag('b'); }
function text_italic(){ text_add_tag('i'); }
function text_spoiler(){ text_add_tag('spoiler'); }

function text_add_tag(tag_name){
	var el = document.post.text;
	if(!el) return;
	el.focus();
	if(el.selectionStart != undefined){
		var s, e, move_to;
		if((s = el.selectionStart) != (e = el.selectionEnd)){
			el.value = el.value.substring(0, s) + '[' + tag_name + ']' + el.value.substring(s, e) + '[/' + tag_name + ']' + el.value.substring(e);
			move_to = e + 2 * tag_name.length + 5;
			el.setSelectionRange(move_to, move_to);
		}
	}
	else if(document.selection && document.selection.createRange){
		var rng = document.selection.createRange();
		rng.text = '[' + tag_name + ']' + rng.text + '[/' + tag_name + ']';
	}
}
