//#### BEGIN SETTINGS FOR THE FOLLOWING FUNCTIONS ####//

//required Flash version for al Flash objects used in WerkenBij
var requiredMajorVersion = 9;// Major version of Flash required
var requiredMinorVersion = 0;// Minor version of Flash required
var requiredRevision = 0;// Revision version of Flash required

//Overheids Media Player Settings for Testimonial pagina & Landingspagina
var mediaplayerAutoStart = true; //start playing video after page load
var mediaplayerFile = "http://wwwp/Images/mediaplayer.swf"; //location of Flash object of Overheids Media Player

//#### END SETTINGS FOR THE FOLLOWING FUNCTIONS ####//


//#### BEGIN VARIOUS FUNCTIONS (USED ON MORE THEN 1 PLACE) ####//

// flash object generator
function SVB_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, "", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );

    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in ret.objAttrs)
  			str += i + '="' + ret.objAttrs[i] + '" ';
  		for (var i in ret.params)
  			str += '><param name="' + i + '" value="' + ret.params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in ret.embedAttrs)
  			str += i + '="' + ret.embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    return str;
}

// generates code for flash download link
function getFlashDownloadLink(showImage){

  var title = "Installeer Adobe Flash Speler";
  var alt = "Installeer Adobe Flash Speler";
  var msg = "Er is een video voor dit onderdeel aanwezig, installeer de Flash plug-in van Adobe om deze te zien."

  if(showImage){
    
    return "<a href=\"http://get.adobe.com/flashplayer\" class=\"download_flash\" title=\"" + title + "\"><img src=/Images/get_flash_player.gif\" alt=\"" + alt + "\" title=\"" + title + "\" /><span>" + msg + "</span></a>";

  }else{

    return "<a href=\"http://get.adobe.com/flashplayer\" class=\"download_flash\" title=\"" + title + "\"><span>" + msg + " <strong>Download plug-in</strong></span></a>";
  }
}

// creates SRT location with the testimonial url
function getSrtLocation(strUrl){

  strUrl = strUrl.split("#")[0];
	
  if(strUrl.search(/\?/) != -1){	
    strUrl += "&view=srt";	
  }else{		
    strUrl += "?view=srt";
  }
	
  return strUrl.replace(/\?/g,"%3F").replace(/&/g,"%26");
}

//#### END VARIOUS FUNCTIONS (USED ON MORE THEN 1 PLACE) ####//


//#### BEGIN ACCORDEON FUNCTIONS ####//

// creates XML location with the testimonial url
function getAccordeonXMLLocation(){

  var strXMLUrl = document.location.href.split("#")[0];  

  if(strXMLUrl.search(/\?/) != -1){	
    strXMLUrl += "&view=accordeon";	
  }else{		
    strXMLUrl += "?view=accordeon";
  }
	
  return strXMLUrl.replace(/\?/g,"%3F").replace(/&/g,"%26");
}

$(document).ready(function(){

  // only for WerkenBij Home with an accordeon
  $("body.ptWerkenBijHome #accordeon").each(function(){

    var container  = $(this);

    // The first child of accordeon DIV is a script element containing the data object as JSON
    var data = eval("(" + container.children()[0].innerHTML + ")");
	
    // Check if user has the required flash version 
    if (DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision)) {

      // if we've detected an acceptable version
      // embed the Flash Content SWF when all tests are passed
      var mediaObj = SVB_FL_RunContent(
            "src", "http://wwwp/Images/accordeon.swf?XMLPath=" + getAccordeonXMLLocation(),
            "width", "984",
            "height", "270",
            "align", "middle",
            "quality", "high",
            "bgcolor", "#ffffff",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "codebase", "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab",
            "pluginspage", "http://get.adobe.com/flashplayer",
            "wmode", "transparent"
      );  

      $(this).prepend(mediaObj);

    }else{
        
      // add alternative hyperlinks + images to DOM
      for(i in data){

        if(data[i].img != ""){
          $(this).append("<a href=\"" + data[i].href + "\"><img src=\"" + data[i].img + "\" alt=\"" + data[i].alt + "\" /></a>");
        }
      }
        
      // flash download
      $("body.ptWerkenBijHome #media_container").append(getFlashDownloadLink(0));
    }
  });

});	

//#### END ACCORDEON FUNCTIONS ####//


//#### BEGIN LANDINGSPAGINA VIDEO FUNCTIONS ####//

$(document).ready(function(){

  // only for Testimonial pages with a video
  $("body.ptLanding #media").each(function(){

    var container  = $(this);

    //only if the media DIV contains instructions for the video player
    if(container.children().length > 1){

      // The first child of testimonial teaser DIV is a script element containing the data object as JSON
      var data = eval("(" + container.children()[0].innerHTML + ")");
    
      // Check if user has the required flash version 
      if (DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision)) {

        // resize container, to add space for bar with controls (+20px)
        $(this).height($(this).height() + 20);  
      
        // if we've detected an acceptable version
        // embed the Flash Content SWF when all tests are passed
        var movie = new GovVid("testimonial_" + data.showVideo, "480", "270");     
        movie.addImage(data.img);
        movie.addMovie(data.flv); //path calculated from flash file location, or url
        movie.addCaption("flv",getSrtLocation(data.srt)); //caption for flv file
        movie.write("media"); // writes movie to divID

      }else{
      
        // alternative image
        $(this).prepend("<img src=\"" + data.img + "\" alt=\"" + data.alt + "\" />");

        //flash download
        $("body.ptLanding #landingspagina_media_container").append(getFlashDownloadLink(0));
      } 
    }
  });
});

//#### END LANDINGSPAGINA VIDEO FUNCTIONS ####//
  

//#### BEGIN TESTIMONIAL FUNCTIONS ####//

$(document).ready(function(){

  // only for Testimonial pages with a video
  $("body.ptTestimonial #media").each(function(){

    var container  = $(this);

    //only if the media DIV contains instructions for the video player
    if(container.children().length > 1){

      // The first child of testimonial teaser DIV is a script element containing the data object as JSON
      var data = eval("(" + container.children()[0].innerHTML + ")");
    
      // Check if user has the required flash version 
      if (DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision)) {

        // resize container, to add space for bar with controls (+20px)
        $(this).height($(this).height() + 20);
      
        // don't start player if text of the video was requested by URL query
        if(document.location.href.match("#video_text")){

          mediaplayerAutoStart = false;
        }
      
        // if we've detected an acceptable version
        // embed the Flash Content SWF when all tests are passed
        var movie = new GovVid("testimonial_" + data.showVideo, "480", "270");     
        movie.addImage(data.img);
        movie.addMovie(data.flv); //path calculated from flash file location, or url
        movie.addCaption("flv",getSrtLocation(data.srt)); //caption for flv file
        movie.write("media"); // writes movie to divID	

      }else{
      
        // alternative image
        $(this).prepend("<img src=\"" + data.img + "\" alt=\"" + data.alt + "\" />");

        //flash download
        $("body.ptTestimonial #media_container").append(getFlashDownloadLink(0));
      }
    }
  });


  // only for Testimonial pages with a video transcript
  $("body.ptTestimonial #maincontent #video_text").each(function(){

    var video_text = $(this);

    // The first child of the video text DIV is a script element containing the data object as JSON
    var data = eval("(" + video_text.children()[0].innerHTML + ")");

    // Hide text and show hyperlink when the user has the required Flash plugin
    if (DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision)) {
    
      // Hide video text if this view wasn't requested by URL query
      if(!document.location.href.match("#video_text")){
        
        // hide text
        video_text.toggle();
        var toggler = $("<div class='video_text_toggler'><p><a href='#'>" + data.textLink + "</a></p></div>");

      }else{ 

        var toggler = $("<div><p><a class='follow' href='#'>" + data.videoLink + "</a></p></div>");
      }

      // Wire up the toggling behaviour
      toggler.click(function(){

        video_text.toggle();
        
        if (video_text.is(":visible")){
          $("a", toggler).text(data.videoLink);        
        }else{
          $("a", toggler).text(data.textLink);       
        }
        return false;           		    
      });

      // Inject the toggler after the video text DIV
      video_text.after(toggler);
    }

  });

});

//#### END TESTIMONIAL FUNCTIONS ####//


//#### BEGIN TESTIMONIAL TEASER FUNCTIONS ####//

$(document).ready(function(){

  // find all the testimonial teasers in the page
  $("div.testimonial_teaser").each(function(){

    var container  = $(this);

    // The first child of testimonial teaser DIV is a script element containing the data object as JSON
    var data = eval("(" + container.children()[0].innerHTML + ")");
    
    // Check if user has the required flash version 
    if (DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision)) {
      
      // if we've detected an acceptable version
      // embed the Flash Content SWF when all tests are passed
      var mediaObj = SVB_FL_RunContent(
            "src", "http://wwwp/Images/testimonial_teaser.swf?XMLPath=/int//system/xml/TestimonialTeaserXML.jsp&amp;showVideo=" + data.showVideo,
            "width", "252",
            "height", "252",
            "align", "middle",
            "quality", "high",
            "bgcolor", "#ffffff",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "codebase", "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab",
            "pluginspage", "http://get.adobe.com/flashplayer",
            "wmode", "transparent"
      );

    }else{
      
      // alternative image + Flash download link
      var mediaObj = "<a href=\"" + data.href + "\"><img src=\"" + data.img + "\" alt=\"" + data.alt + "\" /></a>" + getFlashDownloadLink(1);
    }

    $(this).prepend(mediaObj);

  });
});

//#### END TESTIMONIAL TEASER FUNCTIONS ####//