 /*
 * Put small preloader
 */
 
 function put_small_preloader(element){
 	element.html('<img src="/images/loading_small.gif" width="16" heigth="16" class=\"icon\" />');
 }
 
 function put_cool_preloader(element){
 	element.html('<img src="/images/loading_cool.gif" width="220" heigth="19" class=\"icon\" />');
 }


 /**
 * refresh flash select in editing tml
 **/
 
 function ref_select(cat_id, parent, current, init){
 	
 	$.get('/ajax/ajax_flash.x',{
	 	act:"get_cat_list",
		parent:cat_id
		}, function(data){
			//bof 1
			$("#cat_id").empty();
			$("item", data).each(
				function(){
					if(current==this.getAttribute('id') && init==1){
						$("#cat_id").append("<option value="+this.getAttribute('id')+" selected>"+this.getAttribute('name')+"</option>");
					}else{
						$("#cat_id").append("<option value="+this.getAttribute('id')+">"+this.getAttribute('name')+"</option>");
					}
				}
			);
			//eof 1
			}
	);
		
 }
 
 function re_count_flash(){
	$.get('/ajax/ajax_flash.x',{
	 	act:"re_count_flash"
		}, function(data){
				$("#re_count_box").html(data);
			}
		);
 }
 
 function put_preloader(in_what){
	$("#"+in_what).html("<img src='tml/img/preload.gif' width='43' height='11'>");	
 }
 
 function flash_menu_cache_del(){
	$.get('/ajax/ajax_flash.x',{
	 	act:"flash_menu_cache_del"
		}, function(data){
				$("#flash_menu_cache_del_box").html(data);
			}
		);
 }
 
 function load_variants_of_swf(url){
	$.get('/ajax/ajax_flash.x',{
	 	act:"load_variants_of_swf",
	 	url:url
		}, function(data){
				$("#load_variants_box").html("");
				//bof 1
				$("#variant_select").empty();
				$("item", data).each(
					function(){
							$("#variant_select").append("<option>"+this.getAttribute('url')+"</option>");	
					}
				);
				//eof 1
			}
		);
 }
 
 function show_add_tag_box(id){
    
 	$.get('/ajax/ajax_tags.x',{
	 	act:"get_tags_of_item_in_del",
	 	id:id
		}, function(data){
			//bof 1
            if($("#tag_box_"+id).html().length>1){
            	$("#tag_box_"+id).empty();
           	}else{
            	var to_append = "<div class='adm_tag_box'><table style='width: 100%'><tr><td><input type='text' id='add_tag_name_"+id+"' size='30' /> <img src='/images/icons/add_small.png' class='but_icon' onclick='add_flash_tag("+id+");' /></td></tr>";
            	//делаем список тегов к этой флешке c возможностью удалить
            	to_append += data;
            	//
            	to_append += "</table></div>";
            	//$("#tag_box_"+id).attr('tip',to_append);
                $("#tag_box_"+id).qtip({
                  content: {
                        text: to_append,
                        title: {
                           text: 'Теги', // Give the tooltip a title using each elements text
                           button: 'Close' // Show a close link in the title
                        }
                 },
                  position: {
                         corner: {
                            target: 'topRight',
                            tooltip: 'bottomLeft'
                         }
                  },
                  style: {
                     name: 'light',
                     padding: '7px 13px',
                     width: {
                        max: 300,
                        min: 0
                     },
                     tip: true
                  },
                  show: { 
                    when: { event: false },
                    ready: true 
                  }/*,
                  hide: { 
                    when: { event: 'unfocus' } 
                  }*/
               });
               $("#add_tag_name_"+id).focus();	
               $("#add_tag_name_"+id).autocomplete("/ajax/ajax_tags.x?act=get_similar_tag", {
            	    delay:400,
            	    minChars:2,
            	    matchSubset:1,
            	    autoFill:true,
            	    matchContains:1,
            	    cacheLength:10,
            	    selectFirst:true,
            	    maxItemsToShow:10
              });
           	}
			//eof 1
			}
	      );
 	
 }
 
/* function show_add_tag_box(id){
 	$.get('/ajax/ajax_tags.x',{
	 	act:"get_tags_of_item_in_del",
	 	id:id
		}, function(data){
			//bof 1
if($("#tag_box_"+id).html().length>1){
		$("#tag_box_"+id).empty();
	}else{
	var to_append = "<div class='adm_tag_box'>Добавить тег:<table style='width: 100%'><tr><td align='center'><input type='text' id='add_tag_name_"+id+"' size='30'> <input type='button' value='+' onclick='add_flash_tag("+id+");'></td></tr>";
	//делаем список тегов к этой флешке c возможностью удалить
	to_append += data;
	//
	to_append += "</table></div>";
	$("#tag_box_"+id).append(to_append);
	$("#add_tag_name_"+id).focus();	
	}
			//eof 1
			}
	);
 	
 }*/
 /*
 function get_similar_tag(id){
    $.get('/ajax/ajax_tags.x',{
	 	act:"get_similar_tag",
	 	id:id,
		name:$("#add_tag_name_"+id).attr("value")
		}, function(data){
			//bof 1
			
			//eof 1
			}
	);
 }*/
 
 function add_flash_tag(id){
	$.get('/ajax/ajax_tags.x',{
	 	act:"add_tag_to_item",
	 	id:id,
		name:$("#add_tag_name_"+id).attr("value")
		}, function(data){
			//bof 1
            $("#tag_box_"+id).qtip("destroy");
			show_add_tag_box(id);
            get_tags_of_item(id);
			//eof 1
			}
	);	
 }  
 
 function get_tags_of_item(id){
	$.get('/ajax/ajax_tags.x',{
	 	act:"get_tags_of_item",
	 	id:id
		}, function(data){
			//bof 1
			$("#i_tag_place_"+id).html(data);
			//eof 1
			}
	);
 }
 
 function delete_tag_from_flash(t_id,f_id){
	$.get('/ajax/ajax_tags.x',{
	 	act:"delete_tag_from_flash",
	 	t_id:t_id,
	 	f_id:f_id
		}, function(data){
			//bof 1
			//$("#tag_box_"+f_id).empty();
            $("#tag_box_"+f_id).qtip("destroy");
			show_add_tag_box(f_id);
			get_tags_of_item(f_id);
			//eof 1
			}
	);	
 }
 
 /*
 * запуск по загрузке
 */
 
 $(document).ready(function(){

	//все загругления
	$('.box_green').corner("6px");
	$('.box_red').corner("6px");
	$('.box_pink').corner("6px");
	$('.box_violet').corner("6px");
	$('.box_black').corner("6px");
	$('.box_darck').corner("6px");
	$('.box_light').corner("6px");
	//
    
    //спойлер
    $(".f_spoiler_name").click(function(){
        if($(this).attr("showed")=='0'){
            $(this).attr("showed","1");
            $(this).find("img").attr("src","/images/icons/sp_minus.png");
            $(this).parent().find(".f_spoiler_text").show();
        }else if($(this).attr("showed")=='1'){
            $(this).attr("showed","0");
            $(this).find("img").attr("src","/images/icons/sp_plus.png");
            $(this).parent().find(".f_spoiler_text").hide();
        }
    });
    //
    
    $('.qtip').each(function()
   {
      $(this).qtip({
         content: $(this).attr('tip'),
         position: {
             corner: {
                target: 'topRight',
                tooltip: 'bottomLeft'
             }
        },
      style: {
         name: 'cream',
         padding: '7px 13px',
         width: {
            max: 300,
            min: 0
         },
         tip: true
      }
   });
   });
	
 });
