$(function() {
    $(".uscom").click(function(){
       
        var getid = this.id;
        $("#coms_"+getid).toggle("slow");
        return false;
    })
    
    $('#login_form').dialog({
            bgiframe: true,
            width: 380,
            modal: true,
            autoOpen: false,
            stack: false
    });
    $('#reg_form').dialog({
            bgiframe: true,
            width: 380,
            modal: true,
            autoOpen: false
    });
    $('#why_register').dialog({
            bgiframe: true,
            width: 380,
            modal: true,
            autoOpen: false
    });
    $('#lost_password').dialog({
            bgiframe: true,
            width: 380,
            modal: true,
            autoOpen: false
    });
    $('#ruls_comment').dialog({
            bgiframe: true,
            width: 380,
            modal: true,
            autoOpen: false
    });
    
    $('.global_message').click(function(){
        var getTitleMess = $(this).text();
        var getTitle = $(this).attr("title");
        $(".publish_mess").dialog({autoOpen:false, modal: true, title: getTitleMess});
        $(".publish_mess").text(getTitle);
	$(".publish_mess").dialog('open');
        return false;
    });
    
    $(".hide_com_right, .show_com_right").click(function(){
        $(".hide_comments, .show_comments").toggle("slow");
        var getId = this.id.split("shc_");
        $.ajax({
            type: "POST",
            url: "libs/ajax_showhide.php",
            data: "comments=shc&news_id="+getId[1],
            success: function(msg){
            var parse = jsonParse(msg);
                if(parse.shc == 0){
                    $("#shc_"+getId[1]).removeClass();
                    $("#shc_"+getId[1]).addClass("hide_com_right");
                }
                else if(parse.shc == 1){
                    $("#shc_"+getId[1]).removeClass();
                    $("#shc_"+getId[1]).addClass("show_com_right");
                }
            }
          });
        return false;
    });
    
    $(".comment_login, .gray_btn").click(function(){ return false;});
    
    $(".answer_comment").click(function(){
        var getid = this.id.split("answer_");
        $("#com_"+getid[1]).toggle("slow");
        return false;
    });
    
    $(".left_hand,.active_cp").click(function(){
        var getUpId = this.id.split("up_");
       
        $.ajax({
            type: "POST",
            url: "libs/ajax.php",
            data: "vote=up&id="+getUpId[1],
            success: function(msg){
            var parse = jsonParse(msg);
                if(parse.message){
                    $("#comment_dialog").html(parse.message);
                    $("#comment_dialog").dialog({autoOpen:false, modal: true, draggable: false, closeOnEscape: false, title: parse.title});
		    $("#comment_dialog").dialog('open');
                }
                else if(parse.count){
                    if(parse.count > 0){
                        $("#sumvote_"+getUpId[1]).removeClass();
                        $("#sumvote_"+getUpId[1]).addClass("sumv_plus")
                    }
                    else if(parse.count < 0){
                        $("#sumvote_"+getUpId[1]).removeClass();
                        $("#sumvote_"+getUpId[1]).addClass("sumv_minus")
                    }
                    else if(parse.count == 0){
                        $("#sumvote_"+getUpId[1]).removeClass();
                        $("#sumvote_"+getUpId[1]).addClass("sumnormal")
                    }
                    $("#up_"+getUpId[1]).removeClass();
                    $("#up_"+getUpId[1]).addClass("active_cp")
                    $("#sumvote_"+getUpId[1]).text(parse.count);
                }
            }
          });
        return false;
    });
    
    $(".right_hand,.active_cm").click(function(){
        var getDownId = this.id.split("down_");
        
        $.ajax({
            type: "POST",
            url: "libs/ajax.php",
            data: "vote=down&id="+getDownId[1],
            success: function(msg){
            var parse = jsonParse(msg);
                if(parse.message){
                    $("#comment_dialog").html(parse.message);
                    $("#comment_dialog").dialog({autoOpen:false, modal: true, draggable: false, closeOnEscape: false, title: parse.title});
		    $("#comment_dialog").dialog('open');
                }
                else if(parse.count){
                    if(parse.count > 0){
                        $("#sumvote_"+getDownId[1]).removeClass();
                        $("#sumvote_"+getDownId[1]).addClass("sumv_plus")
                    }
                    else if(parse.count < 0){
                        $("#sumvote_"+getDownId[1]).removeClass();
                        $("#sumvote_"+getDownId[1]).addClass("sumv_minus")
                    }
                    else if(parse.count == 0){
                        $("#sumvote_"+getDownId[1]).removeClass();
                        $("#sumvote_"+getDownId[1]).addClass("sumnormal")
                    }
                    $("#down_"+getDownId[1]).removeClass();
                    $("#down_"+getDownId[1]).addClass("active_cm")
                    $("#sumvote_"+getDownId[1]).text(parse.count);
                }
            }
          });
        return false;
    });
    
    $(".zoom").fancybox({
        //'zoomSpeedIn':	500,
		//'zoomSpeedOut':	500,
        'overlayOpacity':	0.7,
		'overlayColor':	'#FFF'
    });
    
})
