/*
 * APPLICATION SPECIFIC JAVASCRIPT
 */


function toggleCheckBoxBySelector(box, class_name )
{
  $$( class_name ).each(function(e){
    e.checked = box.checked;
  }); 
  
}


// INIT VIDEOS

var initVideos = function()
{
  $$('.video').each(function(el)
  {
    initVideo(el);
  });
}
function initVideo(el)
{
    flash = el.down('.flv').innerHTML;
    image = el.down('.image').innerHTML;
    width = el.down('.width').innerHTML;
    height = el.down('.height').innerHTML;
    embed = $('embed_' + el.id);


    flashvars = {file: flash, image: image, backcolor: "#27333d", frontcolor: "#eeeeee"};
    params = {allowfullscreen: "true", allowscriptaccess: "always", wmode: "transparent"};
    attributes = {};
    swfobject.embedSWF("/pekin/player.swf", embed.id, width, height, "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
}

Event.observe(window, 'load', initVideos );


var initContentInsert = function()
{
  $$('#content-insert h4').each(function(heading){

    heading.observe('click', function(evt){
      evt.element().toggleClassName('active')
      evt.element().next('.options').toggle();
    })

  });

  $$('#content-insert li').each(function(li){

    li.observe('mouseover', function(evt){
      evt.element().addClassName('hover');
    });
    
    li.observe('mouseout', function(evt){
      evt.element().removeClassName('hover');
    });

    li.observe('click', function(evt){
      el = evt.element();
      el = Element.extend(el);
      c = el.down('.content').innerHTML;
      editor = tinyMCE.get('page_content');
      editor.execCommand('mceInsertContent', true, c);
    })

  });

}

Event.observe(window,'load', initContentInsert);
