var $ = jQuery.noConflict();
$(document).ready(function(){
	$('#example > ul').tabs();

    $('#blog_postEditForm').livequery(function()
    {
        if(CKEDITOR.instances.post_content_min){
            CKEDITOR.remove(CKEDITOR.instances.post_content_min);
        }
        CKEDITOR.replace( 'post_content_min',{
            filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images',
            filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
            toolbar : [['Source','Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-'],['Image']],
            skin : 'v2'
        });
        if(CKEDITOR.instances.post_content_max){
            CKEDITOR.remove(CKEDITOR.instances.post_content_max);
        }
        CKEDITOR.replace('post_content_max',
        {
            skin : 'v2',
            filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images',
            filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images'
        });
    });


    $('#blog_postEditForm').livequery(function()
    {
        $(this).submit(function(e)
        {
            var options={
                success: function(r)
                {
                    $('.form_edit').html(r);
                }
            };
            $(this).ajaxSubmit(options);
            return false;
        });
    });
	
	$('#posts_list').livequery(function(){
		
		$(this).find('.post_delete').each(function(index,item){
			$(item).bind("click", function(){
				$.ajax({
					type: 'post',
					url: $(item).attr('href'),								
					error: function(){},
			    	success: function(t)
			    	{			    	
				  		$(item).parent().parent().html('<td colspan="6">'+t+'</td>');
				  		$('.post_viewer:last').html("");
					}
				});		
				
				
				return false;
			});
		});
		$(this).find('.post_view').each(function(index,item){
			$(item).bind("click", function(){
				$.ajax({
					type: 'post',
					url: $(item).attr('href'),								
					error: function(){},
			    	success: function(t)
			    	{                        
				  		$('.post_viewer:last').html(t);
					}
				});		
				return false;
			});
		});
			$(this).find('.post_edit').each(function(index,item){
			$(item).bind("click", function(){
				$("#post_viewer").html("");
				$.ajax({
					type: 'post',
					url: $(item).attr('href'),								
					error: function(){},
			    	success: function(t)
			    	{

				  		$('.post_viewer:last').html(t);
					}
				});		
				return false;
			});
		});
		
		
	});

    $('.post_paginator').livequery(function(e){
       $(this).find('a').each(function(index,item){
        $(item).bind("click", function(){
            $.ajax({
					type: 'post',
					url: $(item).attr('href'),
					error: function(){},
			    	success: function(t)
			    	{
				  		$(".blog_posts_main").html(t);            
					}
				});		
            
            return false;
        });
       });
    });
	
});
