﻿jq(document).ready(function(){
   
   jq.ui.dialog.defaults.bgiframe = true;	
   jq.ui.dialog.defaults.closeOnEscape = true; 
   
   //настройки прелоадера
   jq.blockUI.defaults.css = {
                        opacity: '1',
                        border: 'none',
                        padding: '0px',
                        width: '300px',
                        height: '300px',
                        cursor: 'default',
                        textAlign : 'left',
                        'background-color': '',
                        'margin-left': '-150px',
                        'margin-top': '-150px',
                        left: '50%',
                        top: '50%'};  
   jq.blockUI.defaults.overlayCSS = { }; 
       
   jq.blockUI.defaults.message = '<img alt="" src="http://vuspehe.com/images/loading.gif"/>';   
  
});
var SiteManager = new function(){
   
    this.AddComment = function()
    {
        if(jq("#comment_user").val() == "")
        {
            alert("Введите свое имя!")
            return;
        }
        if(jq("#comment_text").val() == "")
        {
            alert("Введите тексте комментария!")
            return;
        }
        if(jq("#post_id").val() != "")
        {
            
            AjaxPro.onLoading = function(b)
            {
                if(b)
                {
                    jq('#comments_btn').hide();
                    jq('#comments_loader').show();
                    
                    jq.blockUI.defaults.message = ''
                    jq.blockUI();
                }
                else
                {
//                    jq('#comments_loader').hide();
//                    jq('#comments_btn').show();
//                    
//                    jq.unblockUI();
//                    jq.blockUI.defaults.message = '<img alt="" src="http://vuspehe.com/images/loading.gif"/>';                    
                }
            };
            
            Blog.AddComment(jq("#comment_user").val(), jq("#comment_text").val(), jq("#comment_url").val(), jq("#post_id").val(), this.callbackAddComment);
        }
    };
    
    this.callbackAddComment = function(result)
    {
        if(result!= null)
        {
//            jq("#comment_text").val("");
//            jq("#comments_container").append(result.value[1]);
//            jq("#" + result.value[0]).fadeTo(0,0.0);
//            jq("#" + result.value[0]).fadeTo(800, 1);
            
            window.open(window.location, '_self'); 
            //jq.scrollTo(jq("#" +result.value[0] ).position().top, {speed:500});
        }
    };
    
    this.RemoveComment = function(id)
    {
        if(jq("#post_id").val() != "" && confirm("Вы действительно хотите удалить этот комментарий?"))
        {
            AjaxPro.onLoading = function(b){if(b){jq.blockUI();}else{jq.unblockUI();}};
            Blog.RemoveComment(id, jq("#post_id").val(), this.callbackRemoveComment);
        }
    };
   
    this.callbackRemoveComment = function(result)
    {
        if(result!= null && result.value != -1)
        {
            jq("#comment_" + result.value).remove();
        }
    };
    
    this.AddNewsComment = function()
    {
        if(jq("#comment_user").val() == "")
        {
            alert("Введите свое имя!")
            return;
        }
        if(jq("#comment_text").val() == "")
        {
            alert("Введите тексте комментария!")
            return;
        }
        if(jq("#news_id").val() != "")
        {
            
            AjaxPro.onLoading = function(b)
            {
                if(b)
                {
                    jq('#comments_btn').hide();
                    jq('#comments_loader').show();
                    
                    jq.blockUI.defaults.message = ''
                    jq.blockUI();
                }
                else
                {
//                    jq('#comments_loader').hide();
//                    jq('#comments_btn').show();
//                    
//                    jq.unblockUI();
//                    jq.blockUI.defaults.message = '<img alt="" src="http://vuspehe.com/images/loading.gif"/>';                    
                }
            };
            
            News.AddComment(jq("#comment_user").val(), jq("#comment_text").val(), jq("#comment_url").val(), jq("#news_id").val(), this.callbackAddComment);
        }
    };
        
    this.RemoveNewsComment = function(id)
    {
        if(confirm("Вы действительно хотите удалить этот комментарий?"))
        {
            AjaxPro.onLoading = function(b){if(b){jq.blockUI();}else{jq.unblockUI();}};
            News.RemoveComment(id, this.callbackRemoveComment);
        }
    };
      
    
    this.ShowProjectVideo = function()
    {
        try
        {   
            jq('object').hide(); 
            jq('#presentation_obj').show();
            jq.blockUI({message:jq("#presentation_dlg"),
                    css: { 
                        left: '50%',
                        top: '50%',
                        opacity: '1',
                        border: 'none',
                        padding: '0px',
                        width: '660px',
                        height: '590px',
                        cursor: 'default',
                        textAlign : 'left',
                        'margin-left': '-330px',
                        'margin-top': '-285px',
                        'background-color':'Transparent'
                    },
                    
                    overlayCSS: { 
                        backgroundColor: '#AAA',
                        cursor: 'default',
                        opacity: '0.3' 
                    },
                    focusInput : false,
                    baseZ : 6666,
                    
                    fadeIn: 0,
                    fadeOut: 0
                });
                           
                 
        }
        catch(e){  }; 
    };
    
    this.HideProjectVideo = function()
    {
        jq('object').show(); 
        jq.unblockUI();
        jq('#presentation_obj').hide();
    };
    
    this.HideInfo = function()
    {
        jq('object').show(); 
        jq('#presentation_obj').hide();         
        jq.unblockUI();
    };
    
    this.GetPartnerInfo = function(id)
    {    
        PhotoAlbum.GetPartnerInfo(id, this.callbackInfo);        
    };

    this.callbackInfo = function(result)
    {
        try
        {   
            jq('object').hide();  
            jq('#parter_photo_container').html(result.value);     
            
            jq.blockUI({message:jq("#parter_photo_info"),
                    css: { 
                        left: '50%',
                        top: '50%',
                        opacity: '1',
                        border: 'none',
                        padding: '0px',
                        width: '700px',
                        height: '418px',
                        cursor: 'default',
                        textAlign : 'left',
                        'margin-left': '-350px',
                        'margin-top': '-210px',
                        'background-color':'Transparent'
                    },
                    
                    overlayCSS: { 
                        backgroundColor: '#AAA',
                        cursor: 'default',
                        opacity: '0.3' 
                    },
                    focusInput : false,
                    baseZ : 6666,
                    
                    fadeIn: 0,
                    fadeOut: 0
                });     
        }
        catch(e){}; 
    };
    
    this.ShowUserPhoto = function(id)
    {
        var i = 0;
    
        while(jq('#photo_' + i).html() != null &&
              jq('#photo_' + i).html() != '' )
        {
            jq('#photo_' + i).hide();
            i++;
        }
        
        jq('#photo_' + id).css('opacity', 0);
		jq('#photo_' + id).show(); // Show  
		jq('#photo_' + id).animate({opacity: 1}, 500, null);
    };    
    
    this.HideUserPhoto = function(id)
    {
        jq('#photo_' + id).hide();
    };
}


jQuery(document).ready(function(){

jQuery("#navigation li").hover(

function(){
jQuery(this).find('ul').show('fast');
},

function(){
jQuery(this).find('ul').hide('fast');
}
);
});
