$(function() {
	$('#feature').flexslider({
		animation: 'slide',
		controlsContainer: '.slider-nav',
		slideshowSpeed: 8000
	});

	if($().fancybox){
		$(".fancybox").fancybox();
	}

	/* Setup links that automatically popup in a new window */
	$('a[rel=external]').live('click', function() {
		window.open($(this).attr('href'));
		return false;
	});

	if(!Modernizr.input.placeholder) {
		$('[placeholder]').focus(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
		}).blur(function() {
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
		}).blur();
	}

	// Tooltips for processes stuff
	if($().qtip){
		$('.tip').each(function() {
			var ele  = $(this),
				title = typeof ele.attr('oldtitle') == 'undefined' ? ele.attr('title') : ele.attr('oldtitle'),
				twin = $('[title="'+title+'"]').not(ele).length > 0 ? $('[title="'+title+'"]').not(ele) : $('[oldtitle="'+title+'"]').not(ele); // get all elements with same title except self

			ele.qtip({
				content: '<h2>'+ele.attr('title')+'</h2>'+ele.attr('alt'),
				position: {
					my: 'bottom left',
					at: 'top right'
				}
			});

			ele.mouseover(function() {
				twin.qtip('disable');
				twin.each(function() {
					if(this.tagName === 'AREA') {
						twin.trigger('mouseover.maphilight');
					}else{
						twin.addClass('hover');
					}
				})
			}).mouseout(function() {
				twin.qtip('enable');
				twin.each(function() {
					if(this.tagName === 'AREA') {
						twin.trigger('mouseout.maphilight');
					}else{
						twin.removeClass('hover');
					}
				})
			})
		});
	}
});
