   var swf = '/swf/mediaplayer.swf';
   var media = {'player': '/swf/longtailvideo/player.swf',
		    'path': { CDN: 'http://d2vg7zx9grf27a.cloudfront.net',
				  internal: '/downloads/index'
				},
		    'skin': { 'default': "",
				  external: '/swf/longtailvideo/skins/glow.zip'
				},
		    'background': { 'default': '/img/internal/videoscreen.jpg',
					  'wide': '/img/internal/VideoScreen672x358.jpg'
					},
		    'stretching': 'fill',
		    'controlbar': { 'default': 'bottom',
					  external: 'over'
					}
		   };

   var swf_background = '/img/internal/videoscreen.jpg';
   var swf_background_wide = '/img/internal/VideoScreen672x358.jpg';
   var swf_flowplayer = '/swf/flowplayer.commercial-3.2.2.swf';
   var CDN_path = "http://d2vg7zx9grf27a.cloudfront.net";
   var flowplayer_keys = {'nicheprofitclassroom.com' : '#$c6d97b5e0bedbcd3552'};

// JavaScript Document
function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function isDefined(value)
{
  return typeof(value) != "undefined";
}
function popupWindow(url, width, height, scrolling, top, left, resizable)
{
   //var top = ($(window).height() - height) / 2;
   //var left = ($(window).width() - width) / 2;

   var left = (isDefined(left) || left != null ? left : (screen.width  - width)/2);
   var top = (isDefined(top) || top != null  ? top : (screen.height - height)/2);
   resizable  = isDefined(resizable) ? resizable : 0;

   params = ' top=' + top +
		',left=' + left +
		',width=' + width +
		',height=' + height +
		',toolbar=no' +
		',location=no' +
		',scrollbars=' + (isDefined(scrolling) && scrolling != null ? 'yes' : 'no') +
		',resizable=' + resizable;

   var win = window.open(url, 'general', params);
   if (window.focus) {win.focus()}

   return win;
}
function initAddVideoClass() {
	function addVideoClass(e) {
		YAHOO.util.Dom.removeClass (YAHOO.util.Dom.getElementsByClassName ('videoLinkClicked'), 'videoLinkClicked');
		YAHOO.util.Dom.addClass (this, 'videoLinkClicked');
	}
	YAHOO.util.Event.addListener (YAHOO.util.Dom.getElementsByClassName ('videolink'), 'click', addVideoClass);
}

function centerwindow(w,h) {
     var winw = (screen.width - w) / 2;
     var winl = (screen.height - h) / 2;
	 self.moveTo(winw,winl);
} 

function flashOff() 
{
		var flash = document.getElementsByTagName('embed');
		for (var i=0; i< flash.length; i++) {
			flash[i].style.display = 'none';
		}
}
	
function flashOn() 
{
		var flash = document.getElementsByTagName('embed');
		for (var i=0; i< flash.length; i++) {
			flash[i].style.display = 'block';
		}
}

function npcpop(poplocation,windowName,windowProperties,w,h) 
{
	var winw = 'screenX=' + (screen.width - w) / 2;
	var winl = 'screenY=' + (screen.height - h) / 2;
	winpopprop = windowProperties + ',' + winl + ',' + winw;
	window.open(poplocation,windowName,winpopprop);	
}


/* Code for drop down */

	var DDSPEED = 10;
	var DDTIMER = 15;
	
	// main function to handle the mouse events //
	function ddMenu(id, d)
	{
		var h = document.getElementById(id);
	  	var c = document.getElementById(id + '-1');
	  	clearInterval(c.timer);
	  	if(d == 1)
	  	{
			$("#" + c.id).show();
			clearTimeout(h.timer);
	  		if (c.maxh && c.maxh <= c.offsetHeight) 
				return;
			else if(!c.maxh) 
			{	
		  		$("#" + c.id).css({ "display": 'block'
						  	, "height": '265px'
						  	});

	  			c.maxh = c.offsetHeight;
		  		$("#" + c.id).css({ "height": '0px'});

		  		flashOff();
			}
			el = h;
		
			var left = 0;
		
			while (el && el.nodeType == 1 && el !== document.documentElement) 
			{
				left += el.offsetLeft;
				el = el.offsetParent;
			}

//			if ((navigator.appVersion.indexOf("MSIE 7") > 1) || (navigator.appVersion.indexOf("MSIE 6") > 1))
//				left += 175;
		
			c.style.left = left+'px';
		
			c.timer = setInterval(function(){ddSlide(c,1);}, DDTIMER);
			flashOff();
	 	}
	 	else 
	 	{
			h.timer = setTimeout(function(){ddCollapse(c);}, 50);
	 	}
	}
	
	// collapse the menu //
	function ddCollapse(c)
	{
	  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
	  flashOn()

	}
	
	// cancel the collapse if a user rolls over the dropdown //
	function cancelHide(id)
	{
	  var h = document.getElementById(id);
	  var c = document.getElementById(id + '-1');
	  clearTimeout(h.timer);
	  clearInterval(c.timer);
	  flashOff()
	  if(c.offsetHeight < c.maxh)
		c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
	}
	
	// incrementally expand/contract the dropdown and change the opacity //
	function ddSlide(c, d)
	{
	  var currh = c.offsetHeight;
	  var dist;
	  if(d == 1)
		dist = (Math.round((c.maxh - currh) / DDSPEED));
	  else
		dist = (Math.round(currh / DDSPEED));

	  if(dist <= 1 && d == 1)
		dist = 1;

	  $("#" + c.id).css({ 
				   "opacity": currh / c.maxh,
				   "filter": 'alpha(opacity=' + (currh * 100 / c.maxh) + ')',
				   "height": currh + (dist * d) + 'px'
				  }
				 );

		if (d == -1)
		{
			if (currh > 0 && currh <= 4)
			{
				$("#" + c.id).hide();
				clearInterval(c.timer);
			}
		}
		if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1))
		{
			clearInterval(c.timer);
		}


	}

function removeVideoSelect(link)
{

   $(".VideoDirectory a").each
   (
	function()
	{
		$(this).removeClass("Selected");
	}
   );
   $(link).addClass("Selected");
}

/** Insert an embedded video inside a div */
function embedVideo(divId, videoName, width, height)
{
   var ext = videoName.indexOf(".") == -1 ? ".flv" : "";

   html = '<embed ' +
	    '	style="clear: both;" ' +
	    '	src="' + swf + '" ' +
	    '	width="' + width + '" ' +
	    '	height="' + height + '" ' +
	    '	allowscriptaccess="always" ' +
	    '	allowfullscreen="true" ' +
	    ' wmode="transparent"' +
	    '	flashvars="file=/downloads/index/' + videoName + ext + '&image=' + (width > 650 ? swf_background_wide : swf_background) + '" align="middle"> ' +
	    '</embed>';

   $('#' + divId).html(html);
}
function embedVideo2(divId, videoTitle,subTitle,videoName, width, height) 
{	
   html = '<div class="Header">' +
	    '<h2 class="videoheader"><strong>' + videoTitle + '</strong></h2>' +
	    '<div class="TextRight" id="subTitle">' + subTitle + '</div>' +
	    '</div>' +
	    '<div class="VideoBox1"><embed ' + ' style="clear: both;" ' + 'src="' + swf + '" ' + 'width="' + width + '" ' +'	height="' + height + '" ' + ' allowscriptaccess="always" ' + ' allowfullscreen="true" ' + 'flashvars="file=/videos/index/' + videoName + '.flv&image=' + swf_background + '" align="middle" wmode="transparent"> ' + '</embed>' +
	    '</div>'+
	    '<div style="padding:5px;"></div>'+
          '<div class="ClearFloat"></div>'+	
	    '</div>';

   $('#' + divId).html(html);
}
function extractExtension(value)
{
   result = "";
   ext = value.split(".");
   if (ext.length > 1)
   {
	result = ext[ext.length - 1];
   }
   return result;
}
function playerConfig(object)
{
   var config = {};
   config.id = $(object).attr("id");
   config.player = $(object).hasAttr("player") ? $(object).attr("player") : media.player;
   config.isExternal = $(object).hasAttr("external");

   config.file = $.trim($(object).attr("file"));
   if (config.file.length > 0 && config.file.substr(0, 1) != "/")
   	config.file = (config.isExternal ? media.path.CDN : media.path.internal) + "/" + config.file;
   config.autoStart = $(object).hasAttr("auto");
   config.width = $(object).hasAttr("width") ? $(object).attr("width") : $.empty;;
   config.height = $(object).hasAttr("height") ? $(object).attr("height") : $.empty;
   config.image = $(object).hasAttr("image") ? $(object).attr("image") : $.empty;
   config.stretching = $(object).hasAttr("stretch") ? $(object).attr("stretch") : media.stretching;
   config.skin = $(object).hasAttr("skin") ? $(object).attr("skin") : (config.isExternal ? media.skin.external : media.skin["default"]);
   config.controlbar = $(object).hasAttr("bar") ? $(object).attr("bar") : (config.isExternal ? media.controlbar.external : media.controlbar["default"]);
   config.flashvars = $(object).hasAttr("vars") ? $(object).attr("vars") : $.empty;

   return config;
}
function setupPlayer(config)
{
   if (!(typeof jwplayer == 'undefined'))
   {
	jwplayer(config.id).setup
	(
		{
			flashplayer: config.player, 
			file: config.file,
			image: config.image,
			autostart: config.autoStart,
			width: config.width,
			height: config.height,
			skin: config.skin,
			controlbar: config.controlbar,
			flashvars: config.flashvars,
			stretching: config.stretching
		}
	);
   }
}
function loadPlayer(id, video, autoPlay)
{
   var ext = video.indexOf(".") == -1 ? ".flv" : $.empty;
   autoPlay = $.isDefined(autoPlay) ? autoPlay : true;

   jwplayer(id).load(media.path.internal + '/' + video + ext);

   if (autoPlay)
	jwplayer(id).play();
}
function activatePlayer()
{
   var domain = location.host.split(".")[1] + "." + location.host.split(".")[2];
   var video_url = CDN_path + "/" + $("#player").attr("url");
   var autoPlay = $("#player").attr("auto") == null ? true : $("#player").attr("auto").toLowerCase() == "true";

   $f("player", {src: swf_flowplayer, cachebusting: true}, 
		    { clip: {
					url: video_url,
					autoPlay: autoPlay,
					autoBuffering: true,
					onBegin : function() 
						    {
							// provide a Player event listener
							this.unmute();  
							this.setVolume(100);// set volume property 
						    }
				},
			key: flowplayer_keys[domain],
			plugins: 
				{
					controls: 
					{ 
						autoHide: 'always',
						hideDelay: 1000,
						time: false
					}
				}
			}
	);
}
function setupGeneralBox(object)
{
   var width = parseInt($(object).attr("width"));
   var height = $(object).hasAttr("height") ? parseInt($(object).attr("height")) : $(window).height() - 15;

   var scrolling = $(object).hasAttr("scrolling") ? $(object).attr("scrolling") : "no" ;
   var title = $(object).hasAttr("title") ? $(object).attr("title") : $.empty;
   var titleShow = title != "";
   var centerOnScroll = $(object).hasAttr("centerOnScroll");
   var padding = $(this).hasAttr("padding") ? parseInt($(this).attr("padding")) : 0;
   var margin = $(this).hasAttr("margin") ? parseInt($(this).attr("margin")) : 0;

   if (!(typeof $.fancybox == 'undefined'))
   {
	$(object).fancybox
	(
		{
			'type' : 'iframe',
			'titleShow' : titleShow,
			'title' : title,
			'autoScale' : false,
			'centerOnScroll' : centerOnScroll,
			'width' : width,
			'height' : height,
			'hideOnOverlayClick' : false,
			'scrolling' : scrolling,
			'padding' : padding,
			'margin' : margin,
			'onComplete' : function()
					   {
						if ($("#fancybox-wrap").height() > height)
						{
							offset = $("#fancybox-wrap").offset();
							$("#fancybox-wrap").css({'position' : "absolute", 'top' : offset.top - 25});
						}
					   },
			'onStart'	: function ()
					  {
						//$.blockMessage.show2({element: "#fancybox-outer", message: 'Please wait while page is loaded'});
					  },
			'onComplete': function () 
					  {
						//$.blockMessage.hide("#fancybox-content");
					  },
			'onClosed'	: function () 
					  {
						if(typeof closeGeneralWindow == 'function') 
						{ 
							closeGeneralWindow(); 
						}
					  }
		}
	);
   }
}
function setupPreload(object)
{
   if($(object).attr("src") != null)
   {
	var ext = extractExtension($(object).attr("src"));
	if (ext != "")
	{
		MM_preloadImages( $(object).attr("src"), $(object).attr("src").replace("." + ext, "-on." + ext));
	}
   }
}
function setupMouseover(object)
{
   if($(object).attr("src") != null)
   {
	var ext = extractExtension($(object).attr("src"));
	$(object).hover
	(
		function()
		{	
			$(object).attr("src", $(object).attr("src").replace("." + ext, "-on." + ext));
		},
		function()
		{
			$(object).attr("src", $(object).attr("src").replace("-on." + ext, "." + ext));
		}
	);
   }
}
$(document).ready
(
	function()
	{
		if (navigator.appName.toLowerCase() == "netscape")
			$("embed").attr("wmode", "opaque").wrap('<div></div>');
		else
		{
			// IE
			var embedTag;
			$("embed").each
			(
				function(i) 
				{
					embedTag = $(this).attr("outerHTML");
	        			if ((embedTag != null) && (embedTag.length > 0)) 
					{
	            			embedTag = embedTag.replace(/embed /gi, "embed wmode=\"opaque\" ");
	            			$(this).attr("outerHTML", embedTag);
	        			}
	        			// This "else" was added
	        			else 
					{
	            			$(this).wrap("<div></div>");
	        			}
	    			}
			);
		}
		$(".a_iframe_box").each
		(
			function() 
			{
				$(this).click
				(
					function()
					{
						//TINY.box.show({iframe:'/my_account/credit_card', width:830, height:500, animate: true, boxid:'frameless_right'});
						var params = {animate: true};
						var boxType = $(this).attr("box_type") == null ? "iframe" : $(this).attr("box_type").toLowerCase();
						var url = $(this).attr("url") == null ? null : $(this).attr("url");
						var contenId = $(this).attr("content_id") == null ? null : $(this).attr("content_id");
						var top = $(this).attr("top") == null ? null : parseInt($(this).attr("top"));
						var left = $(this).attr("left") == null ? null : parseInt($(this).attr("left"));
						var width = parseInt($(this).attr("width"));
						var height = $(this).attr("height") == null ? $(window).height() - 15: parseInt($(this).attr("height"));
						var animate = $(this).attr("animate") == null ? true : $(this).attr("animate");
						var boxId = $(this).attr("boxid") == null ? "frameless_right" : $(this).attr("boxid");

						switch (boxType)
						{
							case "html":
								params[boxType] = $("#" + contentId).length > 0 ? $("#" + contentId).html() : "";
							break;
							default:
								params["iframe"] = url;
							break;
						}
						if (top != null) params["top"] = top;
						if (left != null) params["left"] = left;
						if (width != null) params["width"] = width;
						if (height != null) params["height"] = height;
						if (animate != null) params["animate"] = animate;
						if (boxId != null) params["boxid"] = boxId;

						TINY.box.show(params);
					}
				);
			}
		);
		if (!(typeof $.fancybox == 'undefined'))
		{
			$(".a_flash_video").click
			(
				function() 
				{
					width = parseInt($(this).attr("width"));
					height = parseInt($(this).attr("height"));
	
					if ($(this).hasAttr("background"))
						swf_background = "/img/internal/" + $(this).attr("background");
	
					video = $(this).attr("video");
					vars = 'file=/downloads/index/' + video + '&amp;image=' + swf_background;
					$.fancybox({
							'padding'		: 0,
							'autoScale'		: false,
							'centerOnScroll'	: true,
							'transitionIn'	: 'none',
							'transitionOut'	: 'none',
							'width'		: width,
							'height'		: height,
							'href'		: swf.replace(new RegExp("watch\\?v=", "i"), 'v/'),
							'type'		: 'swf',
							'swf'			: {'wmode'	: 'transparent', 
										   'allowfullscreen'	: 'true',
										   'flashvars' : vars
										  },
							'onStart'		: function () {flashOff();},
							'onClosed'		: function () {flashOn();}
					       });
	
					return false;
				}
			);
			$(".a_general_box").each
			(
				function() 
				{
					setupGeneralBox(this);
				}
			);
			$(".InlineBox").each
			(
				function() 
				{
					var type = $(this).hasAttr("type") ? $.trim($(this).attr("type")).toLowerCase() : $.empty;
					var width = $(this).hasAttr("width") ? parseInt($(this).attr("width")) : null;
					var height = $(this).hasAttr("height") ? parseInt($(this).attr("height")) : $(window).height() - 15;
					var scrolling = $(this).hasAttr("scrolling") ? $(this).attr("scrolling") : "no";
					var title = $(this).hasAttr("title") ? $(this).attr("title") : $.empty;
					var titleShow = title != $.empty;
					var centerOnScroll = $(this).hasAttr("centerOnScroll");
					var padding = $(this).hasAttr("padding") ? parseInt($(this).attr("padding")) : 0;
					var margin = $(this).hasAttr("margin") ? parseInt($(this).attr("margin")) : 0;
					var href = $(this).hasAttr("href") ? $.trim($(this).attr("href")) : $.empty;
					var index = 0;
	
					if (type == "video")
					{
						var config = playerConfig(this);
						if (!$.isEmpty(config["id"]))
						{
							href = (href.length > 0) ? href.substr(1) : $.empty;
							var html = '<div style="display: none;">' +
								     '	<div id="' + href + '" style="width: ' + width + 'px; height: ' + height + 'px;">' +
								     '		<div id="' + config.id + '-' + index + '" file="' + config.file + '" width="' + width + '" height="' + height + '" class="jwplayer" ' + (config.image == $.empty ? $.empty : 'image="' + config.image + '"') + (config.stretching == $.empty ? $.empty : ' stretch="' + config.stretching + '"') + '></div>' +
								     '	</div>' +
								     '</div>';
	
							$("body").append(html);
						}
					}
	
					$(this).fancybox({
								'titleShow' : titleShow,
								'title' : title,
								'autoScale' : false,
								'centerOnScroll' : centerOnScroll,
								'width' : width,
								'height' : height,
								'hideOnOverlayClick' : false,
								'scrolling' : scrolling,
								'padding' : padding,
								'margin' : margin,
								'onComplete' : function()
										   {
											if ($("#fancybox-wrap").height() > height)
											{
												offset = $("#fancybox-wrap").offset();
												$("#fancybox-wrap").css({'position' : "absolute", 
																 'top' : offset.top - 25
																});
											}
										   }
					       	     });
	
					index++;
				}
			);
		}
		$('.img_preload').each
		(
			function()
			{
				setupPreload(this);
			}
		);
		$('.img_mouseover').each
		(
			function()
			{
				setupMouseover(this);
			}
		);
		//==================================
		//=> Cloud front streaming
		//==================================
		if ($("#player").length > 0)
		{
			activatePlayer();
		}
		$(".jwplayer").each
		(
			function()
			{
				setupPlayer(playerConfig(this));
			}
		);

   		if ($(".PlayerBorder").length > 0)
			$(".PlayerBorder").removeClass("PlayerBorder");
		//----------------------------------
	}
);
var img_loader = new Image();
    img_loader.src = '/img/main/ajax-loader.gif';
var img_loader_icon = new Image();
    img_loader_icon.src = '/img/icons/information.png';

function showMessage(message, width)
{	
	width = (width == null) ? 275 : width;
	message = message == null ? 'Please wait while we process your request' : message;
	message =			'<center>' +
					'<table>' +
					'<tr>' +
					'<td rowspan="2"><img src="/img/icons/information.png" width="25 height="25"></td>' +
					'<td>' +
					'<span style="font-size:10px;font-weight:normal;padding-left:8px;text-align:center;">' +
					message +
					'</span>' +
					'</td>' +
					'</tr>' +
					'<tr>' +
					'<td align="center"><img src="/img/main/ajax-loader.gif" width="220" height="19"></td>' +
					'</tr>' +
					'</table>' +
					'</center>';

	left = ($(window).width() - width) / 2;
	$.blockUI({ message : message, css: { width: width + 'px', left: left + 'px' }});
}
function hideMessage()
{	
	$.unblockUI();
}
var log = {
		'page' :
			function(callback)
			{
				var url = "/ping/index";
				var data = {"location": location.href};
				callback = $.isDefined(callback) ? callback : function() {};

				$.request.post("/ping/index", {"type": "xml", "data": {"location": location.href}, "callback": callback});
			}
	    };
