
/* Highslide Bilder-Gallerie */
hs.graphicsDir = 'highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'glossy-dark';
hs.wrapperClassName = 'dark';
hs.fadeInOut = true;

if (hs.addSlideshow) hs.addSlideshow({
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .6,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

/* eigener BB-Editor */
var undos = new Array();
var redos = new Array();

function loadlikebutton() {
/* <fb:like href="http://www.facebook.com/pages/Schachclub-Kreut-eV/193380657351555" layout="button_count" show_faces="true" font="lucida grande" colorscheme="dark"></fb:like> */
	
	$('fblike').innerHTML = '<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FSchachclub-Kreut-eV%2F193380657351555&amp;layout=button_count&amp;show_faces=true&amp;width=90&amp;action=like&amp;font=lucida+grande&amp;colorscheme=dark&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe>';
}

function BBAutoReplace(input) {
	// Replace mail-adresses
	input.value = input.value.replace(/(\S+)@(\S+)\.(\w+)/gi, "[email]$1@$2.$3[/email]");

	// Remove double email-tags
	input.value = input.value.replace(/\[email\]\[email\]/gi, "[email]");
	input.value = input.value.replace(/\[\/email\]\[\/email\]/gi, "[/email]");

	// Replace URLs
	input.value = input.value.replace(/http:\/\/(\S+)\.(\S+)/gi, "[url]http://$1.$2[/url]");
	input.value = input.value.replace(/www.(\S+)\.(\S+)/gi, "[url]http://www.$1.$2[/url]");

	// Remove many url-tags
	input.value = input.value.replace(/\[url\]http:\/\/\[url\]/gi, "[url]");
	input.value = input.value.replace(/\[\/url\]\[\/url\]/gi, "[/url]");
	input.value = input.value.replace(/\[url\]\[url\]/gi, "[url]");
	input.value = input.value.replace(/\[\/url\]\[\/url\]/gi, "[/url]");
}

function BBRedo(id) {
	if(typeof redos[id][redos[id].length-1] != 'undefined') {
		$(id).value = redos[id][redos[id].length-1];

		redos[id].pop();		
	}
}

function BBUndo(id) {
	if(typeof undos[id][undos[id].length-1] != 'undefined') {

		if(typeof redos[id] == 'undefined')
			redos[id] = new Array();

		redos[id][redos[id].length] = $(id).value;

		$(id).value = undos[id][undos[id].length-1];

		undos[id].pop();
	}
}

function bbprompt(atag, etag, txt, input) {
	var reply; 

	input.focus();
	
	// Prüfen ob Text markiert
	if(typeof document.selection != 'undefined') {
		// Internet Explorer >_> (fahr zur Hölle)
		var range = document.selection.createRange();

		reply = range.text;
	} else {
		// Firefox, Opera, alles brauchbare
		var start = input.selectionStart;
		var end = input.selectionEnd;
		
		reply = input.value.substring(start, end);
	}


	if(reply.length <= 0) 
		reply = prompt(txt, "");
	
		
	if(reply != null) 
		addbbcode(atag + reply + etag, input);
}

function addbbcode(tag, input) {
	input.focus();

	if(typeof undos[input.id] == 'undefined')
		undos[input.id] = new Array();

	undos[input.id][undos[input.id].length] = input.value;

	if(typeof redos[input.id] != 'undefined') {
		while(redos[input.id].length > 0)
			redos[input.id].pop();
	}
  
	if(typeof document.selection != 'undefined') {
		//  Internet Explorer >_>
		
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = tag;
		
		range = document.selection.createRange();
		if (insText.length != 0) {
		  range.moveStart('character', tag.length + insText.length );      
		}
		range.select();
	} else {
		//	Gute Browser
		var start = input.selectionStart;
		var end = input.selectionEnd;

		input.value = input.value.substr(0, start) + tag + input.value.substr(end);
		
		var pos;

		pos = start + tag.length;

		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
}


/* JavaScript-Popups von http://dhtmlpopups.webarticles.org/movable.php */
var ie = document.all;
var nn6 = document.getElementById &&! document.all;

var isdrag = false;
var x, y, tx, ty, my;
var dobj;

function movemouse( e ) { 
  var ev = nn6 ? e : window.event;

  if (ev.pageX === undefined) {    // Internet Explorer
    var pageX = ev.clientX + document.documentElement.scrollLeft;
    var pageY = ev.clientY + document.documentElement.scrollTop;
  } else {  // Firefox, Opera, Google Chrome and Safari
    var pageX = ev.pageX;
    var pageY = ev.pageY;
  }


  if( isdrag ) {
    dobj.style.left = pageX - 20 + 'px';
    dobj.style.top  = pageY - 20 + 'px';
    return false;
  }

  my = pageY;
}

function selectmouse( e ) {
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";

  while (fobj.tagName != topelement && fobj.className != "dragme") {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }

  if (fobj.className=="dragme") {
    isdrag = true;

    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
  
    return false;
  }
}

function styledPopupClose( popup ) {
	popup.style.display = "none";
}

function showPopUp( popup ) {
	// Close all other PopUps
	pops = document.getElementsByTagName("div");
	for(var i = 0; i < pops.length; i ++) {
		if(pops[i].className == "styled_popup")
			styledPopupClose(pops[i]);
	}

	// Open new PopUp
	dobj = popup;
	popup.style.display = 'block';
	
	// Position new PopUp
	//ty = document.body.clientHeight - 500;
	ty = my;
	tx = document.body.clientWidth / 2 - 150;


	popup.style.top = ty + 'px';
	popup.style.left = tx + 'px';
}

/* Hinweis auf Schachspiel */
var dispVal = true;
function blink() {
	if (dispVal) {
		dispVal = false;
		document.getElementById("mnuLive-Schach").style.color="#FF4848";
	} else {
		dispVal = true;
		document.getElementById("mnuLive-Schach").style.color="#FFFFFF";
	}
}

document.onmousemove = movemouse;
document.onmousedown = selectmouse;
document.onmouseup = new Function("isdrag=false");
