// JavaScript Document

(function($){
	$.fn.contentSlicer = function(){
		this.each(function(){
			var parent = $(this);
			var children = parent.children();
			
			for(var i=0;i<children.length;i++){
				
				if(children[i].tagName.indexOf('H3') != -1){
					if(typeof ulTag !='undefined' && ulTag.children().length == 0){
						ulTag.remove();
					};
					var ulTag = $('<ul></ul>');
					ulTag.insertAfter(children.eq(i));
				}
				else {
					
					if(children[i].tagName.indexOf('H4') != -1){
						
						var liTag = $('<li></li>').appendTo(ulTag);
						liTag.append(children.eq(i));
						
						if(typeof divContainer !='undefined' && divContainer.children().length == 0){
							divContainer.remove();
						};
						var divContainer = $('<div class="contentSlicerContainer"></div>').appendTo(liTag);
						
						/* Slider */
						divContainer.hide();
						children.eq(i).click(function(){
							var obj = $(this);
							var next = obj.next();
							if(typeof next[0] != 'undefined'){
								if(next.is(':visible')){
									next.slideUp(300);
									obj.removeClass('open');
								}
								else {
									next.slideDown(300);
									obj.addClass('open');
								}
							}
						})
						.hover(function(){
							$(this).addClass('href');
						},function(){$(this).removeClass('href');});
						
					}
					else {
						if(typeof liTag != 'undefined'){
							divContainer.append(children.eq(i));
						};
					};
					
				};
				
			};
			
		});
		
	};
	$(document).ready(function(){
		$('#description').contentSlicer();
	});
})(jQuery)
