$(function(){

	// Setup font resizer
	$('#layer-body').fontresizer({excluded: '#layer-menu-main'});
	
	// Initialise collapsible toggle 				
	$('a.toggle-item').click(function(){
		if($(this).hasClass('collapse')) {
			$(this).removeClass('collapse');
			$('#'+$(this).attr('rel')).show();
			// Toggle Hide/Show wordings
			$('span.expand', this).hide();	
			$('span.collapse', this).show();
			$('#layer-page-footer').attr("style","height:240px");
			
		} else {
			$(this).addClass('collapse');
			$('#'+$(this).attr('rel')).hide();
			// Toggle Hide/Show wordings
			$('span.expand', this).show();	
			$('span.collapse', this).hide();
			$('#layer-page-footer').attr("style","height:30px");
		}		
		return false;
	});		
	// Hide default wordings 
	$('a.toggle-item').each(function(){
		var toggleItem = $('#'+$(this).attr('rel'));
		if(toggleItem.hasClass('hidden')){
			toggleItem.removeClass('hidden');
			
			$(this).addClass('collapse');
			toggleItem.hide();
			$('span.collapse', this).hide();
		}
		else {
			
			$('span.expand', this).hide();
		}
	});	
	
		
	// pullquote functions
	$('span.pullquote-left').each(function() {
		var parentTag = $(this).parent();
		var newNode = $('<blockquote class="pulledquote"></blockquote>');
		
		$(this).removeClass('pullquote-left');
		$('<span class="pulledquote-text">'+$(this).html()+'</span>').appendTo(newNode);
		$('<span class="pullquote-bottom"></span>').appendTo(newNode);
		newNode.removeClass('pullquote-left');
		newNode.addClass('pulledquote-left').prependTo( $(this).parent());
		
	});
	
	//Collapsible link
		$('.link-collapsible').click(function(){
		if($(this).hasClass('link-collapse')) {
			$(this).removeClass('link-collapse').addClass('link-expand');
			$($(this).attr('href')).show();
		} else {
			$(this).addClass('link-collapse').removeClass('link-expand');
			$($(this).attr('href')).hide();				
		}		
		return false;
	});	

	//$('.layer-filter-form').corner("keep").css("border", "1px solid #eeeeee");	
	
	$('span.pullquote-right').each(function() {
		var parentTag = $(this).parent();
		var newNode = $('<blockquote class="pulledquote"></blockquote>');
		
		$(this).removeClass('pullquote-right');
		newNode.html('<span class="pulledquote-text">'+$(this).html()+'</span>');
		$('<span class="pullquote-bottom"></span>').appendTo(newNode);
		newNode.removeClass('pullquote-right');
		newNode.addClass('pulledquote-right').prependTo( $(this).parent());
	});
	
	$('span.pullquote-center').each(function() {
		var newNode = $('<blockquote class="pulledquote"></blockquote>');
		
		$(this).removeClass('pullquote-center');
		newNode.html('<span class="pulledquote-text">'+$(this).html()+'</span>');
		$('<span class="pullquote-bottom"></span><span style="display:block;clear:both></span>"').appendTo(newNode);
		newNode.removeClass('pullquote-center');
		newNode.addClass('pulledquote-center').prependTo($(this).parent());
	});
	
});	
