$(document).ready(function(){


	/* External links
	------------------------------------------------------------- */
	$('a').each(function() {
	
		var href = $(this).attr('href');
	  
		// kludgy
		domain = location.hostname;	// current domain
		domain = domain.split('.');
		domain.shift(); // remove subdomain
		domain = domain.join('.');

		// console.log(location.hostname);	  
		// console.log(domain);
				
		if (this.hostname && this.hostname !== location.hostname && this.hostname.indexOf(domain) == -1)
		{
    	$(this)
    		.removeAttr('target')
    		.attr('rel', 'external')	    		
        .attr('title', href)
        .click(function() {
           window.open($(this).attr('href'));
           return false;
       });
		}
  
	});
	
	$('a > img').each(function() {		
		$(this).parents('a').addClass('image-link');		
	});
		

	/* Layout fixes
	------------------------------------------------------------- */
	$('#footer, .section, .block, .widget, .teaser, .showcase-pager, .list, #color-guide').addClass('clear');

	$('.section, .block .body').each(function() {
		$(this).children('.column:first').addClass('first');
		$(this).children('.column:last').addClass('last');
	});
	$('.list').each(function() {
		$(this).children('.teaser:last').addClass('last');
	});
	$('.nav-sub').each(function() {
		$(this).children('li:last').addClass('last');
	});
  	$('#nav-main li.parent:last').addClass('last');

	// if ( $('a.more').html() == '' )
	// {
	// 	$('a.more').html('&nbsp;');		
	// }




	/* Convert image to background image (for round corner images)
	------------------------------------------------------------- */
	$('.cycle .slide, .widget.cap').each(function() {
		var src = $(this).children('.image').children('img').attr('src');
		// console.log(src);
		$(this).css('background-image', 'url(' + src + ')');
		$(this).children('.image').hide();
	});

	
	$('.project .image').each(function() {
		var src = $(this).children('a').children('img').attr('src');
		// console.log(src);
		$(this).css('background-image', 'url(' + src + ')');
		$(this).children('a').children('img').hide();
	});
	
	$('.flickr-image, [class*=wp-image]').each(function() {			
		$(this).wrap('<span class="image-box"></span>');		
	});

	$('.image-box').each(function() {
		
		box = $(this);
		img = box.find('img');		
		link = box.find('a');
		src = img.attr('src');
		
		box.css('background-image', 'url(' + src + ')');				
		
		img.hide();

		w = img.width();
		h = img.height();
		
		box.width(w);		
		box.height(h);
					
		if (link != 'undefined')
		{
			link.width(w);
			link.height(h);
		}
		
	});
	



	/* Show / hide guide elements
	------------------------------------------------------------- */
	$('#show-sections').click(function(event){
		$('.section').toggleClass('guide');
		$(this).toggleText('Show Sections', 'Hide Sections');
		return false;
	});
	$('#show-columns').click(function(event){
		$('.column').toggleClass('guide');
		$(this).toggleText('Show Columns', 'Hide Columns');		
		return false;
	});
	$('#show-blocks').click(function(event){
		$('.block').toggleClass('guide');
		$(this).toggleText('Show Blocks', 'Hide Blocks');		
		return false;
	});

	
	

		
	/* Cycle widget slideshow
	------------------------------------------------------------- */
	$('.cycle .slideshow').cycle({ 
		timeout: 	7000, 		
		speed: 		600,
		// fx:     	'scrollHorz', 
		fx: 			'fade',
    easing: 	'easeInOutSine',		
		pager:  	'.pager'				
	});

	
	/* Cycle exhibition slideshow
	------------------------------------------------------------- */
	$('.cycle .slideshow-half').cycle({ 
		timeout: 	7000, 		
		speed: 		600,
		// fx:     	'scrollHorz', 
		fx: 			'fade',
   		easing: 	'easeInOutSine',
		pager: '.pager'
	});

	
	
	/* Misc
	------------------------------------------------------------- */
	$('a.print').click( function() { window.print(); });
	
	$('iframe').hide();

	
  /* Press PDF links
  ------------------------------------------------------------- */
  $("a:contains('Lesen Sie mehr')").addClass('more');
	$("a:contains('(weiterlesen…)')").addClass('more-link');
	$("a:contains('Read more')").addClass('more');
	
});
