var d4jscDraw = function() {
  
  var draw = function(context) {
	$(context).each(function() {
		
		var $content = $(this);
		var $holder = $(this.parentNode);
		
		var appStyleClass = 'app1';
		if($content.attr('className').match(/\b(app[1-5])\b/)) {
			appStyleClass = RegExp.$1;
		}
		
		if(location.href.match(/StylePreview/)) {
			var $t = $content.find('span.style-title');
			$t.css({
				position: 'absolute',
				right: '0px',
				top: '0px',
				padding: '3px 9px',
				font: '11px Trebuchet MS,verdana,arial,sans-serif',
				'font-style': 'italic',
				color: 'black',
				border: '1px solid white',
				'background-color': '#D5E93B'
			});
			$holder.hover(
				function() { $t.show(); },
				function() { $t.hide(); }
			);
		}
		if(navigator.userAgent.match(/MSIE 6/)) {
			// vaannetaan IE6:lle kokoja rautalangasta
			$content.css({height: $content.height()});
			$holder.css({height: $holder.height(), width: $holder.width()});
		}
		$holder.addClass('jsc-holder');
		$holder.addClass(appStyleClass + '-jsc-holder');
		
		$content.addClass('jsc-content');
		
		var height = $holder.height();
		
		// lisataan apudivit
		if($holder.find('div.jsc-1').length==0) {
			$holder.append('<div class="jsc-1"></div><div class="jsc-2"></div><div class="jsc-3"></div>');
		}
		
		// DEBUG:
		//$('div.jsc-1',holder).css({'border-left': '3px solid red'});
		//$('div.jsc-2',holder).css({'border-right': '3px solid green', 'background': 'yellow'});
		//$('div.jsc-3',holder).css({'border-left': '3px solid blue'});
		
		// suurennetaan keski-taustakuvaa paddingien verran - vasta silla saadaan oikea koko
		$holder.find('div.jsc-2').each(function() {
			height += (+ $holder.css('padding-top'   ).replace(/px/, ""));
			height += (+ $holder.css('padding-bottom').replace(/px/, ""));
			$(this).height(height);
		});

		
		if(navigator.userAgent.match(/MSIE 6/)) {
			// IE 6: "bottom: 0" (tai -1px) ei aina toimi, joten asetetaan sijainti ylhaalta pain
			
			$holder.find('div.jsc-3').each(function() {
				$(this).css({bottom: null, top: (height - $(this).height())+'px'});
			});
			

			if(typeof(supersleight) != 'undefined') {
				supersleight.run($holder[0]);
			}
		}
	});
  };
  
  $(function() {
  	draw('div.jsc');
  });
  
  // ei julkisesti kutsuttavia metodeja
  return {
  	draw: draw
  };
}();

