$(document).ready(function() {
	

	$('.jFollowlink').bind('click', function() {
		window.location.href = $(this).find('a').attr('href');
	});	
	
	
	$('form#sidebar_search').submit(function() {
		var input = $(this).find('input[name=query]').val();
		window.location.href = $(this).attr('action').replace('QUERY', encodeURI(input));
		return false;
	});
	
	
	$('ul#mainnavigation li.clickable').click(function() {
		//window.location.href = $(this).find('a').attr('href');
	});

	
	$('img.jImgHover').mouseenter(function() {
		$(this).attr('src', $(this).attr('src').replace('.','_hover.') ); 
	});

	
	$('img.jImgHover').mouseleave(function() {
		$(this).attr('src', $(this).attr('src').replace('_hover.','.') ); 
	});
	
	/*
	hash = $(document).attr('location').hash;
	if (hash!='') {
		$(document).attr('location').href = hash.replace('#', '');
	}
	*/
	
	$('div.fbshare').live('click', function() {
		var url = $(this).find('a').attr('href');
		popup(url, 700, 400);
		return false;
	});
	
	
	$('select.sb, select.sbsmall, select.sbmini, select.sbwide').selectBox();
	
	
	$('ul.jCarouselCircular').jcarousel({wrap: 'circular'});
	
	
	$('div.coda-slider').codaSlider({
		autoSlide: true,
		autoSlideInterval: 5000,
		autoHeight: true,
		carousel: true,
		crossLinking: false,
		dynamicArrows: false,
		dynamicTabs: true,
		dynamicTabsAlign: 'right'
	});
	
	
});



function number_format (number, decimals, dec_point, thousands_sep) {
	var n = number, prec = decimals;

	var toFixedFix = function (n,prec) {
		var k = Math.pow(10,prec);
		return (Math.round(n*k)/k).toString();
	};
 
	n = !isFinite(+n) ? 0 : +n;
	prec = !isFinite(+prec) ? 0 : Math.abs(prec);
	var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
	var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;

	var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec);
	var abs = toFixedFix(Math.abs(n), prec);
	var _, i;

	if (abs >= 1000) {
		_ = abs.split(/\D/);
		i = _[0].length % 3 || 3;
		_[0] = s.slice(0,i + (n < 0)) +
		_[0].slice(i).replace(/(\d{3})/g, sep+'$1');
		s = _.join(dec);
	} else {
		s = s.replace('.', dec);
	}

	var decPos = s.indexOf(dec);
	if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {

		s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
	} else if (prec >= 1 && decPos === -1) {
		s += dec+new Array(prec).join(0)+'0';
	}
	return s;
}



function popup(url, width, height) {
	var opener = window.open(url, 'opener1', 'width='+width+',height='+height+',status=yes,scrollbars=yes,resizable=no');
	opener.focus();
}



function ekomirandom(id, holder) {
	var rand = Math.floor(Math.random()*10)
	var rand = (rand==0) ? 1 : rand;
	$('img#'+holder).attr('src', 'https://connect.ekomi.de/widget/'+id+'-'+rand+'.gif');
	setTimeout("ekomirandom('"+id+"', '"+holder+"')", 3000);
}



function noticebox(html, showclosebutton) {
	var height = $(document).height();
	$('div#noticebox_background').css({'opacity':'0.5', 'height':height}).toggle();
	$('div#noticebox_box').find('div.html').html(html);
	if (showclosebutton==false) { $('div#noticebox_box').find('div.close').hide(); } else { $('div#noticebox_box').find('div.close').show(); }
	$('div#noticebox_box').toggle();
}



function noticebox_content(html) {
	$('div#noticebox_box').find('div.html').html(html);
}



