/*
utility making embed flash or alt image list
require jquery.swfobject.js
author: Takanobu Inafuku a.k.a inafact
*/

(function($){

   function removeAllEmbed()
   {

   }

   //!- extend jquery
   $.fn.swflist = function(stage, elements, swfargs){

     //!- finding stage
     var stg = (stage != null) ? $(stage) : $('div[id*="swfStage"]');

     return this.each(function(i, el){

       var hasflash = $(el).attr('href').search(/\.flv|\.swf/) != -1 ? true : false;
       var swf_path = hasflash ? $(el).attr('href') : '';
       //var swf_path = hasflash ? $(el).attr('alt') : '';
       var resource_path = $(el).children().eq(0).is('img') ? $(el).children().eq(0).attr('alt') : '';
       //var img_path = altflag ? $(el).attr('href') : ($(el).attr('href') + "/" + (i + 1));

       //!- hide stage, clear href, memory index
       $(el).parent().children('div.swfstage').css('display', 'none');
       $(el).attr('href', 'javascript:void(0)');
       $(el).data('local_ID', {value:i});

       $(el).click(function(){
         //!- first if child element has flash, remove this node
         var que = $(this).data('local_ID').value;
         stg.each(function(j, je)
           {
             if(j != que){
               $(je).children().remove();
               $(je).css('display', 'none');
             }
             $(je).parent().children('a').css('display', 'block');
           }
         );

         //!- clicked one, change visible:none, and embed flash to parent element
         $(this).css({'display':'none'});
         stg.eq($(this).data('local_ID').value).css('display', 'block');
         stg.eq($(this).data('local_ID').value).flash(
           {
             swf: swf_path,
             width:600, height:450,
             parms:{window:'transparent'},
             flashvars:{prefix:'', video_flv:resource_path}
           }
         );

       });
       //!- end click handler

     });
   };
 }
)(jQuery);