/*
 * Плагин создания слайдеров
 * 2011, Brobbikov Sasha (alexandr.brn@gmail.com)
*/
jQuery.fn.slideView = function(options){

	var options = jQuery.extend({
		slide: "",
		count: '2', //Колилчество вкладок
		width: '300px', //ширина вкладки
		height: ' ', //высота каждого элемента li
		init: '', //Начальное значение (block, none)
		message: '.message',
                                    
		name: '',
                                    elem:"1",
		complete: function(){
			//alert(1);
		},
                                    click: function(){
			//alert(1);
		} //Функция после обработки слайдов//Функция после обработки слайдов
	}, options);
	
	var main_block = " ";
	var parent_block = " ";
	var parent = new Array();
	var main = $(this);
	
	$.getJSON("ajax.php?type="+options.name+"&main=one", function(data){
		main_block = "";
		
                                  
                
		for(var key in data){
			var value = data[key];

			main_block += "<li  title='"+value.ID+"'><b></b><i></i><a href='#"+value.ID+"'><span>"+value.NAME+" <s></s></span></a></li>";
			//main_block = "1";
		}
		
		var main_template = '<div class="ul_holder" id="main"><ul class="white_arrow white_arrow_js">'+main_block+'</ul></div>';
		
		main.append(main_template);	
                                    
                                    
		$(options.slide+' #main ul li').click(function(){
		
			
			if ($(this).attr("class") != "selected") {
                                                              
                                                                $(this).parent().children().removeAttr("class");
                                                                $(this).attr("class",'selected');
                                                                $(this).animate({width:options.width},"fast");
                                                            
                                                            if($(this).attr("title")  == 0){
                                                                show_slide();
                                                                options.complete();
                                                                $(options.slide+' .parent_slide *').remove();
                                                            }
                                                            
                                                            if($(this).attr("title")  != 0){
			
				$.getJSON("ajax.php?type="+options.name+"&main=two&value=" + $(this).attr("title"), function(data){
				
					$(options.slide+' .parent_slide').animate({
						opacity: "0.1",
						width:0
					}, 500, function(){
						$(this).remove();
					});
					
					for (var key in data) {
						var value = data[key];
						
						parent_block += "<li title='" + value.ID + "'><b></b><i></i><a href='#" + value.ID + "'><span>" + value.NAME + " <s></s></span></a></li>";
						
					}
					
					var parent_template = '<div class="ul_holder parent_slide" style="display:none"><ul class="white_arrow white_arrow_js">' + parent_block + '</ul></div>';
					
					main.append(parent_template);
                                        
                                                                                        
					
					$(options.slide+' .parent_slide').animate({
						height: "show"
					}, "fast");
					
					$(options.slide+' .parent_slide ul li').click(function(){
					
						if ($(this).attr("class") == "selected") {
						
							if ($(options.slide+' .parent_slide ul li:not(.selected):visible').length > 0) {
							
								show_slide();
								options.complete();
								
							}
							else {
								hide_slide();	
							}

						}
						else {
							$(this).animate({
								//width: "900px"
							}, "fast");
							
							$(this).parent().children().removeAttr("class");
							$(this).attr("class", 'selected');
							
							show_slide();
							options.complete();
							
						}
					});
					
					
					parent_template = "";
					parent_block = '';
				});
                                                        }
			}
			else{
				
				if ($(options.slide+' .parent_slide ul li:not(.selected):visible').length > 0) {
							
								
                                                                        }
                                                                        else {
                                                                                        hide_slide();
                                                                                    }
				
			}
			
		});
		
	function hide_slide(){
		
		$(options.slide+' .parent_slide ul li:not(.selected)').animate({
			height: "show",
		}, "2000");
		
		$(options.slide+' #main ul li:not(.selected)').animate({
			height: "show"
		}, "1000");
		
                                    $(options.slide).parent().children(options.message).remove();
                                    options.click();
                                    
		
	}
	
	function show_slide(){
		
		$(options.slide+' .parent_slide ul li:not(.selected)').animate({
			height: "hide",
		}, "2000");
		
		$(options.slide+' #main ul li:not(.selected)').animate({
			height: "hide"
		}, "1000");
		
                              
                
	}
	
	function load_view(){
		
		
		
	}
		
	function postSlide(){
		
		
		
	}
	function complete(){
		
		//alert(1);
		
	}
		
	});
	
	
	
	
	
	
	
	
	
}
