
$(document).ready(function(){
	$(window).scroll(function(){
		if($(window).scrollTop()>1000)
			$('.scroll_fix_bg').show(); 
		else 
			$('.scroll_fix_bg').hide(); 
	});
	$('.scroll_fix_bg').click(function(){$(window).scrollTop(0);});
});


function clc(txt){
var el=document.getElementById("textarea");
	el.focus();
    var start=el.selectionStart;
    var end=el.selectionEnd;
	el.value=el.value.substring(0,el.selectionStart)+
    txt+
	el.value.substring(el.selectionStart,el.selectionEnd)+
	""+
    el.value.substring(el.selectionEnd);
	el.selectionStart=start+txt.length;
	el.selectionEnd=el.selectionStart;
}

window.onload = function(){ 
	window.setTimeout(
		function(){ 
			window.addEventListener(
				"popstate",  
				function(e){
					e.preventDefault(); 
					Page.Prev(e.state.link);
				},  
			false); 
		}, 
	1); 
}

var Page = {
	Loading: function(f){
		if(f == 'start'){
			$('#loading').show();
			$('#window').html('').hide();
		}
		if(f == 'stop'){
			$('#loading').hide();
			$('html, body').scrollTop(0);
		}
	},
	Go: function(h){
	
		history.pushState({link:h}, null, h);
		Page.Loading('start');
		
		$('.content').load(h, {ajax: 'yes'}, function(data){
			Page.Loading('stop');
		});
	},
	Prev: function(h){
		
		Page.Loading('start');
		$('.content').load(h, {ajax: 'yes'}, function(data){
			Page.Loading('stop');
		});		
	}
}

var Window = {
		Open: function(h){
		$('#window').load(h, {ajax: 'yes', window: 'yes'}, function(data){
		$('#window').fadeIn(200);
		});
	},
		Close: function(){
		$('#window').fadeOut(200);
	}
}


var Like = {
		Go: function(h,id){		
		$('#like_'+id).load(h, {ajax: 'yes'}, function(data){
		});
	}
}

var Smiles = {
		Open: function(){	
		$('#block_smiles').load('/smiles.php', {ajax: 'yes'}, function(data){
		$('#block_smiles').slideDown(200);
		$('#button_smiles_open').hide();
		$('#button_smiles_close').show();
		});
	},
		Close: function(){		
		$('#block_smiles').slideUp(200);
		$('#button_smiles_open').show();
		$('#button_smiles_close').hide();
	}
}

var Title = {
		Open: function(h){
		$('#title_menu').slideDown(200);
	}
}

var Notifications = {
		Close: function(id){
		$('#block_notification_close_'+id).remove();
	}
}

var Dialog = {
		Refresh: function(id){		
		$('#refresh_dialog').load('/mail/?id='+id+' '+'#refresh_dialog span', {ajax: 'yes'}, function(data){
		});
	}
}

var BlockMenu = {
		Open: function(id){
		$('div#block_menu_'+id).slideDown(200);
		$('a#block_menu_'+id).attr('onClick', 'BlockMenu.Close('+id+'); return false');
		$('img#block_menu_'+id).attr('src', '/design/img/menu_hide.png');
	},
		Close: function(id){
		$('div#block_menu_'+id).slideUp(200);
		$('a#block_menu_'+id).attr('onClick', 'BlockMenu.Open('+id+'); return false');
		$('img#block_menu_'+id).attr('src', '/design/img/menu_show.png');
	}
}