jQuery.fn.icvideo = function(options){
    
    // Объявляем набор опций для jQuery
    var options = jQuery.extend({
        video: [], // Массив ссылок на видео.
        current: 0 // Текущее видео.
    }, options);
    
    jQ = this; // Объявляем переменную для работы внутри встроенного класса.

    video = {
        // Метод инициализации. выставляет видео по умолчанию
        init: function()
        {
          jQ.append('<div align="right" style="font-size: 10px; margin: 5px 5px 5px 5px">' + 
'<a href="#" onclick="$(this).parent().parent(\'div\').hide()"></a>&nbsp;' + '</div>' );
                
          var startVideo = false;
          
          for(var vid in options.video)
            if(vid!='' && vid != undefined && vid != null)
            {
                options.current = vid;
                var camnumber = parseInt(vid)+1;
                startVideo = true;
                jQ.append('<div id="video"><div align="center"><embed height="370" width="400" flashvars="width=400&height=370&file='+options.video[vid]+'&bufferlength=3&autoscroll=true&screencolor=0xCCE78B&image=http://norilsk-zv.ru/webcam/cam'+camnumber+'.jpg" allowfullscreen="true" allowscriptaccess="never" src="/mediaplayer.swf"></div></div>');
                break;
            }
          
          if(startVideo == false) 
              jQ.append('<div id="video"><table><tr><td>     .</td></tr></div>'); 
          
jQ.append('<div id="links" align="center" style="font-size: 10px; margin-top: 5px; font-size: 20pt"><a href="#" onclick="$.icvideo_Action.prev();" style="text-decoration: none; font-size:20pt">&larr;</a>&nbsp;'+
'&nbsp;&nbsp;<span id="camnumber">'+camnumber+'</span>&nbsp;'+
                    '<a href="#" style="text-decoration: none; font-size:20pt" onclick="$.icvideo_Action.next();">&rarr;</a>'+
                    '</div>' );

          return jQ;
           
        },
        // Метод перехода к следующему видео.
        next: function()
        {
            var plus = parseInt(options.current)+1;
            if(options.video[plus] != undefined && options.video[plus] != '' )
                  options.current++;

            jQ.children('div #links').children('#camnumber').html(parseInt(options.current)+1);
            jQ.children('#video').html('<div align="center"><embed height="370" width="400" flashvars="width=400&height=370&file='+options.video[options.current]+'&bufferlength=3&autoscroll=true&screencolor=0xCCE78B&image=http://norilsk-zv.ru/webcam/cam'+(parseInt(options.current)+1)+'.jpg" allowfullscreen="true" allowscriptaccess="never" src="/mediaplayer.swf"></div>');
        },
        // Метод перехода к предидущему видео.
        prev: function()
        {
            var minus = parseInt(options.current)-1;
            if(options.video[minus] != undefined && options.video[minus] != '' )
                  options.current--;

            jQ.children('div #links').children('#camnumber').html(parseInt(options.current)+1);
            jQ.children('#video').html('<div align="center"><embed height="370" width="400" flashvars="width=400&height=370&file='+options.video[options.current]+'&bufferlength=3&autoscroll=true&screencolor=0xCCE78B&image=http://norilsk-zv.ru/webcam/cam'+(parseInt(options.current)+1)+'.jpg" allowfullscreen="true" allowscriptaccess="never" src="/mediaplayer.swf"></div>');
        }
    }
    
    // Производим инициализацию
    video.init();
    // Присваиваем свойству icvideo_Actions объект video, для перемещения по видео.
    jQuery.icvideo_Action = video;
    // Возвращаем jQuery объект
    return jQ;
};


