$(document).ready(function(){
    
    $('.word_count').each(function() {
        var input = '#' + this.id;
        var count = input + '_count';
        $(count).show();
        word_count(input, count);
        $(this).keyup(function() { word_count(input, count) });
    });

$("a").tooltip({
	delay:0,
	showURL: false,
	track: true,
	showBody: " - "
	});
	
$("img").tooltip({
	delay:0,
	showURL: false,
	track: true,
	showBody: " - "
	});
	
$(".tools").tooltip({
	delay:0,
	showURL: false,
	track: true,
	showBody: " - "
	});
 

$("#rediger").click(function() {
	$("#links").toggle();
	});

$("#ting").click(function() {
	$("#tings").toggle();
	});
	
$("#friendonline").click(function() {
	$("#fron").toggle();
	});
});

function NextBefore(show, close) {
	$("#" + show).show("slow");
	$("#" + close).hide();
}

 function showhide(id) {
 $("#" + id).toggle("slow");
 }
 
 function tilflink() {
	var side = $("#side").html();
	$("#linkrrr").append('<div id="dialog" style="display:none;" title="Tilføj Dit Quicklink"><form method="post" action="/include/ting/link.php"><input type="text" style="width:100%;" name="navn" title="Hvad skal navnet være på det?"><br /><input type="submit" value="Opret QuickLink Nu!"><br /><input type="hidden" name="side" value="'+ side +'"></form></div>');
 
 $("#dialog").dialog({
					bgiframe: true,
					width: 350,
					draggable: false,
					resizable: false,
					modal: true
				});
 }
 

function word_count(field, count) {

    var number = 0;
    var matches = $(field).val().match(/\b/g);
    if(matches) {
        number = matches.length/2;
    }
    $(count).text( number + ' Ord');

}

 function chat_popup() {
window.open( "http://hogwartsschool.dk/chat/", "chat", 
"status = 1, height = 520, width = 780, resizable = 0" )
}

function show (id) { $("#" + id).show (); }
function vis (id) { $("#" + id).hide (); }
function luk (id) { $("#" + id).hide(); }

function menu_to(id) { 
    $("#"+id).toggle('fast');
}

function gem(id) {
    $("#"+id).hide();
}

function gemet(id) {
    $("."+id).hide();
}

function viset(id) {
    $("."+id).show();
}

function klokken(){
var tid = new Date();
var time = tid.getHours();
if(time < 10){
time = "0"+time;
}
var minut = tid.getMinutes();
if(minut < 10){
minut = "0"+minut;
}
var sekund = tid.getSeconds();
if(sekund < 10){
sekund = "0"+sekund;
}

var klokken = time+":"+minut+":"+sekund;

document.getElementById("visUr").innerHTML = klokken + '<img src="/img/icons/clock.png" style="float:right;" />';

window.setTimeout("klokken();",1000);
}
	
function klik (lol,hj) {
if(document.getElementById(hj).value==lol) {document.getElementById(hj).value = '';}
}
function blur (mahope,jh) {
if(document.getElementById(jh).value == '') {document.getElementById(jh).value = mahope;}
}


jQuery.fn.hint = function (blurClass) {

if (!blurClass) { 

blurClass = 'blur';

}

return this.each(function () {

// get jQuery version of 'this'

var $input = jQuery(this),

// capture the rest of the variable to allow for reuse

title = $input.attr('title'),

$form = jQuery(this.form),

$win = jQuery(window);

function remove() {

if ($input.val() === title && $input.hasClass(blurClass)) {

$input.val('').removeClass(blurClass);

}

}

// only apply logic if the element has the attribute

if (title) { 

// on blur, set value to title attr if text is blank

$input.blur(function () {

if (this.value === '') {

$input.val(title).addClass(blurClass);

}

}).focus(remove).blur(); // now change all inputs to title

// clear the pre-defined text when form is submitted

$form.submit(remove);

$win.unload(remove); // handles Firefox's autocomplete

}

});

};

$(document).ready(function(){ 

$('input:text').hint();
$('input:password').hint();
$('textarea').hint();
});


/**
 * jQuery sound plugin (no flash)
 * 
 * port of script.aculo.us' sound.js (http://script.aculo.us), based on code by Jules Gravinese (http://www.webveteran.com/) 
 * 
 * Copyright (c) 2007 Jörn Zaefferer (http://bassistance.de) 
 * 
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *   
 * $Id: jquery.sound.js 5854 2008-10-04 10:22:25Z joern.zaefferer $
 */

/**
 * API Documentation
 * 
 * // play a sound from the url
 * $.sound.play(url)
 * 
 * // play a sound from the url, on a track, stopping any sound already running on that track
 * $.sound.play(url, {
 *   track: "track1"
 * });
 * 
 * // increase the timeout to four seconds before removing the sound object from the dom for longer sounds
 * $.sound.play(url, {
 *   timeout: 4000
 * });
 * 
 * // stop a sound by removing the element returned by play
 * var sound = $.sound.play(url);
 * sound.remove();
 * 
 * // disable playing sounds
 * $.sound.enabled = false;
 * 
 * // enable playing sounds
 * $.sound.enabled = true
 */

(function($) {
	
$.sound = {
	tracks: {},
	enabled: true,
	template: function(src) {
		// todo: move bgsound element and browser sniffing in here
		// todo: test wmv on windows: Builder.node('embed', {type:'application/x-mplayer2', pluginspage:'http://microsoft.com/windows/mediaplayer/en/download/',        id:'mediaPlayer', name:'mediaPlayer', displaysize:'4', autosize:'-1', bgcolor:'darkblue', showcontrols:'false', showtracker:'-1', showdisplay:'0', showstatusbar:'-1', videoborder3d:'-1', width:'0', height:'0', src:audioFile, autostart:'true', designtimesp:'5311', loop:'false'});
		// is_win = (agt.indexOf("windows") != -1);
		return '<embed style="height:0" loop="false" src="' + src + '" autostart="true" hidden="true"/>';
	},
	play: function(url, options){
		if (!this.enabled)
			return;
		options = $.extend({
			url: url,
			timeout: 2000
		}, options);
		
		if (options.track) {
			if (this.tracks[options.track]) {
				var current = this.tracks[options.track];
				// TODO check when Stop is avaiable, certainly not on a jQuery object
				current[0].Stop && current[0].Stop();
				current.remove();  
			}
		}
		
		var element = $.browser.msie
		  	? $('<bgsound/>').attr({
		        src: options.url,
				loop: 1,
				autostart: true
		      })
		  	: $(this.template(options.url));
			
		element.appendTo("body");
		
		if (options.track) {
			this.tracks[options.track] = element;
		}
		
		setTimeout(function() {
			element.remove();
		}, options.timeout)
		
		return element;
	}
};

})(jQuery);

