$(document).ready(function(){
    
    //$('.new_time:eq(5)').css({display: 'none'});


    //Vote
    
    $('.sms').click(function(){
        $('.sms').hide(0);
        $('.sms_opened').show(0);
    });    
        
    
    $('.vote_view_result').click(function(){
        
        var id_vote = $(this).prev('input[name=vote_id]').attr('value');
        var vote_area = $(this).parents('.vote_block');
        
        $(vote_area).html('<div class="load_vote"></div>');
        
        $.ajax({              
            type: "POST",
            url: "poll.php",
            data: {'id': id_vote, 'flag': 'result'},
            async: false, success: function(msg){
            
                $(vote_area).html(msg);
            
            }
        });
        
    });
    
    $('.vote_go').click(function(){
        
        var id_vote = $(this).next('input[name=vote_id]').attr('value');
        var vote_area = $(this).parents('.vote_block');
        var answer = $(vote_area).find('input[name=vote_val]:checked').attr('value');
         
        $(vote_area).html('<div class="load_vote"></div>');
        
        $.ajax({              
            type: "POST",
            url: "poll.php",
            data: {'id':id_vote,'flag':'add','answer':answer},
            async: false, success: function(msg){
            
                $(vote_area).html(msg);
            
            }
        });
        
    });

    
    $('.item_news_main:odd').css({ background: '#DCDCDC'});
    
    $(".full_photo").click(function(){
        
        var cat = $(this).attr('rel');
        var id = $(this).children('img').attr('alt');
        
        var cont = $.ajax({              
            type: "POST",
            url: "get_info_photo.php",
            data: {'id': id, 
                   'cat': cat},
            async: false 
        }).responseText;

        $('#dialog').remove();
        $('body').append(cont);
        $("#dialog").dialog({
			width: 625,
            height: 550,
			modal: true,
            resizable: false
		});
        
        $('input[name="star"]').rating({
            callback: function(value, link){
                $(this).rating('readOnly', true, true);
                $.ajax({              
                    type: "POST",
                    url: "photo_rating.php", 
                    data: {'id': value},
                    async: false, success: function(msg){alert(msg);}
                });
            }
        });
        
        return false;
        
    });
    

    $(".dialog_video").click(function(){
        
        var valve = $(this).attr('rel');
        var video = valve.split('|');
        var player = '<div id="dialog" title="'+video[2]+'">'+
            '<script type="text/javascript">'+
            'var flashvars = {'+ 
            'allowFullScreen: true,'+
            'MediaLink: "uploads/video/'+video[0]+'",'+
            'image: "uploads/video_images/'+video[1]+'",'+
            'logo: "images/logo_trans_vkt.png",'+
            'logoLink: "http://www.vkt.ru",'+
            'logoTarget: "_blank",'+
            'playOnStart: false,'+
            'share: false'+
        '};'+
        'swfobject.embedSWF("preview.swf", "playerdiv", "500", "430", "9.0.0", "expressInstall.swf", flashvars, false, false);'+
        '</script>'+
        '<div style="width: 500px;height: 430px;" id="playerdiv"></div>'+
        '</div>';
        
        $('#dialog').remove();
        $('body').append(player);
        $("#dialog").dialog({
			width: 525,
            height: 480,
			modal: true,
            resizable: false
		});
    });
	
	$(".broadcast").click(function(){
			
        var player = '<div id="dialog" title="Прямая трансляция">'+
		'<embed src="http://www.cdnvideo.ru/aloha/jwplayer/mediaplayer-viral/player-viral.swf" height="680" width="640" allowscriptaccess="always" allowfullscreen="true" flashvars="&bandwidth=1779&file=1&playlist=bottom&playlistfile=http%3A%2F%2Fwww.cdnvideo.ru%2Faloha%2Fjwplayer%2Fvkt.xml&playlistsize=200&plugins=viral-2d&streamer=rtmp%3A%2F%2Fvkt.cdnvideo.ru%2Frtp"/>'+
        '</div>';
        
        $('#dialog').remove();
        $('body').append(player);
        $("#dialog").dialog({
			width: 665,
            height: 730,
			modal: true,
            resizable: false
		});
    });
    
    
    $("#butt_feed_main").live('click',function(){
        
        var fio = $('.fio');
        var fio_val = fio.attr('value');
        var email = $('.email');
        var email_val = email.attr('value');
        var post = $('.post');
        var post_val = post.attr('value');
        
        if(fio_val == '' || fio_val == 'ФИО')return $(fio).css('border', '1px solid red');
        else $(fio).css('border', '1px solid #dcdcdc');
        if(email_val == '' || email_val == 'Email')return $(email).css('border', '1px solid red');
        else $(email).css('border', '1px solid #dcdcdc');
        if(post_val == '' || post_val == 'Сообщение')return $(post).css('border', '1px solid red');
        else $(post).css('border', '1px solid #dcdcdc');
        
        $('#feedack_main').html('Отправка сообщения...');
        
        var cont = $.ajax({              
            type: "POST",
            url: "feedback.php",
            data: {'post': post_val,'fio': fio_val,'email': email_val},
            async: false 
        }).responseText;
        
        $('#feedack_main').html(cont);
        
    });
    
     $(".send_comm").live('click',function(){
        
        var name = $('.name_comm');
        var name_val = name.attr('value');
        var email = $('.email_comm');
        var email_val = email.attr('value');
        var post = $('.post_comm');
        var post_val = post.attr('value');
        var url = $('.url_comm').attr('value');
        
        if(name_val == '' || name_val == '')return $(name).css('border', '1px solid red');
        else $(name).css('border', '1px solid #dcdcdc');
        if(email_val == '' || email_val == '')return $(email).css('border', '1px solid red');
        else $(email).css('border', '1px solid #dcdcdc');
        if(post_val == '' || post_val == '')return $(post).css('border', '1px solid red');
        else $(post).css('border', '1px solid #dcdcdc');
        
        $('#post').html('Отправка сообщения...');
        
        var cont = $.ajax({              
            type: "POST",
            url: "comment.php",
            data: {'post': post_val,'name': name_val,'email': email_val, 'url': url},
            async: false 
        }).responseText;
        
        $('#post').html(cont);
        
    });
    
});

pic = new Image();
pic.src="/images/ajax-loader.gif";

