// way to fire a page request in hidden iframe
// good for doing google analytics tracking for offsite
// links, PDFs etc.
function loadFrame(goto_url)
{
	if ($("#loaderFrame").attr("id") != undefined){
		$("#loaderFrame").attr("src",goto_url);		
	}
	return true;
}

// Retrieves particular cookie
function getCookie(cookieName)
{
   var cookieFoundAt;
   var cookieValue;
 
   // find start position in cookie string
   cookieFoundAt = document.cookie.indexOf(cookieName + "=");
   
   if (cookieFoundAt < 0)
      {
         cookieValue = "";
      }
   else
      {
         // move to actual start of cookie's data
         cookieFoundAt = document.cookie.indexOf("=",cookieFoundAt);
         cookieFoundAt++;
         
         // find end position of cookie's data
         cookieEnd = document.cookie.indexOf(";", cookieFoundAt);
         if (cookieEnd == -1)
            {
             cookieEnd = document.cookie.length - 1;
            }
         cookieValue =document.cookie.substring(cookieFoundAt,cookieEnd  );
      }
   return cookieValue;
}

/**
 * adds trim method to strings
 *
 * @param {String} delim A list of characters to remove from beginning and end
 *				         of the current string; default is whitespace
 */
String.prototype.trim = function(delim) {
	return this.replace(new RegExp("^[\\s" + delim + "]+"),'').replace(new RegExp("[\\s" + delim + "]+$"), '');
}

/***
 * Sets textbox input state to blur/focus styles
 *
 * @param	o		DOMObject	The input object to style
 * @param	action	string		The action to style
 */
function formatInput(o, action) {
	switch(action) {
		case "blur":
			o.className = "blur";
			break;
		case "focus":
			o.className = "focus";
			break;
		default:
			break;
	}
}

/**
 * Provides generic form validation.
 *
 * Usage:
 * 1. Add to form: onsubmit="return(fmValidate(this))"
 * 2. Add required="true" attribute to desired inputs
 * 2a. Add validate="email" to input that needs email format verification
 *
 */
function fmValidate(theForm) {
	var hlColor = "#fc3";
	var hlMark = "&raquo;"
    var isValid = true;
	
	var els = theForm.elements;
    
	var firstBad = false;
    for(var i=0; i < els.length; i++) {
		var el = els[i];
		if(el.getAttribute("required") == "true") {
	        if(el.value == "") {
	            el.style.background = hlColor;
	            isValid = false;
				if(!firstBad) {
					el.focus();
					firstBad = true;
				}
	        } else {
	            el.style.background = "none";
	        }				
		}
		if(el.getAttribute("validate") == "email" && !SplunkUtil.isValidEmailAddress(el.value)) {
            el.style.background = hlColor;
            isValid = false;
			
		}
    }
    
    if(!isValid) alert("You need to fill in the required fields,\nwhich are marked in yellow.");
    return isValid;
}



function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function flipPanel(caller, panelId) {
	$("." + caller.className).removeClass('selected');
	$(caller).addClass('selected');
	
	$("." + $("#" + panelId).attr('class')).hide();
	$("#" + panelId).css('display','block');
	
}

var gRotatePanelsPid = 0;
function rotatePanels(panelClass, panelContainer, selectedIndex, timeout) {

	var ACTIVE_CLASS_NAME = 'activePanel';
	
	// kill any lingering timers
   //clearTimeout(gRotatePanelsPid);

    // set defaults
    if(!selectedIndex) selectedIndex = 0;
    if(!timeout) timeout = 5000;
    
    // get DOMs
    var domContainer = $(panelContainer);
	var domPanels = getElementsByClassName(domContainer, panelClass);
	var panelCount = domPanels.length;
    
    // determine next panel to show
    var nextIndex = (selectedIndex + 1) % panelCount;
    var activeIndex = 0;
	
	// hide all panels
	for(var i=0; i<panelCount; i++) {
	    if(Element.hasClassName(domPanels[i], ACTIVE_CLASS_NAME)) {
	        activeIndex = i;        
	        break;
	    }
	}
	

	// hide active panel
    //Element.removeClassName(domPanels[activeIndex], ACTIVE_CLASS_NAME);
    
	// show new one
	Element.addClassName(domPanels[selectedIndex], ACTIVE_CLASS_NAME);
	
	// schedule next rotation
	//gRotatePanelsPid = setTimeout('rotatePanels("' + panelClass + '","' + panelContainer + '",' + nextIndex + ',' + timeout + ')', timeout);
	
	return true;
    
}




function openDemo2(demoname){
		
	// define where we'll go
	var	gotoUrl = '';
	
	// set width 
	var width = 800;
	var height = 650;
	

	if (!demoname) return false;
	
	// see who they're trying to get
	if (demoname == 'chris'){
		gotoUrl = '/web_assets/screencastdemos/chris_mcdaniel/reardendemo.html';
		width = 875;
		height = 640;
	}
	if (demoname == 'corey'){
		gotoUrl = '/web_assets/screencastdemos/corey_shields/corey2.html';
		width = 1000;
		height = 550;
	}
	if (demoname == 'brent'){
		gotoUrl = '/web_assets/screencastdemos/brent_chapman/brentdemo.html';
		width = 875;
		height = 640;
	}
	if (demoname == 'matthew'){
		gotoUrl = '/web_assets/screencastdemos/matthew_zeier/mozilla.html';
		width = 900;
		height = 655;
	}
	
	if (demoname == 'steve'){
		gotoUrl = '/web_assets/screencastdemos/steve_loyd/index.html';
		width = 950;
		height = 650;
	}
	
	if (demoname == 'sneakpeekQT1'){
		gotoUrl = '/web_assets/video/movie1.html';
		width = 660;
		height = 390;
	}
	
	if (demoname == 'sneakpeekQT2'){
		gotoUrl = '/web_assets/video/movie2.html';
		width = 660;
		height = 390;
	}
	
	if (demoname == 'sneakpeekQT3'){
		gotoUrl = '/web_assets/video/movie3.html';
		width = 660;
		height = 390;
	}
	
	if (demoname == 'sneakpeekQT4'){
		gotoUrl = '/web_assets/video/movie4.html';
		width = 660;
		height = 390;
	}
	
	window.open(gotoUrl,'blank','toolbar=no,width=' + width + ',height=' + height);
	
	return false;
}


function openVideo(url,width,height){
		
	// define where we'll go
	var	gotoUrl = '/web_assets/' + url;
	


	if (!url) return false;
	
	
	window.open(gotoUrl,'blank','toolbar=no,width=' + width + ',height=' + height);
	
	return false;
}

function showhide(layer_ref) {
	
	$('#' + layer_ref).slideToggle();
	
	return false;
}


/**
 *  Class for utility functions
 */
function SplunkUtil() {
    var self = this;
    
    self.isValidEmailAddress = function(email){
        var emailRegex = /^[A-Za-z0-9\_\-\+]+[A-Za-z0-9\_\-\.\+]*@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,}$/;
        return emailRegex.test(email);
    }
    
}
var SplunkUtil = new SplunkUtil(); 



/**
*	do small rounded corners with jquery
***/

$(function(){
	$('.smallRoundedCorners').append('<div class="smallRoundedUL"></div><div class="smallRoundedLL"></div><div class="smallRoundedLR"></div><div class="smallRoundedUR"></div>');
});


/**
*	set an offset to be used when displaying hero modules
**/
var heroModuleTimerOffset = 0;

/**
* 	global pause all hero flag
**/
var pauseAllHeros = 0;

/* global var needed for video seeking //see WEB-3737 */
var playerId = '';

/**
* 	Modal Video popup functions
**/
function showFancyVideoDiv(aid){

	preFancyVideoDiv();
	
	$.getJSON("/page/ajax_article_get/" + aid, function(articleAry){
		if (articleAry.embed_html_output != "Empty Article Body" && articleAry.embed_html_output != "Article Not Found"){
	
			// init
			var suffix = '';
			
			var localPlayerId = "FancyVideoDivEmbedObj";
			playerId = localPlayerId; // see WEB-3737
			
			/* $("#FancyVideoDivEmbed").html(articleAry.embed_html_output);*/
			$("#FancyVideoBrowseLink").show();
			$("#modalVideoSidebar").show();
			$("#FancyVideoDivLeft").removeClass("span-12").addClass("span-8");
			$("#FancyVideoDivTitle").html(articleAry.title);
			$("#FancyVideoDivDescr").html(articleAry.summary);
			$("#FancyVideoDivPermalink").html("<a href=\"/view/" + articleAry.document_id + 
				"\">http://www.splunk.com/view/" + articleAry.document_id + "</a>");

			positionAndShowFancyVideoDiv(articleAry, 'FancyVideoDivEmbed', localPlayerId);
		} 
	});
}

function hideFancyVideoDiv(){
	$("#FancyVideoDivEmbed").html("");
	$("#FancyVideoDivTitle").html("");
	$("#FancyVideoDivDescr").html("");
	$("#FancyVideoDivPermalink").html("");
	$("#FancyVideoDivOuter").slideUp('fast', function(){
		/*if($.browser.browser == "Firefox") {
			//and now reposition stupid navHeroItems which get borked for some reason
			$('.heroBottom .heroNavItem').hide().css('display','block');
		}*/
		$("#modalOpacityLayer").hide();
	});

	//restart rotation of all hero content mods
	pauseAllHeros = 0;
	
}

function preFancyVideoDiv() {
	//pause rotation of all hero content mods
	pauseAllHeros = 1;

	$("#modalOpacityLayer").css({height:$(document).height(), width:$(document).width(),display:"block"});

	$(window).resize(function(){
		$("#modalOpacityLayer").css({width:$(document).width()});
	});
	
	if ( $.browser.browser == "MSIE" && $.browser.version.number == 6){
        $("#modalOpacityLayer").css('opacity',.8);  
	}	
	
	var t = $(window).height()/2 - 50;
	var l = $(window).width()/2 - 50;
	var preLoadHtml = "<div id='FancyPreLoader' style='left:" + l + "px; top:" + t + "px;'></div>";
	$('body').append(preLoadHtml);
}

function positionAndShowFancyVideoDiv(articleAry, targetDiv, localPlayerId) {	
	if ( $(window).height() < 656 ) {
		topOffset = $(window).scrollTop() + 10;
	} else {
		var topOffset = ($(window).height() - $("#FancyVideoDivOuter").height())/2 + $(window).scrollTop(); 
		if ( topOffset < 0 ) {
			topOffset = 10;
		}
	}
	$("#FancyPreLoader").remove();
	$("#FancyVideoDivOuter").css({top: topOffset}).slideDown('fast', function() {
			$("#FancyVideoDivEmbed").html("<div class='noFlash'><p>You must have Flash installed and Javascript<br /> enabled to play this video.</p><a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' target='_blank'>Click here</a> if you need to download the free Flash Player.</div>");
			videoDisplay(articleAry, targetDiv, localPlayerId);
		}
	);	
}

/* video seeking functions */
function playerReady(obj) {	
	var player = document.getElementById(playerId);
	player.addModelListener("TIME", "updatepos");	
}

function FLVseekTo(second){
	var player = document.getElementById(playerId);
	player.sendEvent('SEEK', second);
}

function FLVload(flvURL){
	var player = document.getElementById(playerId);
	player.sendEvent("LOAD", flvURL);
}

function FLVReload(){
	var player = document.getElementById(playerId);
	player.sendEvent("LOAD", "#$SrvURL##$base_url##$flv_url#");
}

function wikiSidebarToggler(){
	$('.wikiSidebarTopicHeader').click(function(){
		$(this).toggleClass('topicOpen');
		$(this).next('ul.wikiSidebarTopicList').slideToggle('fast');
	});
}

// Function that determines which js to execute depending on video type

function videoDisplay (articleAry, targetDiv, localPlayerId) {

	// set default video type, if not set (it really should be, but just in case)
	if (articleAry.video_type == '') {
		articleAry.video_type = 'raw';
	}

	// set default width and height, if not set
	if (articleAry.flv_width == '') {
		articleAry.flv_width = 624;
	}
	if (articleAry.flv_height == '') {
		articleAry.flv_height = 351;
	}

	switch(articleAry.video_type) {
		case 'raw': // Raw SWF, super old-school
			var JS_flv_height = Number(articleAry.flv_height) + 38;
			var so = new SWFObject(articleAry.base_url +  articleAry.flv_url, localPlayerId, articleAry.flv_width, JS_flv_height, 8, "#ffffff","high");
			break;
		case 'jwplayer': // JW Player, old-school
			var so = new SWFObject(articleAry.SrvURL + "web_assets/video/flash_components/player3.swf", localPlayerId , articleAry.flv_width , articleAry.flv_height, 8, "#ffffff","high");
			so.addParam('flashvars','file=' + articleAry.SrvURL + articleAry.base_url + articleAry.flv_url + '&streamer=lighttpd&autostart=true');
			break;
		case 'fliqz': // Fliqz
			var so = new SWFObject("http://applications.fliqz.com/c051a0b4147946ffa7b1cb25eb2ea0a7.swf", localPlayerId, articleAry.flv_width , articleAry.flv_height, 8, "#ffffff","high");
			so.addParam('flashvars','at=' + articleAry.flv_url + '&autoPlayback=true');
			break;
		case 'vimeo': // Vimeo
			var so = new SWFObject("http://www.vimeo.com/moogaloop.swf", localPlayerId, articleAry.flv_width, articleAry.flv_height, 8, "#ffffff","high");
			so.addParam('flashvars', 'clip_id=' + articleAry.flv_url + '&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&fullscreen=0&autoplay=1&js_api=1&js_onload=vimeo_player_loaded');
			break;
		case 'viddler': // Viddler
			var so = new SWFObject("http://www.viddler.com/player/" + articleAry.flv_url, localPlayerId, articleAry.flv_width, articleAry.flv_height, 8, "#ffffff", "high");
			so.addParam('flashvars', 'autoplay=t');
			break;
		case 'youtube': // YouTube (HTML5!)
			var videoEmbedUrl = 'http://www.youtube.com/embed/' + articleAry.flv_url;
			var videoEmbedHtml = '<iframe width="' + articleAry.flv_width + '"  height="' + articleAry.flv_height + '" src="' + videoEmbedUrl + '?autoplay=1&modestbranding=1&hd=1&rel=0" frameborder="0" allowfullscreen></iframe>';
			break;
	}

	if (articleAry.video_type != 'youtube') { // Flash
		// attributes and params that apply to all types of videos
		so.setAttribute('xiRedirectUrl', articleAry.permalink);
		so.addParam("wmode", "window");
		so.addParam('menu','false');
		so.addParam('bgcolor','#000000');
		so.addParam('scale','exactfit');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('pluginspage','http://www.macromedia.com/go/getflashplayer');
		so.useExpressInstall(articleAry.SrvURL + 'themes/splunk_com/scripts/js/swfobject1-5/expressinstall.swf');
		so.write(targetDiv);
	} else { // HTML5
		$('#'+targetDiv).html(videoEmbedHtml);
	}

}

/* International sites menu */

$(function(){
    $('#languageSwitcher').click(function(evt){
        orig = evt.target;

        if ( $(orig).attr('id') == "languageSwitcherLink") {
            if ( !$('#languageMenu').is('.menuOpen') ) {
                evt.stopPropagation();
                $('body').trigger('internationalOpen', [1]);
                showInternational();
            }
        }
    });

    $('body').click(function() {
        $('body').trigger("internationalOpen");
    });
    
    $('body').bind('internationalOpen', onInternationalOpen)
       
});

function onInternationalOpen(e, menuFlag) {
    if ( menuFlag == 1 ) {
        return false;
    } else {
        hideInternational();
    }
}

function showInternational() {
    $('#languageMenu').addClass('menuOpen');
}

function hideInternational() {
    $('#languageMenu').removeClass('menuOpen');
}


/*******************
    tabification 
********************/

function tabify ( tabID ) { 
    var $tabID = (tabID.substr(0,1) == '#') ? $(tabID) : $('#' + tabID);
        
    if ( $tabID.children('li').children('a').length > 1 ) {
        $tabID.children('li').children('a').each(function(){
            tab = $(this).attr('href');
            if ( $(this).parent('li').is('.current') ) {
                $(tab).css('display','block');
            } else {
                $(tab).css('display','none');
            }
        }); 

        $tabID.bind('click', function(evt){
            var t = evt.target;
            
            if ( $(t).is('a') && !$(t).parent('li').is('.current') ) {
                $li = $(t).parent('li');
                $a = $(t);
            } else if ( $(t).is('li') && !$(t).is('.current') ) {
                $li = $(t);
                $a = $(t).children('a');   
            } else {
                 return false;
            }
            
            $current = $('.current', $tabID);
            shownTab = $current.children('a').attr('href');

            $(shownTab).css('display','none');
            $current.removeClass('current');
            
            $li.addClass('current');
            tabToShow = $a.attr('href');
            $(tabToShow).css('display','block');   
            
            $(t).blur();
            
            return false;
        });  
    }    
       
}

// this function takes a display count
// and the ID of a parent div.  it will then
// select N random  children of the parent
// and show them.  requires jquery and that
// children have display none
function randomlyShowChildren(desiredCount,ParentID,ChildClass){
	//init
	var availOptions = $("#" + ParentID + " ." + ChildClass).length;
	var selected = new Array();
	var counter = 0;
	var tmpVal = null;
	
	// choose N items from the parent DIV
	while  ( selected.length  !=  desiredCount ){
		
		// get a temp value and see if it's already selected
		tmpVal = Math.floor(Math.random()*availOptions) + 1;

		if ($.inArray(tmpVal, selected) == -1){
			selected[counter] = tmpVal;
			$("#" + ParentID + " div:nth-child(" + selected[counter] + ")").show();
			counter++;
		}
	}
};

// synchronous ab test recorder for show and click
// of ab test per WEB-4956
function abtestRecorder(action, testName, offset, pageName, destination){
	
	// cleanse testname, pagename and destination for 
	// ampersands and double quotes. these wil fuck up 
	// the query string written to logs in splunk
	testName = testName.replace("&", "");
	testName = testName.replace('"', '');
	pageName = pageName.replace("&", "");
	pageName = pageName.replace('"', '');
	if (destination != undefined){
		destination = destination.replace("&", "");
		destination = destination.replace('"', '');
	}
	
	// call recorder end point, but turn off async so
	// page unload doesn't kill our tracking request
	$.ajax({
		url: "/page/ajax_recorder",
		data: "itemBeingRecorded=abtest&action=" + action +
			"&testName=" + testName + "&offset=" + offset +
			"&pageName=" + pageName + "&destination=" + destination,
		async: false
	});
}

// output HTML of random AB Test and set
// click handler per WEB-4956
function renderAbtest(testName, testJSON, testLocationPageName){
	var abtests,testName;
	var testOffset = Math.floor(Math.random()*testJSON.length);
	
	// push random into HTML of ID and record show
	$("#abtest_" + testName).html(testJSON[testOffset]);			
	abtestRecorder('show', testName, testOffset, testLocationPageName);
	
	// add click event handler to ID
	$("#abtest_" + testName + " a").click(function () { 
		testDestination = $(this).attr("href");
		abtestRecorder('click', testName, testOffset, testLocationPageName, testDestination);
	});
}

// search tip recorder
function searchTipRecord(action, name, search, article, destination, async) {
	if (destination != undefined){
		destination = destination.replace("&", "");
		destination = destination.replace('"', '');
	}
	// call recorder end point, but turn off async so
	// page unload doesn't kill our tracking request
	$.ajax({
		url: "/page/ajax_recorder",
		data: "itemBeingRecorded=" + name + "&action=" + action +
			"&article=" + article + "&search=" + search + "&destination=" + destination,
		async: async
	});
}

// search tip recorder setup
function searchTipSetup(){
	$(".searchtipItem").find('a').click(function() {
		var destination = $(this).attr("href");
		var search = $(this).closest('.searchtipItem').attr('search');
		var article = $(this).closest('.searchtipItem').attr('article');
		searchTipRecord('click', 'SearchTip', search, article, destination, false);
	});
	$(".searchtipItem").each(function() {
		var search = $(this).attr('search');
		var article = $(this).attr('article');
		searchTipRecord('view', 'SearchTip', search, article, 'NA', true);
	});
}

function submitTellAFriend(formPath,formPagename){

	// check 3 fields
	tellafriendemail = $('#tellafriendemail').val().trim(' ');
	//tellafriendnote = $('#tellafriendnote').val().trim(' ');
	tellafriendname = $('#tellafriendname').val().trim(' ');
	error = '';
	if(!SplunkUtil.isValidEmailAddress(tellafriendemail)) {
			error = error + " - Invalid Email\n";
	}
//	if(tellafriendnote == '') {
//            error = error + " - Note is empty\n";
//	}
	if(tellafriendname == '') {
            error = error + " - Please provide your name\n";
	}

	// return error if any
	if (error != ''){
		alert("Please fix these items in order to Tell a Colleague:\n" + error);
		return false;
	}

	// make it so they can't sumit it again while we fire AJAX
	$('#submitTellAFriend').unbind('click');
	$('#submitTellAFriendAfter').show();
	$('#submitTellAFriend').val('Sending...');

	// process POST passing all form vars
	$.post("/page/tellafriend/post",{ 
			formPath: formPath, formPagename: formPagename,tellafriendemail: tellafriendemail, tellafriendname: tellafriendname
		}, function(formResponse){

		// if we got success, hide modal, if not show error
		// and reset form to be submitted again
		if(formResponse.result == 'success'){

			// call recorder end point to record sending
			$.ajax({
				url: "/page/ajax_recorder",
				data: "itemBeingRecorded=tellafriend&action=send" +
					"&formPath=" + formPath + "&formPagename=\"" + formPagename + "\""
					+ "&fromName=\"" + tellafriendname + "\"toEmail=" + tellafriendemail
			});

			hideFancyVideoDiv();
		} else {
			// hide spinner, reset button text and
			// add handler back to button
			$('#submitTellAFriendAfter').hide();
			$('#submitTellAFriend').val('Send');
			$("#submitTellAFriend").click(function() {
				submitTellAFriend(formPath,formPath);
			});

			// alert error
			if(formResponse.result == 'badcaptcha'){
				alert('Please enter the correct captcha text');
			} else {
				alert('An error occured.  Please try again or contact support@splunk.com.');
			}

		}
	}, "json");
}

// put handlers on search tip links
function tellAFreindSetup(){	

	$(".forwardtofriend").click(function() {

		formPath = location.pathname;
		formPagename = $('title').html().replace('Splunk : ','').replace('Splunk | ','');
		
		$.getJSON("/page/tellafriend/get?formPagename=" + formPagename + "&formPath=" + formPath, function(formAry){
			preFancyVideoDiv();

			// prep body of modal to have extra classes and remove some classes
			$("#FancyVideoDivEmbed").attr('class','tellafriend')
			$("#FancyVideoDivLeft").removeClass("span-8").addClass("span-12");
			$("#FancyVideoDivEmbed").html('');

			// create the form for the end user
			$("#FancyVideoDivEmbed").append('<b>Your Name:</b><span> '
				+ '<input id="tellafriendname" type="text" size="20" /></span><br />');
			
			$("#FancyVideoDivEmbed").append('<b>Recipient\'s Email:</b><span> '
				+ '<input id="tellafriendemail" type="text" size="20" /></span><br />');

			//$("#FancyVideoDivEmbed").append('<b>Captcha:</b><span> '
			//	+ formAry.captcha + '</span><br />');

			$("#FancyVideoDivEmbed").append('<b>Subject:</b><span>' 
					+ formAry.subject + '</span><br />');

			$("#FancyVideoDivEmbed").append("<b>Email:</b><div id='tellafreindbody'>"
				+ formAry.body + "<br />"
				//+ "<textarea cols='70' rows='4' id='tellafriendnote'>Check out this great page on Splunk. -Your Friend</textarea>"
				+ "</div><br />");

			$("#FancyVideoDivEmbed").append('<b>&nbsp;</b>'
				+ '<input type="submit" class="primary" value="Send" id="submitTellAFriend" >'
				+ '<div id="submitTellAFriendAfter" >'
				+ '<img id="tellAFriendWait" src="/themes/splunk_com/images/transp.spinner.gif" />'
				+ '</div>'	);

			// set modal title and hide video related content
			$("#FancyVideoDivTitle").html('Tell a Colleague : ' + formPagename);
			$("#FancyVideoBrowseLink").hide();
			$("#modalVideoSidebar").hide();

			// show modal
			positionAndShowFancyVideoDiv();

			// cufon it up on the title
			Cufon.replace('.en #FancyVideoDivTitle', { fontFamily: 'Myriad Pro' });

			// call recorder end point to record showing form
			$.ajax({
				url: "/page/ajax_recorder",
				data: "itemBeingRecorded=tellafriend&action=show" +
					"&formPath=" + formPath + "&formPagename=\"" + formPagename + "\"&fromName=NA&toEmail=NA"
			});
			
			// add handler to button now that it's rendered
			$("#submitTellAFriend").click(function() {
				submitTellAFriend(formPath,formPagename);
			});
		});

		return false;
	});
	
}

