/*
	VolonType 0.1
	---------------------
	2010 Philip Cristofor
	---------------------
	www.volontaire.se
*/

// VARS
voLogo = 1;

$(function (){  
	
	// Fixa heights och grejer
	winHeight 	= $(window).height();
	winWidth 	= $(window).width();
	$("#typeWrap").height(winHeight-67);
	
	wrapHeight 	= $("#typeWrap").height();
	$("#typewriter").height(wrapHeight);
  	
  	$("#typer").height("100%");
	
	// Centrera loggan
	$("#logo").OpCenter();
	
	// Ladda Rich Text-grejen
	var typer = $('#typer').rte({
		css: ['css/master.css'],
		width: 700,
		controls_rte: volontools,
	}, typer);
	
	// Skala med fönstret, mmkay?	
	$(window).bind('resize', function() {
			$("#typeWrap").height($(window).height()-67);
			$("#typewriter").height($("#typeWrap").height());
			$("#typer").height($("#typeWrap").height());
			$("iframe").attr({'height':'100%'});
	});
	
	// Skicka till skrivare
	$("#typePrint").click(function(){
		window.frames['volontype'].focus();
		window.frames['volontype'].print();
	});
	
	// Skicka som e-post
	$("#typeSend").click(function(){
		var epostadd = prompt("To where?","valid@email.pls");
		var epostmsg = window.frames['volontype'].document.body.innerHTML;
		if (epostadd) {
			$.get("/type/sendType.php", {email:epostadd, message:epostmsg}, function(){
				alert("It was sent!\n\nKTHXBAI")
			});
		}
		
	});
	
	// Ta bort allt, typ med en knapp eller Escape
	$("#typeClear").click(function(){
		if(confirm("Clear All?\nThere is NO UNDO possible!")) window.frames['volontype'].document.body.innerHTML ="";
	});
	
	$(window.frames['volontype']).keyup(function (e) {
		if(e.which == 27) {
			if(confirm("Clear All?\nThere is NO UNDO possible!")) window.frames['volontype'].document.body.innerHTML ="";
		}
	});
	
	// GÖM ALLT
	
	$("#typer").mouseenter(function(){
		$("#typesaver").fadeOut(500);
		$(".rte-toolbar").fadeOut(500);
	});
	
	$("#typer").mouseleave(function(){
		$("#typesaver").fadeIn(500);
		$(".rte-toolbar").fadeIn(500);
	});
	
	$("#typesaver").mouseenter(function(){
		$("#typesaver").show();
	});
	
	$(".rte-toolbar").mouseenter(function(){
		$(".rte-toolbar").show();
	});
	
	// Töm Loggan
	setTimeout('$("#logo").fadeOut(200)', 2000);

}); 

jQuery.fn.OpCenter = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height()-100 ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
