function getURLParam(strURL, strParamName){
  this.strReturn = "";
  this.strURL = strURL;
  if ( strURL.indexOf("?") > -1 ){
    var strQueryString = strURL.substr(strURL.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        this.strReturn = aParam[1];
        break;
      }
    }
  }
  return this.strReturn;
}

function mediaPlayerController() {
    
    var videos = $$('.play-video');
    videos.each(function(item){ 
    item.addEvent('click', function(){
      
      //var videoPath = getURLParam(item.href, 'video');
      //var posterPath = getURLParam(item.href, 'poster');
      
      var videoContainer = new Element('div', {'id':'mbVideo'});
      var p = new Element('p');
      //var downloadLink = new Element('a', {'href':item.href, 'text':'Download video (mp4)', 'class': 'download'});
      
      var obj = new Swiff('resources/video/player.swf', {
        id: 'swfPlayer',
        width: 480,
        height: 290,
        params: {
          wmode: 'opaque',
          bgcolor: '#fff',
          allowfullscreen: 'true',
          movie: 'resources/video/player.swf',
          quality: 'high',
          allowScriptAccess: 'sameDomain'
        },
        vars: {
          file: item.href,
          //image: posterPath,
          autostart: 'true',
          backcolor: '000000',
          frontcolor: 'FFFFFF',
          lightcolor: '888888',
          volume: 100
        }
      });
      
      obj.inject(videoContainer);
      //downloadLink.inject(p);
      p.inject(videoContainer);
      
      mediaBoxOverlay.show(videoContainer, {cloneContent: false});
      
      return false;
    });
    
  });
  
  if (videos.length > 0) var mediaBoxOverlay = new Overlay( { destroyContent: true } );
}

function menuHandler() {
  var topLevelMenuItems = $$('#navigation ul li.drop');
  topLevelMenuItems.each(function(item){
    item.addEvent('mouseover', function(){
      if(this.getChildren('ul')) {
        if(this.getChildren('ul').getStyle('display') == 'none') {
          this.getChildren('ul').setStyle('display','block');
        } else {
          this.getChildren('ul').setStyle('display','none');
        }
      }
    });
  });
}


window.addEvent('domready', function() {
  if(Browser.Engine.trident && Browser.Engine.version == 4) menuHandler();
  
  if ($$('#slider.motion-slider').length > 0) {
    var spotlight = new Glider('slider', {duration:0.5, frequency:15.0, manualGlide:true, autoGlide:false });
}
if ($$('#slider.web-slider').length > 0) {
    var spotlight = new Glider('slider', { duration: 0.5, frequency: 15.0, manualGlide: true, autoGlide: true });
}
  if ($$('#slider.print-slider').length > 0) {
    var spotlight = new Glider('slider', {duration:0.5, frequency:15.0, manualGlide:false, autoGlide:true });
  }
  if ($$('#slider.testimonial-slider').length > 0) {
    var spotlight = new Glider('slider', {duration:0.5, frequency:17.0, manualGlide:false, autoGlide:true });
  }
  
  var controls = $('spotlight-controls');
  if  (controls) {

    controls.innerHTML = '<a class="prev left" href="#" style="text-decoration:none;border-bottom:1px dotted #01acc0;padding-top:0px;marigin:0px;">Previous</a>&nbsp&nbsp;<a class="next right" href="#" style="text-decoration:none;border-bottom:1px dotted #01acc0;">Next</a>';
    controls.getFirst('.next').addEvent('click', function() { spotlight.stop();spotlight.next();return false; });
    controls.getFirst('.prev').addEvent('click', function() { spotlight.stop();spotlight.previous();return false; });

}

    var controls = $('spotlight-controls-testimonials');

    if (controls) {

        controls.innerHTML = '<a class="prev left" href="#" style="text-decoration:none;border-bottom:1px dotted #01acc0">Previous</a>&nbsp&nbsp;<a class="next right" href="#" style="text-decoration:none;border-bottom:1px dotted #01acc0">Next</a>';

        controls.getFirst('.next').addEvent('click', function() { spotlight.stop(); spotlight.next(); return false; });

        controls.getFirst('.prev').addEvent('click', function() { spotlight.stop(); spotlight.previous(); return false; });

    }
  
  mediaPlayerController();



});



function imageDragBlock(imageCount) {

    for (i = 1; i <= imageCount; i++) {

        var imageNum = "image" + i

        document.getElementById(imageNum).ondragstart = function() { return false; }

    }

}


