$(document).ready(function(){

	if($(".tx-historyview-pi1").children('div').hasClass('single')){
		$('.langmenu').hide();
	} else {
		$('.langmenu').show();
	}

	//themebox frontpage

        $(".html-element").each(function(){
		var elm = $(this);
		//console.log(elm.children().length);
		if(elm.children().length > 0){
			elm.prev().hide();
		} else {
			elm.hide();
		}
	});	

	$('.themebox').each(function(){
		$(this).find('.theme:first').show()
		
		//build list
		
		$(this).children('.theme').each(function(i){
			//build list item
			liitem = '<li><a href="'+ $(this).find('a').attr('href') +'"><span class="holder"><img width="139" height="77" alt="" src="'+ $(this).find('img').attr('src') +'"><span class="overlay">'+ $(this).find('.type').text() +'</span></span><span class="description">'+ $(this).find('.description h3').text()+'</span></a></li>';
			$(this).parent().find('.themelist ul').append(liitem);
		})
		
				
		$(this).find('.themelist li:first').addClass('active');
		
		//click in list
		$(this).find('.themelist li').each(function(i){
			$(this).children('a').click(function(){
				$(this).parents('.themebox').find('.theme').hide();
				$(this).parents('.themebox').find('.theme').eq(i).show()
				$(this).parent().parent().children('li').removeClass('active');
				$(this).parent().addClass('active');
				return false;
			});
		});
			
	});
	
	
	
	//searchbox focus
	
	$("#header .header-holder input:text").each(function(){
		var ov = $(this).val();
		
		$(this).focus(function(){
			var fv = $(this).val();
			if (fv == ov) {
  				$(this).val('');
  			}
		});
	
		$(this).blur(function(){
			var bv = $(this).val();
  			if (bv.length < 1) {
  				$(this).val(ov);
  			}
		});
	});
	
	$(".hidelabel input:text").each(function(){
		//var ov = $(this).val();
		
		$(this).focus(function(){
			$(this).prev('label').hide();
		});
	
		$(this).blur(function(){
			var bv = jQuery(this).val();
  			if (bv.length < 1) {
  				$(this).prev('label').show();
  			}
		});
	});
	
// Scale images in databaseelements
	$('.content img').each(function(){
		var img = $(this);
		if(img.width() > 597){
			img.jScale({w:'597px'});
		}
	});
		
		// pdf link
		var href = $('#content a.single_pdf').attr('href');
		if (href) $('#sidebar a.pdf').attr('href', href);
		
		
		
});
