/*************************************/
/* BEGIN ORIGINAL popupcards.js ******/
/*************************************/
var closedPopups = new Array();

function initClosedPopups() {
        try {
       if (closedPopups.length == 0 && window.opener && window.opener.closedPopups) {
      closedPopups = window.opener.closedPopups;
       }
        } catch(e) {
            // opened by a window in a different domain - continue
        }
   for (var i=0;i<closedPopups.length;i++) {
        var p = $("div[id^="+closedPopups[i]+"_z]");
        if (!$(p).hasClass('popupcardModule')) {
                
            $("#h264Iframe_" + popup_name).each(function(i, elem) {        
			if (typeof elem.contentWindow.hideMe == 'function') {
				elem.contentWindow.hideMe(); // run function
            }});
                
            $(p).hide();			
        } else {
            $(p).css({'visibility':'hidden','z-index':'2'});
            
			$(p).children('iframe').each(function(i, elem) {        
				if (typeof elem.contentWindow.hideMe == 'function') {
					elem.contentWindow.hideMe(); 
				}
			});            
        }
		
        $(p).each(function(){
			//only remove div if you're not a module
			if (!$(this).hasClass('popupcardModule') && !$(this).attr('reverse')){
				this.parentNode.removeChild(this);
			}
		});
   }
}

function closePopup( popup_name ) {
    if ( popup_name == '' ) popup_name = 'brc_wrapper';
        closedPopups.push(popup_name);
        var p = $("div[id^="+popup_name+"_z]");
        if (!$(p).length) return;

        if (!$(p).hasClass('popupcardModule')) {
            $("#h264Iframe_" + popup_name).each(function(i, elem) {        
			if (typeof elem.contentWindow.hideMe == 'function') {
				elem.contentWindow.hideMe(); // run function
            }});
            
            $(p).hide();            
		} else {
			$(p).css({'visibility':'hidden','z-index':'2'});
            
			$(p).children('iframe').each(function(i, elem) {        
				if (typeof elem.contentWindow.hideMe == 'function') {
					elem.contentWindow.hideMe(); 
				}
			});                  
		}

    try {
        // advise the flash or quicktime to stop playing
        // (but note that not all flash responds to the StopPlay command)
      $("div[id^=flashplayer_"+popup_name+"_z]").each(function(){
         if (this.StopPlay) {
            this.StopPlay();
         }
      });
        $("div[id^=qtplayer_"+popup_name+"_z]").each(function(){
         if (this.Stop) {
            this.Stop();
         }
        });
    } catch(e) { }

    // delete the object to stop flash audio
    $(p).each(function(){
		//only remove div if you're not a module
        if (!$(this).hasClass('popupcardModule') && !$(this).attr('reverse')){
		    this.parentNode.removeChild(this);
	    }
	});

	$(p).parent().css({'z-index':'2'});
}

function togglePopup( popup_name )
{
    if ( popup_name == '' ) popup_name = 'brc_wrapper';
    var p = $("div[id^="+popup_name+"_z]");
    if (!p.length) return;

    
    var display = p.get(0).style.display;
    if(display=="none" || p.get(0).style.visibility == "hidden") {
      //Tracker.trackPage({"module_name":popup_name, "module_title":popup_title, "module_type":popup_type, "category": "module", "shortTitle":document.title, "lochref":document.location.href});
      openPopup( popup_name);
    }else{
      closePopup(popup_name);
    }

}

function openPopup( popup_name )
{
    if ( popup_name == '' ) popup_name = 'brc_wrapper';
    var p = $("div[id^="+popup_name+"_z]");
	if (!p.length) return;
	
	$(p).each(function(){
        $(this).show();
	    $(this).css({'visibility':"visible",
	                  'z-index':2});
		
	    $(this).children('iframe').each(function(i, elem) {        
			if (typeof elem.contentWindow.showMe == 'function') {
				elem.contentWindow.showMe(); // run function
			}	        
	    });
                
         // TO DO: call OpenTracker for autoplay popups
         //if ($(p).attr('popup_title') && !popup_name.match(/_z$/) ) {
         // trackPlay($(p).attr('popup_title'),'shown');
         //}
    });
	
    $("#h264Iframe_" + popup_name).each(function(i, elem) {
        if (typeof elem.contentWindow.showMe == 'function') {
        elem.contentWindow.showMe();
    }}); 
    
    $(p).parent().css({'z-index':101});
    
    var popup_title= $(p).attr('popup_title');
    var popup_type= $(p).attr('popup_type');
    if(popup_type=='flv' || popup_type=='swf' || popup_type=='qt' || popup_type=='youtube' || popup_type=='h264' || popup_type=='iframe'){
        Tracker.trackPage({"category":"video","video_name":popup_name, "video_title":popup_title, "video_type":popup_type,"lochref":document.location.href});
    }else if(popup_type=='module'){
        Tracker.trackPage({"module_name":popup_name, "module_title":popup_title, "module_type":popup_type, "category": "module", "shortTitle":document.title, "lochref":document.location.href});
    }

}


function bringToTop(popup_name) {
	var re = new RegExp('^' + popup_name + '.*', "m");
    $('.popupcardModule').each(function(){
		if ($(this).attr('id').match(re)) {
			$(this).css('z-index', 9999);
		} else {$(this).css('z-index', '2');}
	});
}

function hideScrollbars() {
    if (navigator.appName != 'Microsoft Internet Explorer') {
	    $("html").css("overflow", "hidden");
	}
}

function showScrollbars() {
    if (navigator.appName != 'Microsoft Internet Explorer') {
	    $("html").css("overflow", "auto");
	}
}

/***********************/
/* BEGIN flash.js ******/
/***********************/

var qtinstalled = 0;
var flashinstalled = 0;
var flashversion = 0;
var flash_overlay_link;
var flash_overlay_link_alt;
var flash_overlay_link_target;
var myParent;

function flashDetect() {
   // This Flash detection code is largely taken from
   //   <quirksmode.org/js/flash.html>
   if (navigator.plugins && navigator.plugins.length) {
      var x = navigator.plugins["Shockwave Flash"];
      if (x) {
         flashinstalled = 2;
         if (x.description) {
            y = x.description;
                                y = y.substring(16,y.indexOf('.'));
            flashversion = parseInt(y);
         }
      } else {
         flashinstalled = 1;
      }

      if (navigator.plugins["Shockwave Flash 2.0"]) {
         flashinstalled = 2;
         flashversion = 2;
      }
   } else if (navigator.mimeTypes && navigator.mimeTypes.length) {
      x = navigator.mimeTypes['application/x-shockwave-flash'];
      if (x && x.enabledPlugin)
         flashinstalled = 2;
      else
         flashinstalled = 1;
   } else {
      // IE detection
      for(var i=10; i>0; i--){
         try {
            var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
            flashinstalled = 2;
            flashversion = i;
            break;
         } catch(e) { }
      }
   }
}

function insertClicktoPlay(popup_name) {
   var pimg;
   if (flash_previewimg && flash_previewimg != "") {
      pimg = '<img src="' + flash_previewimg + '" width="' + flash_width + '" height="' + flash_height + '" alt="Click to play" title="Click to play" border="0">'
   } else {
      pimg = '<span style="font-family:Verdana,sans-serif;font-size:14px;line-height:42px;">Click here to play</span>';
   }

   var text = '<div id="flashclick_'+popup_name+'" style="width: ' + flash_width + 'px; height: ' + flash_height + 'px; text-align:center; display:table-cell; vertical-align:middle;"><a href="javascript:insertFlashObject(\'flashclick_'+popup_name+'\',\'' + popup_name + '\')"' + (ot_title ? ' onclick="trackPlay(\'' + ot_title +'\',\''+ot_section+'\')"' : '') + '>' + pimg + '</a></div>';

   myParent = document.getElementById(popup_name);
   var inner = $("#"+popup_name+" .popupcardInner");
   if (inner.length > 0) myParent = inner.get(0);
   myParent.innerHTML = text;
}

function insertFlashObject(popup_name) {
   if (!flash || !flash_minversion) return;

   flashDetect();
   if (flashinstalled != 2 || flashversion < flash_minversion) {
      closePopup(popup_name);
   } else {
       var text = '';
       if (flash_overlay_link != undefined) {
      if (flash_overlay_link_target == undefined)
          flash_overlay_link_target = '_blank';
      if (flash_overlay_link_alt == undefined)
          flash_overlay_link_alt = 'Go to '+flash_overlay_link;
      text = '<div style="position:absolute; z-index:20;">'
      + '<a href="'+flash_overlay_link+'" target="'
      + flash_overlay_link_target
      + '">'
      + '<img src="/include/icons/1ptrans.gif" '
      + 'width="'+flash_width+'" height="'+flash_height+'" '
      + 'border="0" alt="'+flash_overlay_link_alt+'">'
      + '</a></div>';
       }
      text += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + flashversion + ',0,0,0" width="' + flash_width + '" height="' + flash_height + '" id="flashplayer_' + popup_name + '" align="middle">'
      text += '<param name="allowScriptAccess" value="always" />'
      text += '<param name="movie" value="' + flash + '" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="' + flash + '" menu="false" quality="high" wmode="transparent" width="' + flash_width + '" height="' + flash_height + '" name="flashplayer_' + popup_name + '" swLiveConnect="true" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>'
      text += '</object>'

      myParent = document.getElementById(popup_name);
      var inner = $("#"+popup_name+" .popupcardInner");
      if (inner.length > 0) myParent = inner.get(0);
      myParent.innerHTML = text;
   }
}

function doFlashMovie(popup_name) {
   if (!flash_movie || !flash_minversion) return;

   flashDetect();
   if (flashinstalled != 2 || flashversion < flash_minversion) {
      closePopup(popup_name);
   } else {
      var ver = (flashversion > 8) ? 8 : flashversion
      var q = flash_movie.indexOf('?');
      if (q >= 0) {
         flash_movie = flash_movie.substring(0,q);
      }
      flash = DocumentProperties.getDocumentUrl() + "/include/mm/fl" + ver + "player.swf?file=" + flash_movie;
      doFlash(popup_name);
   }
}

function doFlash(popup_name) {
   if (!flash || !flash_minversion) return;

   flashDetect();
   if (flashinstalled != 2 || flashversion < flash_minversion) {
      closePopup(popup_name);
   } else {
      // Now show the right stuff
      if (flash_autoplay)  insertFlashObject(popup_name);
      else insertClicktoPlay(popup_name);
   }
}


/*****************************/
/* BEGIN quicktime.js ********/
/*****************************/

var qtinstalled = 0;
var noshow = 0;

function qtDetect() {
   // The Quicktime code was heavily modified from
   //   <apple.com/quicktime/technologies/interactivity/qtjavascript.html>
   if (navigator.plugins && navigator.plugins.length) {
      x = navigator.plugins;
      for (i=0; i<x.length; ++i) {
         if (x[i].name.indexOf("QuickTime") >= 0)
            qtinstalled = 2;
      }
   } else {
      // IE detection.
      try {
         var qt = new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1");
         qtinstalled = 2;
      } catch(e) { }
   }
}

function qtInsertClicktoPlay( popup_name ) {
   var pimg;

   if (qt_previewimg && qt_previewimg != "") {
      pimg = '<img src="' + qt_previewimg + '" width="' + qt_width + '" height="' + qt_height + '" alt="Click to play" title="Click to play" border="0">'
   } else {
      pimg = "Click here to play";
   }

   text = '<div id="qtclick_'+popup_name+'" style="width: ' + qt_width + 'px; height: ' + qt_height + 'px;"><a href="javascript:insertQuicktimeObject(\'qtclick_'+popup_name+'\')" onclick="trackPlay(\'' + ot_title + '\',\'' + ot_section + '\')">' + pimg + '</a></div>';

   myParent = document.getElementById(popup_name);
   var inner = $("#"+popup_name+" .popupcardInner");
   if (inner.length > 0) myParent = inner.get(0);
   myParent.innerHTML = text;

}

function qtInsertQuicktimeObject(popup_name) {
   if (!qt) return;

   qtDetect();
   if (qtinstalled != 2) {
      closePopup(popup_name);
   } else {
      var text = '<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="' + qt_width + '" HEIGHT="' + qt_height + '" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" ID="blowinmovie">'
      text += '<PARAM name="SRC" VALUE="' + qt + '">'
      text += '<PARAM name="AUTOPLAY" VALUE="true">'
      text += '<PARAM name="CONTROLLER" VALUE="true">'
      text += '<PARAM name="ENABLEJAVASCRIPT" VALUE="true"><EMBED SRC="' + qt + '" WIDTH="' + qt_width + '" HEIGHT="' + qt_height + '" AUTOPLAY="true" CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/qt/download/"></EMBED></OBJECT>'

      myParent = document.getElementById(popup_name);
      var inner = $("#"+popup_name+" .popupcardInner");
      if (inner.length > 0) myParent = inner.get(0);
      myParent.innerHTML = text;
   }
}

function doQuicktime( popup_name ) {
   if (!qt) return;

   qtDetect();
   if (qtinstalled != 2) {
      closePopup( popup_name );
   } else {
      // Now show the right stuff
      if (qt_autoplay) qtInsertQuicktimeObject( popup_name);
      else qtInsertClicktoPlay( popup_name );
   }
}

function showSlideShow(me) {
   $(me).onShow();
}

function hideSlideShow(me) {
	$(me).onHide();
}



/*###############Copyright##################
 *####   Copyright 2008 Texterity, Inc  ####
 *###############Copyright##################
 */

