function hashgrid(){
	var grid = new hashgrid({
		numberOfGrids: '2'
	});
}
function pageLayout(){
	$('#pagecontent').masonry({
		columnWidth: 110,
		columnWidth: 60,
		resizeable: false,
		itemSelector: '.pagepost:not(.pagehidden)',
		animate: true
	});
}

//quicksorting categories
function pageDisplay(){
	var speed = 500;
	$('#contentcontrol p').click(function(){
	    var contentClass = '.' + $(this).attr('class');

	    if(contentClass=='.all') {
	        // show all hidden boxes
	        $('#pagecontent').children('.pagehidden')
	            .toggleClass('pagehidden').animate({opacity: 1},{ duration: speed });
	    } else {
	        // hide visible boxes
	        $('#pagecontent').children().not(contentClass).not('.pagehidden')
	            .toggleClass('pagehidden').animate({opacity: 0},{ duration: speed });
	        // show hidden boxes
	        $('#pagecontent').children(contentClass+'.pagehidden')
	            .toggleClass('pagehidden').animate({opacity: 1},{ duration: speed });
	    }
			//console.log('vor dem callback');
			pageLayout();
			//console.log('nach dem callback');
	    return false;
	});
}

//slide smoothly to top of page
function anchorSlide(){
	$('#footer').mouseenter(function(){
		$('.top').stop().animate({top: '-30px'}, 300);
	})
	$('#footer').mouseleave(function(){
		$('.top').stop().animate({top: '0px'}, 300);
	})
  $('.top').click(function() {
		$(document).scrollTo(0,500);
	});
}
//function auf artikel legen damit
//per custom field die felder angelegt werden können
function textColumns(){
	$('#article').columnize({
  	columns: 3,
		lastNeverTallest: true,
		doneFunc: function(){
			$('#article .article-content').removeClass('hiddentext');
		}
  });
}
function textColumns_1(){
	$('.article-content').removeClass('hiddentext');
}
function textColumns_2(){
	$('#article2').columnize({
  	columns: 2,
		lastNeverTallest: true,
		doneFunc: function(){
			$('.article-content').removeClass('hiddentext');
		}
  });
}
function textColumns_3(){
	$('#article3').columnize({
  	columns: 3,
		lastNeverTallest: true,
		doneFunc: function(){
			$('.article-content').removeClass('hiddentext');
		}
  });
}
function textColumns_4(){
	$('#article4').columnize({
  	columns: 4,
		lastNeverTallest: true,
		doneFunc: function(){
			$('.article-content').removeClass('hiddentext');
		}
  });
}
function headershow1(){
	$('#headershow').nivoSlider({
		effect: 'sliceUpDownLeft',
		slices: 10,
		pauseTime:5000,
		controlNav:false,
		animSpeed:800
	})
}
function headershow(){
	 simpleSlide({
	 		'set_speed': 300,
			'status_color_outside': '#aaa',
			'status_color_inside': '#fff',
			'swipe': 'true',
		});
		/*
		 * autoplay feature
		$('.simpleSlide-window').each( function() {
    	var related_group = $(this).attr('rel');
    	window.setInterval("simpleSlideAction('.right-button', " + related_group + ");", 6000);
		});
		$('.slideshow').live('mouseover mouseout',
        function(event) {
            if(event.type == 'mouseover'){
                $(this).children('.left-button, .right-button').stop(true, true).fadeIn();
            }
            else {
                $(this).children('.left-button, .right-button').stop(true, true).fadeOut();
            }
        }
    );
		*/
}

function footershow(){
	 simpleSlide({
	 		'set_speed': 300,
			'status_color_outside': '#aaa',
			'status_color_inside': '#fff',
			'swipe': 'true',
		});
}

//font replacement
function dfr(){
		Cufon.set('fontFamily', 'League Gothic').set('letterSpacing', '0px').set('fontWeight', '900').set('fontStretch', '140%').set('textShadow', '1px 1px 1px #EEEEEE');
		Cufon.replace('h3').replace('#branding h1').replace('.post h3').replace('.slideshow h3').replace('h2');
}


function pagination(){
    $('#pagination a').live('click', function(e){
      e.preventDefault();
      $(this).addClass('loading').text('LOADING...');
      $.ajax({
          type: "GET",
          url: $(this).attr('href') + '#pagecontent',
          dataType: "html",
          success: function(out){
              result = $(out).find('#pagecontent .pagepost');
							result.addClass('newcontent');
              nextlink = $(out).find('#pagination a').attr('href');
              $('#pagecontent').append(result.fadeIn(300));
              $('#pagination a').removeClass('loading').text('NOCH MEHR?');
              if (nextlink != undefined) {
                  $('#pagination a').attr('href', nextlink);
              } else {
                  $('#pagination a').remove();
									$('#pagination p').removeClass('hidden');
              }
							pageLayout();
							dfr();
          }
      });
  });
}

function comments(){
	$('#commentbutton').click(function(){
		$('#comments').slideToggle();
	})
}

jQuery(document).ready(function(){
	hashgrid();
	pageLayout();
	pageDisplay();
	textColumns();
	textColumns_4();
	textColumns_3();
	textColumns_2();
	textColumns_1();
	anchorSlide();
	headershow();
	dfr();
	pagination();
	comments();
});


