$(document).ready(function(){    
    $('.feedback_popup').live('click', function(){
        var popup_feedback = new popUp();
        var tags = $(this).attr('rel');
        var sgname = $(this).attr('sgname');
        var tag_array = new Array();
        if (tags != '') {
            tag_array = tags.split(',');
        }
        popup_feedback.containerStyle = {
            display: 'none',
            zIndex:'5',
            top:'0px',
            left: '0px',
            position:'fixed',
            margin: '0px',
            boxShadow:'0 0 1px #fff',
            borderRadius:'8px',
            opacity: 1,
            backgroundColor:'#fff',
            overflow: 'hidden',
            border: '10px solid rgba(82, 82, 82, 0.7)'
        };
        popup_feedback.onclose = function(){
            popup_feedback.clearMe();
        };
        popup_feedback.load('/default/feedback/add',{
            width: '450px',
            title: 'Feedback',
            params: {default_tags: JSON.stringify(tag_array),sgname:sgname},
            postClear: true,
            buttons:[
            {
                value:'Send',
                clickFunction:function() {
                    $(".feedback_view_form form").ajaxSubmit({
                        type: "POST",
                        dataType: "html",
                        beforeSubmit: function() {
                             popup_feedback.lock();
                             popup_feedback.hideButtons(1);
                        },
                        success: function (data) {
                            try{
                                obj = $.parseJSON(data)
                                if (obj['message'] != undefined) {
                                    $('.feedback_view_form').html(obj['message']);
                                    popup_feedback.unlock();
                                    setTimeout(function(){
                                        popup_feedback.hide();
                                    }, 2000);
                                } else {
                                    popup_feedback.showButtons(1);
                                    popup_feedback.unlock();
                                    $('#feedback_form').parent().html(data);
                                }
                            } catch(e){
                                $('#feedback_form').parent().html(data);
                                popup_feedback.showButtons(1);
                                popup_feedback.unlock();
                            }
                        },
                        error: function ()
                        {
                            alert('error')
                        }

                    });
                }
            },
            {
                //value:'Return to Live Video Streams',
                value:'Close',
                clickFunction:function(){
                    popup_feedback.hide();
                }
            }
            ]
        })
        return false;
    });
});
