document.observe('dom:loaded', domLoaded);
document.observe('starbox:rated', rate);

function domLoaded(){
	
}

function rate(event){
	new Ajax.Request('/rate.php', {
	parameters: event.memo }
	);
}

function hideCode(element, code){
	new Effect.toggle(code, 'blind', {duration:.4});
	if(element.name == 'watch'){
		new Element.update(element, 'Verberg code');
		element.name = 'hide';
	}
	else{
		new Element.update(element, 'Bekijk code');
		element.name = 'watch';	
	}
}

function calcFontCode(id, src){
	text = $('text.' + id);
	button = $('button.' + id);
	textarea = $('textarea.' + id);
	images = $('images.' + id);
	code = $('code.' + id);
	
	if(!text.value.blank()){
		imagetags = '';
		textareacode = '[gadget]';
		for(c=1; c<=text.value.length; c=c+1){
			letter = text.value.substr((c-1), 1).toLowerCase();
			if(letter == ' '){
				letter = 'spatie';	
			}
			if(letter.match('[a-z]+'))
			{
				textareacode = textareacode + '<img src="'+src+letter.toLowerCase()+'.gif" />';
				imagetags = imagetags + '<img src="'+src+letter+'.gif" />';
			}
		}
		textareacode = textareacode + '[/gadget][url=http://www.krabbelmaar.nl]Krabbels met je eigen tekst? Ga naar: krabbelmaar.nl ![/url]';
		Element.update(images, imagetags);
		//alert(textareacode);
		new Effect.BlindDown(code, {duration:.4});
		Element.update(textarea, textareacode.escapeHTML());
	}else{
		alert('Je hebt geen text ingevuld');
	}
}

function copy(text2copy) {
  text2copy = text2copy.unescapeHTML();
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
	new showPopup($('copied'));
	setTimeout(function(){ hidePopup($('copied')); }, '2500');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
	new showPopup($('copied'));
	setTimeout(function(){ hidePopup($('copied')); }, '2500');
  }
}

function showUitleg(){
	showPopup($('uitleg'));	
}

function hideUitleg(){
	hidePopup($('uitleg'));	
}

function showPopup(element){
	setInterval(function(){ centerPopup(element); }, '100');
	new Effect.Appear(element, {queue: 'end', from: '0.0', to: '0.9', duration: '1'});
}

function hidePopup(element){
	new Effect.Fade(element, {queue: 'end', from: '0.9', to: '0.0', duration: '1'});
}

function centerPopup(element){
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	element.style.top = Math.round((viewportheight / 2) - (element.style.height / 2) + document.documentElement.scrollTop) + 'px';

}

function bookmark(title, url){
	urchinTracker ('/addtofavorites/');
	if (document.all){
		window.external.AddFavorite(url, title);
	}
	else if (window.sidebar){
		window.sidebar.addPanel(title, url, '');
	}
}