
jQuery(document).ready(function() {	

	// *** comment ***
	// hide/show comments
	jQuery('#commentform').hide();

	// append link to #postcomment
	var t = jQuery('#postcomment').text();
	jQuery('#postcomment').html('<a href="#" id="postcomment-link" title="Formular anzeigen/verbergen">'+t+'</a>');
	jQuery('#postcomment').addClass('no-line');
	
	// toggle
	jQuery('#postcomment-link').click(function(e) {
		
		jQuery('#commentform').slideToggle( function(){
			jQuery('#commentform:visible').parent().find('#postcomment').removeClass('no-line');
			jQuery('#commentform:hidden').parent().find('#postcomment').addClass('no-line');
			
		});
		jQuery(this).blur(); /* ff seems to have probs loosing focus otherwise */
		e.preventDefault();
		return false;
	});
	// append link to #comments
	var t = jQuery('#comments').text();
	jQuery('#comments').html('<a href="#" id="comments-link" title="Kommentare anzeigen/verbergen">'+t+'</a>');
	//jQuery('#comments').addClass('no-line');
	
	// toggle
	jQuery('#comments-link').click(function(e) {
		
		jQuery('#commentlist').slideToggle( function(){
			jQuery('#commentlist:visible').parent().find('#comments').removeClass('no-line');
			jQuery('#commentlist:hidden').parent().find('#comments').addClass('no-line');
			
		});
		jQuery(this).blur(); /* ff seems to have probs loosing focus otherwise */
		e.preventDefault();
		return false;
	});


	// *** cast ***
	// wrap content in container (without headline -> slice )
	jQuery('.page-crew .pagecontent>ul>li').each( function(){
		jQuery(this).children().slice(1).wrapAll('<div class="details"></div>');
	});
	
	// hide/show
	jQuery('.page-crew .details').hide();
	jQuery('.page-crew .details').addClass('no-bg');
	
	// append link to parent h4
	jQuery('.page-crew h4').addClass('clear');

  	// rearrange html
	jQuery('.page-crew h4').each( function(i){	
  		var t2 = jQuery(this).find('span').html();
		jQuery(this).find('span').remove().html();
		var t1 = jQuery(this).html();
		jQuery(this).html('<span class="col-1">'+t1+'</span> <span class="col-2">'+t2+'</span>');
	});
	// add link if has detail
	jQuery('.page-crew .details').parent().find('h4').each( function(i){
		var t = jQuery(this).find('.col-2').html();
		jQuery(this).find('.col-2').html('<a href="#" class="more-link" title="Details anzeigen/verbergen">'+t+' <span class="label">Details anzeigen</span></a></span>');

	});


	// toggle
	jQuery('.page-crew a.more-link').click( function(e){
		jQuery(this).parent().parent().parent().find('.details').addClass('no-bg'); // remove bg while movement
		jQuery(this).parent().parent().parent().find('.details').slideToggle( function(){
			jQuery('.details:visible').removeClass('no-bg');
			// hints
			jQuery('.details:visible').parent().find('.label').text('Details verbergen');
			jQuery('.details:hidden').parent().find('.label').text('Details anzeigen');
		});
		jQuery(this).blur(); /* ff seems to have probs loosing focus otherwise */
		e.preventDefault();
		return false;
	});
	
	
	
	// *** shaddow ***
	if( jQuery.browser.msie && jQuery.browser.version < 7 ){	 // pngfix cant be used as background-position will be lost
		jQuery('.imageframe').wrap('<div class="clear ds2"></div>');
	} else {
		jQuery('.imageframe').wrap('<div class="clear ds1"></div>');
	}
	jQuery('.storycontent p').addClass('clear');
	
	
	
	// *** anchor navigation ***
	var a = '';
	jQuery('.jump-nav .pagecontent h3').each( function(i){
		jQuery(this).attr('id','jump-'+i);
		a += '<li><a href="#jump-'+i+'">'+jQuery(this).text()+'</a></li>'; 
	});
	if( a != '' ){
		jQuery('h2.storytitle').after('<ul class="jump-nav">'+a+'</ul>');
	}


	// *** list styles ***
	jQuery('li:last-child').addClass('last-child');


	// *** add clear to gallery ***
	jQuery('.gallery p').addClass('clear');

});

