$(document).ready(function(){
	
	function setContentSize(resize) {
        var $page = $('div.content_page');
        var content = $('body')[0];
        
        var contentHeight = content.offsetHeight;
        if(!$.browser.msie){
        	
        		contentHeight = content.scrollHeight;
        	
        		
	    	/*Work out border height - Standard box model*/
	    	var borderHeight = 0;
	        if ($page.css('border-top-style') != "none") {
	            borderHeight += parseInt($page.css('border-top-width'), 10);
	        }
	        if ($page.css('border-bottom-style') != "none") {
	            borderHeight += parseInt($page.css('border-bottom-width'), 10);
	        }
	        if(!resize)
	        contentHeight -= borderHeight/2;
	        else
	        	contentHeight -= borderHeight;
        }
        
        var contentWidth = content.offsetWidth;
    	if(!$.browser.msie){
    		if(!resize)
    			contentWidth = content.scrollWidth;
	        /*Work out whole width - IE box model*/
	    	var borderWidth = 0;
	        if ($page.css('border-left-style') != "none") {
	            borderWidth += parseInt($page.css('border-left-width'), 10);
	        }
	        if ($page.css('border-right-style') != "none") {
	            borderWidth += parseInt($page.css('border-right-width'), 10);
	        }
	        if(!resize)
	        	contentWidth -= borderWidth/2;
	        else
	        	contentWidth += borderWidth/2;
        }
        
    	
        $page.height(contentHeight);
        $page.width(contentWidth);
	}
	
	setContentSize(false);
	$(window).bind("resize", function() {setContentSize(true);});
        
        /* set focus on input field when wrapping was clicked */
        $("input[id^='iItemStyle_'], textarea[id^='iItemStyle_']").each(function(){
           var $wrapping = $(this).parents("[id^='wrappingStyle_']:first");
           $wrapping.bind("click", function(event) {
               $target = $("[id^='iItemStyle_']", this);
               $target.focus();
               event.stopPropagation();
           });
        });
        /*end set focus on input*/
});  