$(document).ready(function(){


	/**
	 * facebook like box
	 */

	//$('#fb-like-box').html('<fb:like-box href="http://www.facebook.com/pages/Dr-Ing-Meywald-GmbH-Co-KG/124588057619906" width="214" height="240" colorscheme="light" show_faces="true" stream="false" header="false" border_color="#ffffff"></fb:like-box>');


	/**
	 * Tooltips
	 * based on jquery.qtips
	 */

	/*
	$('a[title]').qtip({
		position: {
			my: 'bottom left',
			target: 'mouse',
      adjust: {
				x: 5,
				y: -3
      }
		},
		style: {
			classes: 'ui-tooltip-blue ui-tooltip-rounded ui-tooltip-shadow'
		}
	});
	*/


	/**
	 * Image slider (home page)
	 */

	$('.slide-item', '#divisions').hover(
	  function(){
			$(this)
				// cover opacity
				.find('.slide-cover').css('background-color', '#3a4e86').fadeTo(100, 0.93).end()
				// show description
				.find('.slide-description').slideDown(100);
	  },
	  function(){
			$(this)
				// cover opacity
				.find('.slide-cover').css('background-color', '#555860').fadeTo(500, 0.6).end()
				// show description
				.find('.slide-description').slideUp(500);
	  }
	)


	/**
	 * lightbox
	 * based on jquery.fancybox
	 */

	$('a[rel="lightbox"]').fancybox({
		'overlayColor'   : '#333',
		'overlayOpacity' : 0.7,
		'centerOnScroll' : true,
		'transitionIn'   : 'elastic',
		'transitionOut'  : 'elastic',
		'titlePosition'  : 'inside',
		'speedIn'        : 200, 
		'speedOut'       : 100
	});


	/**
	 * search field
	 * clear on focus, replace with default on blur
	 */

	$.fn.search = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	$("#searchfield").search();


	/**
	 * external links
	 *
	 * filters href != hostname or rel="external"
	 * adds .external to elements not containing img, div or mailto
	 * opens external links in new window/tab
	 */

	$('a, area').filter(function() {
		return this.hostname && (this.hostname).split(":")[0] !== (location.hostname).split(":")[0] || $(this).attr('rel') == 'external';
	})
	.not(':has(img, div, mailto)')
	.addClass('external')
	.end()
	.click(function(e) {
		open(this.href); 
		e.preventDefault();
	});


});
