$(function(){
	$('#filter .filter_box').each(function() {
		// check more than 4 items
		if($('li', this).length > 4) {
			// hide list elements > 4 items
			$('li:gt(3)', this).addClass('hide_true');
			$(this).append('<p class="show_more"><a href="#" title="Show more item above">Show more</a></p>');

			// bind event to more link
			$('.show_more a', this).bind("click", function() {
				if($(this).text() == "Show more") {
					$(this).text('Show less');
					$(this).parents('.filter_box').find('li').removeClass('hide_true');
					$(this).parent().removeClass('show_more').addClass('show_fewer');
				} else {
					$(this).text('Show more');
					$(this).parents('.filter_box').find('li:gt(3)').addClass('hide_true');
					$(this).parent().removeClass('show_fewer').addClass('show_more');
				}
				return false;
			});
		}
	});
});

// Search function which allows the show more show less option to be

$(function(){
	// function for the show/hide the options for advanced search
	var moreless = $('.searchcontainer fieldset')
		.append('<div class="moreless"><span>Show more</span></div>');

	var refinesearch = $('.searchcontainer .refinesearch').hide();
	
	$('.searchcontainer .moreless span')
		.css('cursor','pointer')
		.addClass('showmore');

	$('.searchcontainer .moreless span').click(function(){
		if($(refinesearch).is(":hidden")) {
			$(this)
				.text('Show less')
				.removeClass('showmore')
				.addClass('showless')
			$(refinesearch).show();
		}
		else {
			$(this)
				.text('Show more')
				.removeClass('showless')
				.addClass('showmore')
			$(refinesearch).hide();
		};
	});
	
	// functions for text placeholder	
	$('.searchcontainer :input#searchKeyword').each(function(){
		var placeholder = $(this).val();
		$(this).val(placeholder).focus(function(){
			if(this.value == placeholder) {
				$(this).val('')
			};
		}).blur(function(){
			if(this.value == '') {
				$(this).val(placeholder);
			};
		});
	});
	
});
