/**
 * Make element moSlide Plugin features for organizing slithered lists
 *
 * @author Ahmed Alkatheeri
 * 
 * @version 1.0
 * project site: http://www.mubde3.net/blog/
 */

(function($){
    
	$.fn.moSlide = function(title,contain,options) {
		var options = jQuery.extend({
			type: 'normal',
			duration: 0,
			advanced: 0,
			openBox: 0
		},options);
		
		return this.each(function(){

			$(this).show(0);

			if($(this).attr('id') != '') {
				var boxClass = $(this).attr('id');
				var objTitle = $('#'+boxClass+' '+title);
                var objContain = $('#'+boxClass+' '+contain);
			}
			if ($(this).attr('class') != '') {
				var boxClass = $(this).attr('class');
				var objTitle = $('.'+boxClass+' '+title);
                var objContain = $('.'+boxClass+' '+contain);
			}
			
			if(options.openBox == 1) {
				objContain.show();
			}
			
			switch(options.type){
					case'normal':
						objTitle.click(function(){
							$(this).next().slideToggle(options.duration);
						});
					break;
					case'organized':
						objContain.hide();
						if(options.advanced == 1) {
							objTitle.first().addClass('current');
							objTitle.first().next().show();
						}
						
						objTitle.click(function(){
							objTitle.removeClass('current');
                            $(this).addClass('current');
                            
                            objTitle.not('.current').next().slideUp(options.duration);
                            $(this).next().slideDown(options.duration);
                            
						});
					break;
					case'introduced':
						objContain.hide();
						if(options.advanced == 1) {
						   var containLength = objContain.length -1;
						   for(x=0;x<=containLength;x++){
								objContain.eq(x).delay(options.duration * x).slideDown(options.duration);
						   }
						}
						if(options.advanced != 1) {
							objContain.slideDown(options.duration);
						}
						
						objTitle.click(function(){
							$(this).next().slideToggle(options.duration);
						});
						
					break;
			 }
			
		});
			
	}
})(jQuery);
