(function($) {
	
	$.fn.addShadow = function(options) {
		
		var options = $.extend({
			element : 'span',
			className : 'shadow'
		}, options);
		
		return this.each(function() {
			var $this = $(this);
			$('<' + options.element + '/>')
				.attr('class', options.className)
				.html($this.html())
				.appendTo($this);
		});
	};
	
})(jQuery);

$(function() {

	$('#navigation span.button').addShadow();
	
	var nav = $('#wzNavigation');
	if(nav.length){
		nav.insertBefore($('#right').children().eq(0));
	};
		
	var item = $('#company');
	
	// Frontpage
	if(window.location.pathname == '/') {

		var blocks = $('.neighbourhood-item, .block.city');
		if(blocks.length) {
			blocks.remove();
		};
	
	// Item
	} else if(item.length) {
		
		var search = $('#companyLocationSearch');
		if(search.length) {
			item.prependTo(item.parent());
		};
		
	// City
	} else {
		
		var blocks = $('.neighbourhood-item, .block.city');
		blocks.each(function() {
			var blockItems = $(this).find('li');
			if(blockItems.length > 10) {
				blockItems.slice(10).remove();
			};
		});
		
		var search = $('#companyLocationSearch');
		if(search.length) {
			var parent = search.parent();
			search.remove();
			search.insertAfter(parent.children('div:first'));
		};
		
	};
	
	$('#main .inner-wide').masonry({
		columnWidth: 10,
		itemSelector: '.block, #frame_controller'
	});
	
	var counter = 0;
	$('.block').each(function() {
		var el = $(this);
		el.find('h2').addClass('heading' + counter);
		counter == 3 ? counter = 0 : counter++;
		el.bind({
			'mouseover' : function() {
				el.addClass('hover');
			},
			'mouseout' : function() {
				el.removeClass('hover');
			}
		});
	});
	
	$('#navigation > li').menu({
		dropdown : 'ul',
		activeClass : 'active',
		ignoreDummy : true
	});
	
	$('form input[type=text]').focus();
	
});
