jQuery(function($){//document ready
	
	//Searchbox on top
	var searchVisible = $.cookie('search_visible') == 'true';
	var searchBox = $('#searchbox');
	var searchBoxTrigger = $('#searchboxtrigger');

    if (searchVisible) {
        searchBox.show();
		$('#searchboxtrigger .closer').show();
		//console.debug($.cookie('search_visible'));
    } else { 
        searchBox.hide();
		$('#searchboxtrigger .closer').hide();
		//console.debug($.cookie('search_visible'));
    }

    searchBoxTrigger.click(function() {
        if (searchVisible) {
            searchBox.slideUp('fast');
			$('.closer', this).hide();
            $.cookie('search_visible', null);
            searchVisible = false;
			//console.debug($.cookie('search_visible'));
        } else {
            searchBox.slideDown('fast');
			$('.closer', this).show();
            $.cookie('search_visible', 'true');
            searchVisible = true;
			//console.debug($.cookie('search_visible'));
        } 
        return false;
    });
	
	
	//Searchbox on top
	/*$('#searchboxtrigger').click( function() {
	    if($.cookie('search_visible') == 'true') {
	       	$('#searchbox').slideUp('fast');
			$('#searchboxtrigger .closer').hide();
			$.cookie('search_visible', null);
			//console.debug('is hidden');
	    } else {
	       	$('#searchbox').slideDown('fast');
			$('#searchboxtrigger .closer').show();
			$.cookie('search_visible', 'true');
			//console.debug('is visible');
	    } 
	});*/
	
	//Label inside of inputfields
	function insidelabel(selector, name) {
		$(selector).val(name);
		$(selector).css({'color':'#999'});
		
		$(selector).focus(function () {
			//Input Value
			if ($(this).val() == name) { $(this).val(''); }
			$(this).css({'color':'#000'})
		});
		
		/*$(selector).focus(function () {
			if ($(this).val() == name) {
				$(this).css({'color':'#ccc'});
				setCursorPosition($(this),0);
			}
		});
		
		$(selector).keypress(function() {
			if ($(this).val() == name) { $(this).val(''); }
			$(this).css({'color':'#000'});
		});*/
		
		$(selector).blur(function () {
			if ($(this).val() == '') { $(this).val(name); }
			if ($(this).val() == name) {
				$(this).css({'color':'#999'});
			}
		});
	}
	
	insidelabel(".s", "suche…");
	insidelabel("#author", "name");
	insidelabel("#email", "e-mail");
	insidelabel("#url", "webseite");
	insidelabel("#subject", "betreff");
	insidelabel("#comment", "kommentar");
	insidelabel(".contact", "anfrage");
	
	//remove width of image caption
	$(".wp-caption").each(function() {
        $(this).removeAttr("style");
    });

	//Contentarea Linkstyles for Images
	$(function() {
		$("a img").each(function() {
			$(this).parent().addClass("image");			
		});
	});
	
	//Remove preview if post is viewed of the same category
	$(function() {
		$('[id^=post-full]').each(function() {
			var num = $(this).attr('id').replace(/post\-full\-/,'');
			//$('#post-' + num).hide();
			$('#post-' + num).remove();
	    });
	});
	
	var si = $('#post-full');
	var swh;
	//collapse single-wrapper
	$('.collapse').click(function() {
		swh = si.height();
        si.animate({
		    height: '20px'
		}, 500, function() {
			$('.cattag').hide();
			$('.expand').fadeIn('fast');
		});
		$('#post-full .post-body').fadeOut('500');
		$(this).fadeOut('500');
    });
	//expand single-wrapper
	$('.expand').click(function() {
		$('#post-full .post-body').fadeIn('500');
        si.animate({
		    height: swh + 'px'
		}, 500, function() {
			$('.cattag').show();
			$('.collapse').fadeIn('fast');
		});
		$(this).fadeOut('500');
    });
	
	$(window).resize(function() {
		if ( $(window).width() < 665 ) {
			$('#topinfo').css('padding-top', '20px');
		} else {
			$('#topinfo').css('padding-top', '0px');
		}
	});

});//document ready
