(function($, window, undefined){
	$(function(){
	  
		// tpl_guide
		$(".tpl_guide").each(function(){
	    var e = $(this);
	    var h = e.height();
	    var w = e.width();
	    var t = e.attr("title");
	    e.prepend(
	        $('<cite title="' + t + '.tpl"/>').click(function(){
	          e.toggleClass("hover");
	          return false;
	        })
	      )
	      .prepend(
	        $('<div class="overlay" title="' + t + '.tpl"><span>' + t + '.tpl</span></div>').height(h).width(w)
	      )
	    ;
	  });
		
		// DIV.bodyid is in the footer. This copies the data to BODY
		$(".bodyid").each(function() {
			$("BODY").attr("id", $(this).attr("id"));
			$(this).remove();
		});
	
		// Copy the breadcrumbs into the top part.  Prestashop is lame.
		if ($('#old_bc').html())  {
			$("#breadcrumb").html($('#old_bc').html());
			$('#old_bc').remove();
		}
		else  {
			$("#breadcrumb").remove();
		}
		
		// Move search into the header.
		$('DIV#search_block_top').remove().appendTo('DIV#header');
		
		// Select search if it equals the default
		$('#search_block_top #search_query_top').focus(function()  {
			if(this.value == 'Enter search text...')  {
				$(this).val('');
			}
		});
		$('#search_block_top #search_query_top').blur(function()  {
			if (this.value == '')  {
				this.value = this.defaultValue;
			}
		});
		$('#search_block_top #search_query_top_submit').click(function()  {
			$('#search_block_top #searchbox').submit();
			return false;
		});
	
		
		// jQuery masonry
		$(".masonry").each(function(){
			var m = $(this);
			m.masonry({
				itemSelector: m.data("selector"),
				columnWidth: m.data("column-width")
			});
		});
		
		// Change the contact form input box into a text area
		$('FORM#MailArea INPUT#MailMessage').replaceWith('<textarea style="width:160px; height:140px" name="Message" id="MailMessage"></textarea>');
	});
})(jQuery, window);
