 /* initialisation functionality */

 function apply_dom(){
   try{
   hide_elements();
   show_elements();
   initialise_sliders();
   apply_event_handlers();
   consistancise_links();
   intialise_media_player();
   set_up_cookie_hooks();
   }
   catch (e){
     //alert(e); //to do - remove me
   }
 }

 /*
  * Hides any elements that need to be display initially for
  * graceful degredation purposes.
  *
  *
 */
 function hide_elements(){
   /* now handled with noscript tags and stylesheets */
 }


 /*
  * Shows any elements that need to be displayed
  * but whose default state is to be hidden. For example
  * form controls triggered by the presence of a certain
  * selected element.
 */
 function show_elements(){
   var tag_body = document.getElementsByTagName("body");
   switch(tag_body[0].id){
     case "page-book":
       var funded_criteria_selected = document.getElementById('funded_rate');
       if(funded_criteria_selected!=null){ // sometimes this widget isn't present.
          if(funded_criteria_selected.checked){
           document.getElementById('funded-criteria').style.display='block';
         }
       }
   }

 }

  function initialise_sliders(){
    
   var arr_sliders = document.getElementsByClassName('slider');
   var slider;
   var slider_heading;
   var slider_link;
   var offset; 
   

   for(i=0;i < arr_sliders.length;i++){
       slider = arr_sliders[i];
       slider_heading = slider.getElementsByTagName('h1');
       slider_link = slider_heading[0].getElementsByTagName("a");
       slider_link = slider_link[0];
       slider_link.onclick = function(){
                                slide_box(this.parentNode.parentNode.id);
                                return false;
                              }
   }
 
  
 }

 /*
  * attaches the required event handlers
  * 2 types; global or page level handlers.
  *
  *
  *
 */
 function apply_event_handlers(){
 
 

   var global_search = document.getElementById('search-text');
   global_search.onclick = function(){
     if(this.value=='Search'){this.value='';}
   }

   /* this is a custom tag, so potentially it's in every page */
   var global_newsletter_email = document.getElementById('newsletter-email');
   if(global_newsletter_email!=null){
     global_newsletter_email.onclick = function(){
       if(this.value=='Your email here'){this.value='';}
     }
   }
   

   /* this is a custom tag, so potentially it's in every page */
   var global_newsletter_lastname = document.getElementById('last_name');
   if(global_newsletter_lastname!=null){
     global_newsletter_lastname.onclick = function(){
       if(this.value=='Last name here'){this.value='';}
     }
   }
   
   
   /* this is a custom tag, so potentially it's in every page */
   var global_newsletter_firstname = document.getElementById('first_name');
   if(global_newsletter_firstname!=null){
     global_newsletter_firstname.onclick = function(){
       if(this.value=='First name here'){this.value='';}
     }
   }


   /* page specific handlers */
   var tag_body = document.getElementsByTagName("body");
   
   switch(tag_body[0].id){
     case "page-book":
       set_up_funded_control();
       set_up_copy_from_above();
       set_up_other_inputs();
       var booking_form = document.getElementById('course-book');
       /*
         we don't want to load the bookers details from cookies if they've submitted the form.
         If we do, we could silently overwrite details that were loaded, then amended.
         the post classname is inserted by the booking request handler.
       */
       
       if (booking_form.className.indexOf('post')==-1){ 
         load_details();
       }
    break;

    case "page-search":
      set_up_refine_search();
      break;

    case "page-glossary":
      set_up_glossary();
      break;

   }
 }

 function set_up_funded_control(){

   var input_full_rate = document.getElementById("full_rate");
     input_full_rate.onclick = function(){
     document.getElementById("funded-criteria").style.display="none";
   }

   var input_funded_rate = document.getElementById("funded_rate");
   if(input_funded_rate!=null){
     input_funded_rate.onclick = function(){
     document.getElementById("funded-criteria").style.display="block";
   }
   }

 }

 function set_up_copy_from_above(){
   var copy_booker_details = document.getElementById("copy-from-above");
   copy_booker_details.onclick = copy_from_above;
 }

 /*
  * copy the booker's personal details into
  * the trainees personal details section
  *
 */
 function copy_from_above(){
   var title = document.getElementById('title');
   var first_name = document.getElementById('first_name');
   var last_name = document.getElementById('last_name');
   var email = document.getElementById('email');
   var telephone = document.getElementById('telephone');
   var fax = document.getElementById('fax');

   document.getElementById('trainee_first_name').value=first_name.value;
   document.getElementById('trainee_last_name').value=last_name.value;
   document.getElementById('trainee_email').value=email.value;
   document.getElementById('trainee_telephone').value=telephone.value;
   document.getElementById('trainee_fax').value=fax.value;

   var trainee_title = document.getElementById('trainee_title');

   var arr_titles = trainee_title.getElementsByTagName('option');
   for (i=0;i<arr_titles.length;i++){
     if(arr_titles[i].text==title[title.selectedIndex].text){
       arr_titles[i].selected="selected";
     }
   }
 }

 function set_up_cookie_hooks(){
   var form_course_book = document.getElementById("course-book");
   if(form_course_book){
     form_course_book.onsubmit = function (){
       var title = document.getElementById('title');
       title = title[title.selectedIndex].text;

       var trainee_title = document.getElementById('trainee_title');
       trainee_title = trainee_title[trainee_title.selectedIndex].text;

       createCookie("title", title, 365);
       createCookie("trainee_title", trainee_title, 365);

       var all_inputs = document.getElementsByTagName("input");
       for(i=0;i < all_inputs.length;i++){
         if(all_inputs[i].value!=null && all_inputs[i].value!=""){
           createCookie(all_inputs[i].id,all_inputs[i].value, 365);
         }
       }

       var all_textarea = document.getElementsByTagName("textarea");
       for(i=0;i < all_textarea.length;i++){
         if(all_textarea[i].value!=null && all_textarea[i].value!=""){
           createCookie(all_textarea[i].id,all_textarea[i].value, 365);
         }
       }
     }
   }
 }


 /*
  * Some of the form controls reveal extra
  * inputs depending on their values.
  * Here we set up the events to show those
  * inputs, and decide weather to display them or not.
 */
 function set_up_other_inputs(){
   var heard_of_vet_via = document.getElementById('heard_about');
   heard_of_vet_via.onchange = function(){
     document.getElementById('specified-advertisement-container').className='delayed-hide'; //hide the element if the trigger is not selected
     document.getElementById('specified-other-container').className='delayed-hide';
     var heard_of_options = heard_of_vet_via.getElementsByTagName("option");
     for(i=this.selectedIndex;i<heard_of_options.length;i++){
       if(heard_of_options[i].selected){
         if(heard_of_options[i].text=='Advertisement (please specify)'){
           document.getElementById('specified-advertisement-container').className='';
         }
         if(heard_of_options[i].text=='Other (please specify)'){
           document.getElementById('specified-other-container').className='';
         }
       }
     }
   }
 }

 function load_details(){
   var all_inputs = document.getElementsByTagName("input");
   for(i=0;i < all_inputs.length;i++){
     if(all_inputs[i].value==null || all_inputs[i].value==""){
       if(readCookie(all_inputs[i].id)!=null){
         all_inputs[i].value = readCookie(all_inputs[i].id);
       }
     }
   }

   var all_textarea = document.getElementsByTagName("textarea");
   for(i=0;i < all_textarea.length;i++){
     if(all_textarea[i].value==null || all_textarea[i].value==""){
       if(readCookie(all_textarea[i].id)!=null){
         all_textarea[i].value = readCookie(all_textarea[i].id);
       }
     }
   }

   if(readCookie('title')!=null){
     var title = document.getElementById('title');
     var arr_titles = title.getElementsByTagName('option');
     for (i=0;i<arr_titles.length;i++){
       if(arr_titles[i].text==readCookie('title')){
         arr_titles[i].selected="selected";
       }
     }
   }

   if(readCookie('trainee_title')!=null){
     var trainee_title = document.getElementById('trainee_title');
     var arr_titles = trainee_title.getElementsByTagName('option');
     for (i=0;i<arr_titles.length;i++){
       if(arr_titles[i].text==readCookie('trainee_title')){
         arr_titles[i].selected="selected";
       }
     }
   }

 }

 function set_up_refine_search(){
   var input_refine_search = document.getElementById('refine-search');
   input_refine_search.onclick=function(){
     var fieldset_refine_search = document.getElementById('refine-search-options');
     if(fieldset_refine_search.className=='delayed-hide'){
       fieldset_refine_search.className ='';
       input_refine_search.style.display="none";
     }
   }
 }

 function set_up_glossary(){
   var dd_all_definitions = document.getElementsByClassName('letter');
   var list;
   var terms;
   for(i=0;i<dd_all_definitions.length;i++){
     list = dd_all_definitions[i].getElementsByTagName('dl');
     if(list.length > 0){
       terms = list[0].getElementsByTagName('dt');
       
       for(k=0;k<terms.length;k++){
         terms[k].onclick=function(){
           var definition = this.nextSibling;
           reset_glossary();
           definition.className='reset'; //removes the class that hides the definition, displaying the term.
           this.style.textDecoration='underline';
         }
       }
     }
   }
 }

 function reset_glossary(){
   var dd_exposed_terms = document.getElementsByClassName('reset');
   for(i=0;i<dd_exposed_terms.length;i++){
     dd_exposed_terms[i].className="delayed-hide";
     dd_exposed_terms[i].previousSibling.style.textDecoration='none';
   }
 }

 function consistancise_links(){
    var arr_links = document.getElementsByTagName("a");
    for(i=0;i < arr_links.length;i++){
        str_href = new String(arr_links[i].href);
        str_class = new String(arr_links[i].className);
                if(str_class.indexOf("small_window")!=-1 && str_href.valueOf()!="" && str_href.indexOf("mailto")!=0){
                  arr_links[i].onclick= function(){
                       return small_window(this);
                  }
                }
                if(str_class.indexOf("new_window")!=-1 && str_href.valueOf()!="" && str_href.indexOf("mailto")!=0){
                  arr_links[i].onclick= function(){
                       return new_window(this);
                  }
                }
    }

    var link_print = document.getElementById('print');
    if (link_print != null)
    {
        if(link_print.childNodes[0])
        {
          link_print.childNodes[0].onclick = function()
          {
            window.print();
            return false;
          }
        }
    }
  }

  function small_window(link){
    window.open(link.href,null,"height=500,width=300,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes",true);
    return false;
  }

  function new_window(link){
    window.open(link.href,null,"height=600,width=800,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes",true);
    return false;
  }


/************************************** Dom mods *********************************/

document.getElementsByClassName = function(str_needle) {
  
  if(this.domain){
    var         my_array = document.getElementsByTagName("*");
  }
  else{
    var         my_array = this.getElementsByTagName("*");
  }
  
  var        retvalue = new Array(); 
  var        i;
  var        j;

  for (i = 0, j = 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + str_needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
 
  return retvalue;
}

 /************************************ sliders *************************************/

 var slide_speed=1;
 var slide_accel=5;
 var anim_speed=10;
 var timerID="!";

 function slide_box(id)
 {
  if(timerID.indexOf('!')<0)
   return false;

  var tmpBox=getBoxObj(id);
  var tmpIDs="";
  if(tmpBox.group.indexOf('!')<0){
   var tmpBoxes=getBoxObjects(document.getElementById(id).parentNode,tmpBox.group);
   for(var i=0; i<tmpBoxes.length; i++)
    if(id!=tmpBoxes[i].id)
     if(tmpBoxes[i].height>=tmpBoxes[i].max)
       tmpIDs+=":"+tmpBoxes[i].id;
  }

  if(tmpBox.height<=tmpBox.min)
   slide_boxOpen(id+tmpIDs);
 }

 function setBoxHeight(id,height)
 {
  var tmpBoxArr=document.getElementById(id).className.split(" ");
  var content = document.getElementById(id).getElementsByTagName('div');
  content = content[0]; // kludge. we know there is only one child div.

  var tmpBoxVal=tmpBoxArr[1].split(":");
  tmpBoxVal[0]=height;
  var bodyHeight=(height-getBoxObj(id).min)-10;
  if(bodyHeight<1){
   content.style.display="none";
  }
  else{
   content.style.display="block";
   content.style.height=bodyHeight+"px";
  }
  document.getElementById(id).style.height=height+"px";
  document.getElementById(id).className=tmpBoxArr[0]+" "+tmpBoxVal.join(":");
 }

 function getBoxObjects(node,classMatch)
 {
  var arrSliders = node.getElementsByTagName('div');
  var arrSlidersFiltered=new Array();

  for(var i=0; i<arrSliders.length; i++)
   if((arrSliders[i].className.length>=classMatch.length) && (arrSliders[i].className.substr(0,classMatch.length)==classMatch))
    arrSlidersFiltered.push(getBoxObj(arrSliders[i].id));

  return arrSlidersFiltered;
 }


 function getBoxObj(id)
 {
  var tmpBoxArr=document.getElementById(id).className.split(" ");
  var tmpBoxVal=tmpBoxArr[1].split(":");
  var tmpBox=new Object();
  tmpBox.id=id;
  tmpBox.height=parseInt(tmpBoxVal[0]);
  tmpBox.min=parseInt(tmpBoxVal[1]);
  tmpBox.max=parseInt(tmpBoxVal[2]);
  tmpBox.group=tmpBoxArr[0];
  tmpBox.percentage=Math.round((tmpBox.height-tmpBox.min)/((tmpBox.max-tmpBox.min)/100));

  return tmpBox;
 }


 function slide_boxClose(id)
 {
  var complete=false;
  var currBox=getBoxObj(id);
  var newHeight=(currBox.height-Math.round(slide_speed+((currBox.percentage)/slide_accel)));

  if(newHeight<=currBox.min){
   newHeight=currBox.min;
   complete=true;
  }
  setBoxHeight(id,newHeight);
  if(!complete){
   timerID=currBox.id;
   window.setTimeout("slide_boxClose('"+id+"');",anim_speed);
  }
  else
   timerID="!";
 }

 function slide_boxOpen(id)
 {
  var complete=false;
  var currBox;
  if(id.split(":").length<2)
   currBox=getBoxObj(id);
  else
   currBox=getBoxObj(id.split(":")[0]);
  var newHeight=(currBox.height+Math.round(slide_speed+((100-currBox.percentage)/slide_accel)));
  if(newHeight>=currBox.max){
   newHeight=currBox.max;
   complete=true;
  }
  if(id.split(":").length>1){
   var tmpID=id.split(":");
   for(var i=1; i<tmpID.length; i++)
    setBoxHeight(tmpID[i],currBox.max-(newHeight-currBox.min));
   setBoxHeight(id.split(":")[0],newHeight);
  }
  else
   setBoxHeight(id,newHeight);

  if(!complete){
   timerID=currBox.id;
   window.setTimeout("slide_boxOpen('"+id+"');",anim_speed);
  }
  else
   timerID="!";
 }


 /** media player functions ********************/

 /**
  *  checks if the media player needs to be available on the current page.
  *
  *  adds the appropriate handlers to each link that triggers the player
  *
  *
 */
 function intialise_media_player(){
   var media_player = document.getElementById('media-player');
   if (media_player!=null){
     var link_close_icon = document.getElementById('close-media-player');
     link_close_icon.childNodes[0].onclick=function(){ /* child because the element link_close_icon is the enclosing paragraph */
       this.parentNode.parentNode.className="delayed-hide";
       clear_active_players();
       return false;
     }

     var arr_media_player_links = document.getElementsByClassName('media-player');
     for(i=0;i<arr_media_player_links.length;i++){
       arr_media_player_links[i].onclick=trigger_media_player;
     }

   }
 }

 function trigger_media_player(){
   var div_media_player = document.getElementById('media-player');
   div_media_player.className=""; /* show the player */
   build_player(this);

   return false; /* don't let the link actually load the url; note: url points to the actual video file */

 }

 /*
 * Takes a link object. Reads the class name and decides which type of player
 * to display. Responsible for add / removing mark-up that can display a video.
 *
 */
 function build_player(link_video){


   hide_all_players();

   var str_plugin_height = get_plugin_height(link_video);
   var str_plugin_width = get_plugin_width(link_video);



   /** windows media files */
   if(link_video.className.indexOf('x-ms-wmv')!=-1 || link_video.href.indexOf('.asx')!=-1){
     var video_container = build_ms_media_player(link_video);
   }

   /** flash video files *******/
   if(link_video.className.indexOf('x-flv')!=-1){
     clear_active_players();
     var video_container = document.getElementById('flash');
     var so = new SWFObject(FLASH_PLAYER_URI+"?file="+link_video.href+"&autostart=true&bufferlength=15", "vet-flv", str_plugin_width,str_plugin_height, 7, '#e7e7e7');
     so.addParam('wmode', 'transparent');
     so.write('flash');
     var video_container = document.getElementById('flash');
     video_container.className='media-container';
   }

   /** quicktime video files ****/
   if(link_video.className.indexOf('quicktime')!=-1 || link_video.href.indexOf('.mov')!=-1|| link_video.href.indexOf('.mp4')!=-1){
     var video_container = build_quicktime_media_player(link_video);
   }

   var synopsis = get_synopsis(link_video);

   //for whatever reason, we loose the event handlers from the original synopsis.
   synopsis.getElementsByClassName = document.getElementsByClassName;

   var arr_media_player_links = synopsis.getElementsByClassName('media-player');

   for(i=0;i<arr_media_player_links.length;i++){
       arr_media_player_links[i].onclick=trigger_media_player;
   }

   var synopsis_container = document.getElementById('synopsis');

   for(i=0;i<synopsis_container.childNodes.length;i++){
     synopsis_container.removeChild(synopsis_container.childNodes[i]); //remove the current synopsis if present
   }

   try{  //ie may struggle on this
     synopsis_container.appendChild(synopsis);
   }catch (e){
     synopsis_container.innerHTML = synopsis.innerHTML;
   }

   var media_player = document.getElementById('media-player-wrapper');
   media_player.style.width=str_plugin_width+"px";
   media_player.parentNode.style.width=parseInt(str_plugin_width)+80+"px";
 }

 /*
 * constructs a video player to display windows media files
 *
 *
 *
 */
 function build_ms_media_player(link_video){
    /* build something like
        <object width="320" height="290" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="mediaplayer1">
        <param name="Filename" value="kids.mpg">
        <param name="AutoStart" value="True">
        <param name="ShowControls" value="True">
        <param name="ShowStatusBar" value="False">
        <param name="ShowDisplay" value="False">
        <param name="AutoRewind" value="True">
        <embed type="application/x-mplayer2"
               pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
               width="320" height="290" src="/support/dreamweaver/ts/documents/kids.mpg"
               filename="kids.mpg" autostart="True"
               showcontrols="True" showstatusbar="False"
               showdisplay="False" autorewind="True"></embed>
        </object>
     */

     var str_plugin_class_id = "CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95";
     var str_plugin_type = "application/x-oleobject";

     var str_plugin_height = get_plugin_height(link_video);
     var str_plugin_width = get_plugin_width(link_video);

     var str_video_url = link_video.href;

     clear_active_players();
     var video_container = document.getElementById('windows-media');

     var object_media_player = document.createElement('object');
     object_media_player.setAttribute('id','ms-video');
     object_media_player.setAttribute('width',str_plugin_width);
     object_media_player.setAttribute('height',str_plugin_height);
     object_media_player.setAttribute('classid',str_plugin_class_id);
     object_media_player.setAttribute('type',str_plugin_type);
     object_media_player.setAttribute('url',str_video_url);

     try{ //ie has issues with appendChild and object objects. we handle IE issues in the catch block.

       var param_url = document.createElement('param');
       param_url.setAttribute('Filename',str_video_url);
       object_media_player.appendChild(param_url);

       var param_events = document.createElement('param');
       param_events.setAttribute('Autostart','True');
       object_media_player.appendChild(param_events);

       var param_autostart = document.createElement('param');
       param_autostart.setAttribute('ShowControls','True');
       object_media_player.appendChild(param_autostart);

       var param_uimode = document.createElement('param');
       param_uimode.setAttribute('ShowStatusBar','False');
       object_media_player.appendChild(param_uimode);

       var param_showdisplay = document.createElement('param');
       param_showdisplay.setAttribute('ShowDisplay','False');
       object_media_player.appendChild(param_showdisplay);

       var param_autorewind = document.createElement('param');
       param_autorewind.setAttribute('AutoRewind','True');
       object_media_player.appendChild(param_autorewind);

       var embed_msplayer = document.createElement('embed');
       embed_msplayer.setAttribute('pluginspage',"http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/");
       embed_msplayer.setAttribute('width',str_plugin_width);
       embed_msplayer.setAttribute('height',str_plugin_height);
       embed_msplayer.setAttribute('src',str_video_url);
       embed_msplayer.setAttribute('filename',str_video_url);
       embed_msplayer.setAttribute('autostart','True');
       embed_msplayer.setAttribute('showcontrols','True');
       embed_msplayer.setAttribute('showstatusbar','False');
       embed_msplayer.setAttribute('showdisplay','False');
       embed_msplayer.setAttribute('autorewind','True');
       object_media_player.appendChild(embed_msplayer);

       video_container.appendChild(object_media_player);


     }catch(e){
       try{
         var str_ie_object = '<object  width="'+str_plugin_width+'" height="'+str_plugin_height+'" classid="'+str_plugin_class_id+'" type="'+str_plugin_type+'">';
         str_ie_object = str_ie_object + '<param  name="filename" value="'+str_video_url+'" />';
         str_ie_object = str_ie_object + '<param  name="autostart" value="true" />';
         str_ie_object = str_ie_object + '<param  name="showcontrols" value="true" />';
         str_ie_object = str_ie_object + '<param  name="showstatusbar" value="false" />';
         str_ie_object = str_ie_object + '<param  name="showdisplay" value="false" />';
         str_ie_object = str_ie_object + '<param  name="autorewind" value="true" />';
         str_ie_object = str_ie_object + '<param  name="pluginspage" value="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" />';
         str_ie_object = str_ie_object + '</object>';


         video_container.innerHTML = str_ie_object;
       }
       catch(e){
         //if only JS could log...
       }
     }
     video_container.style.width=str_plugin_width+"px";
     video_container.style.height=str_plugin_height+"px";
     video_container.className = "media-container"; // un hide the player



     return video_container;
 }

 /*
 *
 *
 *
 *
 */
 function build_quicktime_media_player(link_video){
   /* build something like
        <object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="320" height="256" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">
        <param name="src" value="sample.mov">
        <param name="autoplay" value="true">
        <param name="controller" value="true">
        <embed src="sample.mov" width="320" height="256" autoplay="true" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed>
        </object>
     */



     var str_plugin_class_id = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
     var str_codebase = "http://www.apple.com/qtactivex/qtplugin.cab";
     var str_plugin_height = get_plugin_height(link_video);
     var str_plugin_width = get_plugin_width(link_video);
     var str_video_url = link_video.href;

     clear_active_players();
     var video_container = document.getElementById('quicktime');
    

     try{
       var object_media_player = document.createElement('object');
       object_media_player.setAttribute('id','apple-quicktime');
       object_media_player.setAttribute('width',str_plugin_width);
       object_media_player.setAttribute('height',str_plugin_height);
       object_media_player.setAttribute('classid',str_plugin_class_id);
       object_media_player.setAttribute('codebase',str_codebase);

       var param_url = document.createElement('param');
       param_url.setAttribute('src',str_video_url);
       object_media_player.appendChild(param_url);

       var param_events = document.createElement('param');
       param_events.setAttribute('SendPlayStateChangeEvents','true');
       object_media_player.appendChild(param_events);

       var param_autostart = document.createElement('param');
       param_autostart.setAttribute('autoplay','true');
       object_media_player.appendChild(param_autostart);

       var param_uimode = document.createElement('param');
       param_uimode.setAttribute('controller','true');
       object_media_player.appendChild(param_uimode);

       var param_uimode = document.createElement('embed');
       param_uimode.setAttribute('src',str_video_url);
       param_uimode.setAttribute('autostart','true');
       param_uimode.setAttribute('controller','true');
       param_uimode.setAttribute('height',str_plugin_height);
       param_uimode.setAttribute('width',str_plugin_width);
       param_uimode.setAttribute('controller',str_plugin_width);
       param_uimode.setAttribute('pluginspage','http://www.apple.com/quicktime/');
       object_media_player.appendChild(param_uimode);

       video_container.appendChild(object_media_player);
    }
    catch(e){
      try{
         var str_ie_object = '<object  width="'+str_plugin_width+'" height="'+str_plugin_height+'" classid="'+str_plugin_class_id+'" codebase="'+str_codebase+'">';
         str_ie_object = str_ie_object + '<param  name="src" value="'+str_video_url+'" />';
         str_ie_object = str_ie_object + '<param  name="autoplay" value="true" />';
         str_ie_object = str_ie_object + '<param  name="controler" value="true" />';
         str_ie_object = str_ie_object + '</object>';

         video_container.innerHTML = str_ie_object;
       }
       catch(e){

       }
    }

    video_container.style.width=str_plugin_width+"px";
    video_container.style.height=str_plugin_height+"px";

    video_container.className = "media-container"; // un hide the player

    return  video_container;
 }

 /*
  * get the height of plugin by parsing the className
  *
 */
  function get_plugin_height(link){
    var height = "200";
    try{
      str_height = new String(link.className.match(/height [0-9]*/));
      height = str_height.match(/[0-9]*$/);
    }catch(e){

    }
    return height;
  }

 /*
  * get the width of plugin by parsing the className
  *
 */
  function get_plugin_width(link){
    var width = "400";
    try{
      str_width = new String(link.className.match(/width [0-9]*/));
      width = str_width.match(/[0-9]*$/);
    }catch(e){
      
    }
    return width;
  }

  /*
  * get the synopsis of the video by parsing the link's id
  *
 */
  function get_synopsis(link){

    //the link id will be something like "[text]video_[number]"
    var str_video_id = new String();
    var str_id =new String();

    try{
      str_video_id = new String(link.id.match(/video_[0-9]*/));
      str_id = str_video_id.match(/[0-9]*$/);
    }catch(e){

    }

    var synopsis = document.getElementById("synopsis_"+str_id);

    if(synopsis.childNodes[0]!=null){
      synopsis = synopsis.cloneNode(true);
      synopsis.className="";
      return synopsis;
    }
    else{
      return document.createElement('div');
    }
  }


 /*
 * reset all the media players so that they can't bee seen.
 *
 *
 */
 function hide_all_players(){
   var arr_all_players = document.getElementsByClassName('media-container');
   for(i=0;i<arr_all_players.length;i++){
     arr_all_players[i].className="media-container delayed-hide";
   }
   return;
 }

 /*
 *  Clear all players that are currently playing
 *
 *
 *
 */
 function clear_active_players(){
   
   var video_container = document.getElementById('quicktime');
   for(i=0;i<video_container.childNodes.length;i++){
       video_container.removeChild(video_container.childNodes[i]);
   }
   
   video_container = document.getElementById('windows-media');
   for(i=0;i<video_container.childNodes.length;i++){
       video_container.removeChild(video_container.childNodes[i]);
   }

   video_container = document.getElementById('flash');
   for(i=0;i<video_container.childNodes.length;i++){
       video_container.removeChild(video_container.childNodes[i]); 
   }
  
 }


 /** cookie functions *************************/

 function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
 }

 function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
 }

 
 /** position calculation *********************/


 function get_position(elm) {
  for(var zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
  return {x:zx,y:zy}
 }


function switchit(list){
var listElementStyle=document.getElementById(list).style;
if (listElementStyle.display=="none"){
listElementStyle.display="block";
}
else {
listElementStyle.display="none";
}
}




 /** onload event handlers ****************/
 
 window.onload=apply_dom;
