/*
 * Stand Up Initiative
 * http://www.stand-up-initiative.de
 *
 * Date: 2011-10
 * Author: Gedankengut.de
 */
 
$(window).load(function(){ extLinkTarget(); });
 
$(document).ready(function(){

	extLinkTarget();
	
	/////
	// IMAGE FADER
	/////
	$('.image-rotate').not('.speed-slow').innerfade({
		speed: 'slow',
		timeout: 5000,
		type: 'sequence'
	});
	$('.image-rotate.speed-slow').innerfade({
		speed: 'slow',
		timeout: 7000,
		type: 'sequence'
	});

    /////
	// GOOGLE +1
	/////		
	window.___gcfg = {lang: 'de'};
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	
	/////
	// EMAIL DECODER
	/////
	$('.encHref').each(function(){
		var strHref = $(this).attr('href');
		$(this).attr('href',rot13(strHref));
	});
	
	$('.encHtml').each(function(){
		$(this).html( rot13( $(this).html() ) );
	});
	
	/////
	// TOOLTIP
	/////
	$('.tip').qtip({
		style: {
			classes: 'ui-tooltip-rounded ui-tooltip-cluetip ui-tooltip-shadow'
		},
		position: {
			my: 'top left',
			at: 'center'
		}
	});

	/////
	// MORE-LINK STATEMENTS
	/////
	$('.promi-details').each(function(){
		var refBox = $(this);
		$('.js-more-link',this).click(function(e){
			e.preventDefault();
			var diffText = $(this).attr('title');
			$('cite span.js-more',refBox).html(diffText);
			$(this).remove();
		});
	});
	
});


/////
// TARGET BLANK
/////
function extLinkTarget(){
	$('.content-wrap a').filter(function(){
		return ($(this).attr("target") != "_blank" && this.hostname && this.hostname != location.hostname);
	}).attr("target","_blank");
}
   
/////
// ENCODE ROT13
/////
function rot13(strEnc){
	var keycode	= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var text = strEnc;
	var textrot	= new String();
	for(var i = 0; i < text.length; i++){
		var codechar = text.substring(i, i + 1);
		var pos = keycode.indexOf(codechar.toUpperCase());
		if(pos >= 0){
			pos = (pos + keycode.length / 2) % keycode.length;
			codechar = (codechar == codechar.toUpperCase()) ? keycode.substring(pos, pos + 1) : keycode.substring(pos, pos + 1).toLowerCase();
		}
		textrot	= textrot + codechar;
	}
	return textrot;
}
