﻿// Copyright (c) 2010 Robust Haven, Leblanc Meneses
// dependencies: jquery, jqueryui
jQuery.fn.CodeBlockPanel = function (defaultSize, ctrl, expandImageUrl, collapseImageUrl) {
	$(this).wrap("<div style='height:" + defaultSize + "px; overflow-y: scroll; ' />");


	window.setTimeout(function () {
		$('.syntaxhighlighter').attr('style', 'overflow-x:hidden !important; overflow-y:hidden !important;');
	}, 3000);


	var wrap = $(this).parent();

	ctrl.insertAfter(wrap);

	var code = $(this);
	ctrl.each(function (index2) {
		$(this).data('Visibility', 'collapsed');
		$(this).click(function (e) {
			if ($(this).data('Visibility') == 'collapsed') {
				wrap.height(code.height());
				ctrl.css("background", "url(" + collapseImageUrl + ")");
				//                                wrap.stop().animate(
				//                                                        { height: code.height() },
				//                                                        {
				//                                                            duration: 1000
				//                                                            ,specialeasing: 'easeOutQuint'
				//                                                        });
				$(this).data('Visibility', 'expand');
			} else {
				wrap.height(defaultSize);
				ctrl.css("background", "url(" + expandImageUrl + ")");
				var top = $(wrap).offset().top;
				$('html, body').animate({ scrollTop: top - 20 }, 0);
				//                                wrap.stop().animate(
				//                                                        { height: defaultSize },
				//                                                        {
				//                                                            duration: 1000
				//                                                            ,specialeasing: 'easeOutQuint'
				//                                                        });
				$(this).data('Visibility', 'collapsed');
			}
		});
	});
}

