/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

jQuery(document).ready(function($) {
    $('#searchtext').focusout(function(){
      $('#searchdiv').hide('slow');  
    });
    
    $('#searchtext').keyup(function(event){
        event.preventDefault();
        var tekst = $(this).attr('value');
        
        
        $.ajax({
            type: "POST",
            url: _DOMAIN+"?ajax=CSite&m=search&q="+tekst,
            dataType:"text",                       
            success: function(msg){                
                if(msg!='false'){                   
                    var dane = eval(msg);
                    var tresc = "";
                    $('#searchdiv').html(""); 
                    $.each(dane, function(key, value) { 
                        //alert(key + ': ' + value); 
                          tresc += '<span style="font-size:11px; color:black; line-height:10px; cursor:pointer; padding-left:5px;" onClick=(jQuery(\'#searchtext\').attr(\'value\',jQuery(this).html()))>'+value.title+'</span><br>';
                    });
                    $('#searchdiv').html(tresc); 
                    $('#searchdiv').show(); 
                }
                else{    
                    $('#searchdiv').hide();
                }        
            }
        });
    });
    
    $('#totop').click(function(){
        $('html, body').animate({
            scrollTop:0
        }, 'slow');
        return false;
    });    
    //    $('.okno-zwiastun-zamknij').click(function(){
    //        var vid = $(this).attr('vid');
    //        myPlayer = VideoJS.setup("example_video_"+vid);
    //        myPlayer.pause();
    //    });
    //    
    $('.okno-zwiastun-zamknij').click(function(){
        var vid = $(this).attr('vid');
        var idek = $(this).attr('idek');

        $('#movie_cont_'+idek).html('');

    });   
    
    $('.but_zwiastun').click(function(){
        var idek = $(this).attr('okno-zwiastun-id');
        var previd = $(this).attr('previd');
        $('#movie_cont_'+previd).html('<iframe src="'+_DOMAIN+'?ajax=CSite&m=getvideo&id='+previd+'" scrolling="no" border="0" frameborder=0 style="width:520px; height:290px; border:0px; margin-top:15px;">'); 

    //        $.ajax({
    //           type: "POST",
    //           url: "?ajax=CSite&m=getvideo&id="+previd,
    //           dataType:"text",                       
    //           success: function(msg){                
    //               if(msg!=''){                   
    //              //   $('#movie_cont_'+previd).html(msg); 
    //               }
    //               else{    
    //                 
    //               }        
    //           }
    //           });
    });
    
});


