// homepage quotations box show/hide routine
var currentLayer = 'start';
function showLayer(lyr) {
   hideLayer(currentLayer);
   document.getElementById(lyr)
      .style.display = 'block';
   currentLayer = lyr;
}

function hideLayer(lyr) {
   document.getElementById(lyr).
      style.display = 'none';
}

/*===================================
	simple toggle: 
	show hide a div on click
  ===================================*/

function toggleDivDisplay(whichDiv)
{

	if(document.getElementById(whichDiv).style.display == 'none') 
	{
	   document.getElementById(whichDiv).style.display = 'block'
	}
	else 
		{
			 document.getElementById(whichDiv).style.display = 'none';
		}
}



/*=================================
generic show/hide function
===================================*/

function showDiv(theDiv)
{
   document.getElementById(theDiv).style.display = 'block';
}

function hideDiv(theDiv) {
    document.getElementById(theDiv).style.display = 'none';
}

// generic pop up windows

function popWin(theURL,winName,features) {
  window.open(theURL,winName,features);
  }







/* =============================
	Homepage tabs and tab divs
   =============================*/

// show tabs.
// id: the id of the div we are showing
// buttonToHighlight: highlight the button that was clicked to show tab to create an "on" state

function showTabContent( id, buttonToHighlight) {
	// set fontStyle to normal, set background image of tab buttons to normal
	document.getElementById( "fug" ).style.fontStyle = "normal";
	document.getElementById( "fug" ).style.borderStyle = "none";
	document.getElementById("fug").style.backgroundImage="url(/images/foll-grafting-button.jpg)";
	document.getElementById("fug").style.color = "#006787";


	document.getElementById( "densepack" ).style.fontStyle = "normal";
	document.getElementById( "densepack" ).style.borderStyle = "none";
    document.getElementById("densepack").style.backgroundImage="url(/images/dense-packing-button.jpg)";
	document.getElementById("densepack").style.color = "#006787";

	document.getElementById( "mega" ).style.fontStyle = "normal";
	document.getElementById( "mega" ).style.borderStyle = "none";
    document.getElementById("mega").style.backgroundImage="url(/images/megasessions-button.jpg)";
	document.getElementById("mega").style.color = "#006787";

	document.getElementById( "nat" ).style.fontStyle = "normal";
	document.getElementById( "nat" ).style.borderStyle = "none";
    document.getElementById("nat").style.backgroundImage="url(/images/natural-results-button.jpg)";
	document.getElementById("nat").style.color = "#006787";

	document.getElementById( "ms" ).style.fontStyle = "normal";
	document.getElementById( "ms" ).style.borderStyle = "none";
    document.getElementById("ms").style.backgroundImage="url(/images/minimal-scarring-button.jpg)";
	document.getElementById("ms").style.color = "#006787";


	//  hide list text
	document.getElementById( "tab1_div" ).style.display = "none";
	document.getElementById( "tab2_div" ).style.display = "none";
	document.getElementById( "tab3_div" ).style.display = "none";
	document.getElementById( "tab4_div" ).style.display = "none";
	document.getElementById( "tab5_div" ).style.display = "none";

	//  show list text
	
	document.getElementById( "tab" + id + "_div" ).style.display = "block";
	document.getElementById(buttonToHighlight).style.fontStyle = "normal";
	

   // if tab is clicked show the "on" state of the button.
	if(buttonToHighlight == "fug") { 
		document.getElementById(buttonToHighlight).style.backgroundImage="url(/images/foll-grafting-button-on.jpg)";
		document.getElementById(buttonToHighlight).style.color = "#c47B47";
		}

	if(buttonToHighlight == "densepack") { 
		document.getElementById(buttonToHighlight).style.backgroundImage="url(/images/dense-packing-button-on.jpg)";
		document.getElementById(buttonToHighlight).style.color = "#c47B47";
	}
	if(buttonToHighlight == "mega") { 
		document.getElementById(buttonToHighlight).style.backgroundImage="url(/images/megasessions-button-on.jpg)";
		document.getElementById(buttonToHighlight).style.color = "#c47B47";
		}
	if(buttonToHighlight == "nat") { 
		document.getElementById(buttonToHighlight).style.backgroundImage="url(/images/natural-results-button-on.jpg)";
		document.getElementById(buttonToHighlight).style.color = "#c47B47";
		}
	if(buttonToHighlight == "ms") { 
		document.getElementById(buttonToHighlight).style.backgroundImage="url(/images/minimal-scarring-button-on.jpg)";
		document.getElementById(buttonToHighlight).style.color = "#c47B47";
		}
}



/*================================================================
Show / hide function for tabs on hair-transplant-videos.php page:
We are showing/hiding Categories, 
My Videos, Mail this Video
==================================================================*/

function showVideoInfoDiv(theDiv, tabToHighlight)
{
   document.getElementById(theDiv).style.display = 'block';
   document.getElementById(tabToHighlight).style.backgroundColor = "#c7d6dd";
}

function hideVideoInfoDiv(theDiv, tabToLowlight) {
    document.getElementById(theDiv).style.display = 'none';
	document.getElementById(tabToLowlight).style.backgroundColor = "#fff";
}



   

/*================================================
	Create the flash player using the swfobject.js
  ================================================*/

	
		function createplayer(theFile, theImage, go) {

			var so = new SWFObject('/mediagallery/flash-player/mediaplayer.swf','thePlayerId','100%','100%','7');
				so.addParam('allowfullscreen','true'); 
				so.addParam('wmode', 'transparent');
				so.addVariable('javascriptid','thePlayerId');
				so.addVariable('enablejs','true');
                // only want to start the video if user clicks...not when they arrive to the homepage or video page.
				// param "go" is set to true in the function call
				if (go) {
					// we'll add startSwitch to flashvars.
					startSwitch = 'autostart=true';
				}
				else {
					startSwitch = 'autostart=false';
				}
				so.addParam('flashvars','file='+theFile+ '&image=' +theImage+ '&backcolor=0x000000&frontcolor=0x7f96bf&screencolor=0x000000&lightcolor=0xCfbb63&searchbar=false&overstretch=true&showstop=true&stretching=fill&displayheight=250&height=250&width=448&javascriptid=thePlayerId&enablejs=true&controlbar=over&allowscriptaccess=always&' +startSwitch);
				so.write('flashVideo');
	} 

  



/*=============================================================
 cookies: We are using these to save the value of a saved video
 on hair-transplant-videos.php page. We are storing multiple name/value pairs in 
 one cookie. 
 ==============================================================*/

function setCookie( name, value, expires, path, domain, secure )
{
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires )
    expires = expires * 1000 * 60 * 60 * 24;
  var expires_date = new Date( today.getTime() + (expires) );

      // separate name/value pairs with an ampersand.
	  if(document.cookie.indexOf(name) > -1 ) {
		 value = getCookie(name) + "&" + value;
		  document.cookie = name+"="+escape( value ) +
			( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) +
			( ( path ) ? ";path=" + path : "" ) +
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
		  }
	  else {
		  document.cookie = name+"="+escape( value ) +
			( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) +
			( ( path ) ? ";path=" + path : "" ) +
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
		  }
}


function getCookie( name )
{
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
    return null;
  if ( start == -1 )
    return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 )
    end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

function deleteCookie(name) {
	setCookie(name,"",-1);
}


function deleteCookiePart(name,fileName) {
	// get value of current cookie
	currCookieValue = getCookie(name);
	newCookieValue = currCookieValue.replace(fileName,'');
	// kill the current cookie
	setCookie(name,"",-1);
	// reset the cookie with the new value
   setCookie( name, newCookieValue, 30)
}


         // get data from the movie so we can mail the video url, and write the video name as a link in the mail-video, and currVideo divs the tabbed divs
		 // on the hair-transplant-videos.php page.
	            
		    function getItemData(idx) {
		    theCookie = getCookie('videoCookie');
			// clear the cookie if it doesn't contain a video name.
			if((theCookie != null && theCookie.indexOf(".flv") == -1)) {
				deleteCookie('videoCookie');
			}
			var obj = thisMovie("thePlayerId").itemData(idx);
			var tmp=obj["file"];
			videoURLParts = tmp.split('/mediagallery/movies/');
			// the filename of the video without all the path stuff preceding it.
			videoFileName = videoURLParts[1];

			// we have the filename, which is in this format 2_spv-26-4944.flv, we need to get
			// the screenshot to load in the player via the link we are mailing
			// the screenshot file is in this format: 2_screenshot_spv-26-4944.flv
			videoFileNameParts = videoFileName.split("_");
			// alert(videoFileNameParts[0]);
			screenshotFileName = videoFileNameParts[1].split(".flv"); // hack off .flv and append .jpg
			screenshotFileName = videoFileNameParts[0] + "_screenshot_" + screenshotFileName[0] + ".jpg";
			
			//alert(screenshotFileName);

			// this is the 'Mail this video' form. We need the video name in a hidden input so a visitor can
			// send it to a friend.
			if(tmp!= "" ) {
				var theVideoURL = "http://www.hassonandwong.com/hair-transplant-videos.php?file=" +videoFileName+ "&amp;screenshot=" +screenshotFileName ;
				var theURL='<p style="margin-right:0px;padding-right:0px"><a  class="saveVideoButton" href="/hair-transplant-videos.php?saved=1" onclick="setCookie(\'videoCookie\',\'' +videoFileName+ '\',60);">Save current video</a></p>';
				theForm =  "<form name='mail-video-form' id='mail-video-form' method='post' action='' style='position: relative; top: 10px; left: 10px;'>";
				theForm += "Your Name <br />";
				theForm += "<input type='text' name='name' /><br />";
				theForm += "Your friend's email:<br />";
				theForm += "<input type='text' name='email' /><br />";
				theForm += "Message:<br />";
				theForm += "<textarea class='mytextarea' name='message' cols='30' rows='2'>Check out the hair transplant video at Hasson &amp; Wong:\n\n";
				theForm +=  "(video link embedded in email)"
				theForm += "</textarea>";
				theForm += "<input type='submit' name='sendMail' value='send' />";
				theForm += "<input type='hidden' name='videoURL' value='" +theVideoURL+ "'>";
				// object/embed code for syndicating videos. URL appears as text in a textbox
                theForm += "<br />Embed code: <input size='24' onclick='this.select()' type='text' value=\"&lt;div style='width:448px;height:250px'&gt;&lt;object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' width='448' height='250'&gt;&lt;param name='flashvars' value='file=http://www.hassonandwong.com/mediagallery/movies/" +videoFileName+ "&amp;amp;image=http://www.hassonandwong.com/mediagallery/movies/video-screenshots/" +screenshotFileName+ "&amp;amp;backcolor=0x000000&amp;amp;frontcolor=0x7f96bf&amp;amp;screencolor=0x000000&amp;amp;lightcolor=0xCfbb63&amp;amp;controlbar=over&amp;amp;searchbar=false&amp;amp;overstretch=true&amp;amp;showstop=true&amp;amp;stretching=fill&amp;amp;displayheight=250&amp;amp;height=250&amp;amp;width=448&amp;autostart=false' /&gt;&lt;param name='movie' value='http://www.hassonandwong.com/mediagallery/flash-player/mediaplayer.swf' /&gt;&lt;param name='allowFullScreen' value='true' /&gt;&lt;param name='allowscriptaccess' value='always' /&gt;&lt;param name='wmode' value='transparent' /&gt;";
                theForm += "&lt;embed type='application/x-shockwave-flash' src='http://www.hassonandwong.com/mediagallery/flash-player/mediaplayer.swf' id='thePlayerId' name='thePlayerId' quality='high' allowfullscreen='true' wmode='transparent' flashvars='file=http://www.hassonandwong.com/mediagallery/movies/" +videoFileName+ "&amp;amp;image=http://www.hassonandwong.com/mediagallery/movies/video-screenshots/" +screenshotFileName+ "&amp;amp;backcolor=0x000000&amp;amp;frontcolor=0x7f96bf&amp;amp;screencolor=0x000000&amp;amp;lightcolor=0xCfbb63&amp;amp;controlbar=over&amp;amp;searchbar=false&amp;amp;overstretch=true&amp;amp;showstop=true&amp;amp;stretching=fill&amp;amp;displayheight=250&amp;amp;height=250&amp;amp;width=448&amp;amp;javascriptid=thePlayerId&amp;amp;enablejs=true&amp;amp;allowscriptaccess=always&amp;amp;autostart=false' height='100%' width='100%'&gt;&lt;/object&gt;&lt;/div&gt;&lt;span style='font-family:Verdana,sans-serif;font-size:10px'&gt;&lt;a href='http://www.hassonandwong.com' target='_blank'&gt;hair transplants&lt;/a&gt; by Hasson &amp; Wong</span> \" /><br />";
                theForm += "<span class='highlight'>Copy &amp; paste the code into your web page</span></form>";
				// write the video name as a link in #currVideo which is in the My Saved Videos #my-saved-videos on hair-transplant-videos.php
				if(document.getElementById("currVideo") !== null) { document.getElementById("currVideo").innerHTML = theURL; }
				// write the mail form to the mail-video div.
				if(document.getElementById("mail-video") != null) { document.getElementById("mail-video").innerHTML = theForm; }
			} 
			else {
				if(document.getElementById("currVideo") != null) { document.getElementById("currVideo").innerHTML = ""; }
			}
		};

	// This is a javascript handler for the player and is always needed.

	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};



    var currentItem;
   
	function getUpdate(typ,pr1,pr2,pid) {
		if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
	};
    
	function sendEvent(typ,prm) { thisMovie("thePlayerId").sendEvent(typ,prm); };
    // get the filename of a currently playing video on hair-transplant-videos.php

	function stopVideoPlayer() {
			if(document.getElementById('thePlayerId') != null) {
				// this lets us stop a currently playing video before creating the video object again if the user clicks another thumbnail. If we don't do this, IE crashes
				sendEvent('stop');
			}
		}