(function($) {
	/**
	 * Some functions for the website
	 */
	$.fn.toggleDefaultValue = function(defaultValue) {
		$(this).val(defaultValue);
		$(this).focus(function() {
			if ($(this).val() == defaultValue)
				$(this).val('');
		})
		$(this).blur(function() {
			if ($(this).val() == '')
				$(this).val(defaultValue);
		})
	}

	$.fn.replaceStartsiteProjects = function() {
		if ($(this).attr('src')) {
			$.get($(this).attr('src'), {
				layout: 'noframe'
			}, function(projectHTML) {
				if (projectHTML != '')
					$('div#latestWork').html(projectHTML);
			});
		}
	}

	$.fn.replaceTeaserProjects = function() {
		if ($(this).attr('src')) {
			$.get($(this).attr('src'), {
				layout: 'noframe'
			}, function(projectHTML) {
				if (projectHTML != '')
					$('div#referenceWork').html(projectHTML);
			});
		}
	}

	/**
	 * Some functions for the projecttool / references
	 */
	$.fn.pagePrev = function () {
		$(this).click(function () {
			$('#referencelistPage').val(parseInt($('#referencelistPage').val()) - 1);
			$('#referencelistForm').submit();
		});
	}

	$.fn.pageNext = function () {
		$(this).click(function () {
			$('#referencelistPage').val(parseInt($('#referencelistPage').val()) + 1);
			$('#referencelistForm').submit();
		});
	}

	$.fn.resetPage = function () {
		$(this).click(function () {
			$('#referencelistPage').val(1);
		});
	}

	$.fn.selectPage = function () {
		$(this).click(function () {
			$('#referencelistPage').val($(this).html());
			$('#referencelistForm').submit();
		});
	};

	$.fn.switchImage = function () {
		$(this).click(function () {
			// Change the image
			$('#pictureWorkBig').attr('src', $(this).attr('href'));

			// Change the active thumbnail
			$('.pictureNavigation a').removeClass('active');
			$(this).addClass('active');

			// Prevent default-link
			return false;
		});
	};
})(jQuery);


jQuery(document).ready(function ($) {
	/**
	 * This part is for the website
	 */
	var width = $("#search").width();
	$("#search").css({
		width:0,
		overflow:'hidden',
		whiteSpace:'nowrap'
	});
	$('#ss').hide();
	$(".btn-slide").click(function() {
		var $$ = $(this);
		var srch = $('#search');

		//$("#search").slideToggle("fast");
		if ($$.hasClass('active')) {
			$('#ss').hide();
			srch.animate({
				width: 0
			}, 'fast', function() {
				srch.hide();
			});
		} else {
			srch.show().animate({
				width: width
			}, 'fast', function() {
				$('#ss').show();
			});
		}
		$$.toggleClass("active");
		return false;
	});

	$('form#tx_indexedsearch input[name="tx_indexedsearch[sword]"]').toggleDefaultValue(searchText);


	/**
	 * This part is for the projecttool
	 */
	$('input[type=checkbox],input[type=radio]').prettyCheckboxes({
		checkboxWidth: 12, // The width of your custom checkbox
		checkboxHeight: 12, // The height of your custom checkbox
		className : 'prettyCheckbox', // The classname of your custom checkbox
		display: 'list' // The style you want it to be display (inline or list)
	});

//	$('#workPages a').selectPage();
//	$('#referencelistForm input[type=checkbox]').resetPage();
	$('.pictureNavigation a').switchImage();
	$('.pictureNavigation a:first').addClass('active');

	$('div.workFilterLegend div.workFilterHeading').click(function() {
		$('div.workFilterLegend div.workFilterEntry').slideToggle();
	})

	$('div#workFilter').click(function() {
		$(this).toggleClass('open');
		$('div#workFilterContent').slideToggle();
	})
});

