//  This function tests whether or not there is a cookie set and whether or not you are going to
//  Microdocs or opening a portfolio video. If there's no cookie, it will take you to the microdocs
//  or portfolio options pages. If there is a cookie, it will take you to either the microdocs
//  gallery or it will pop open your previous selection and return you to the main portfolio page.
function testCookie(whattype){
	//There is a cookie and it's a microdoc --> Opens Gallery of Microdocs
	if ((document.cookie != "") && (whattype=="microdocs"))
			{location.href="http://www.arrowire.com/portfolio/gallery.html";}
	//There is a cookie and it's not a microdoc --> Calls Open Pop-Up function
	else if ((document.cookie != "") && (whattype!="microdocs") && (whattype!="content"))
			{ MM_openBrWindow(whattype,'','width=340,height=260');}
	//There is no cookie --> Opens Options page
	else	{location.href = "http://www.arrowire.com/portfolio/options_portfolio.html?+" + whattype + "+"; }
}

//  This sets your cookie and opens the popup if you were coming from the portfolio page.
function setCookie(playerSpeed){
	var page_to_open = playerSpeed;
	var the_cookie ="microdocs=speed:" + escape(page_to_open);
	document.cookie = the_cookie;
	var the_video = location.search.substring(2, location.search.length-1);
	if (the_video != "")
		if (the_video != "microdocs")
		{history.go(-1);
		testCookie(the_video);}else{testCookie(the_video);}
	}

//  This is where the pop-up info is stored. This is where we distinguish
//  between players embedded on a standard embedded page and a separate
//  one that has images and other unique qualities. 
//  IMPORTANT: All pages that have unique skin to them need to be named
//  open.htm and should be in a folder named the same as the video name
//  within the portfolio folder. 
//  Like 'marketplace' which as a video is 'marketplace_lo'.
function MM_openBrWindow(theURL,winName,features) { 
var thewidth=readcookie();
var withoutskinx = thewidth + 60;
var withoutskiny = (thewidth*3)/4 + 40;  
	if ((theURL == "marketplace") ||(theURL == "daytrader") || (theURL == "mariachi") || (theURL == "cake") || (theURL == "surfrabbi") || (theURL == "rockchiro") || (theURL == "turicchi") || (theURL == "hamerslag")){
		theURL =  "http://www.arrowire.com/portfolio/" + theURL + "/open.htm?+" + theURL + "+";  window.open(theURL,winName,'width=340,height=450');} else{
	theURL = "http://www.arrowire.com/portfolio/open.htm?+" + theURL + "+";  window.open(theURL,winName,'width='+withoutskinx+' height='+withoutskiny);}
}
 
function readcookie(){
var the_cookie = document.cookie;
var broken_cookie = the_cookie.split(":");
var the_name = broken_cookie[1];
var the_name = unescape(the_name);
	if ((the_name == "reallo") ||(the_name == "pclo")) { thewidth = 240; }
	else { thewidth = 320; }	  
	return thewidth;
}
//  This function is called by the open.htm files in the portfolio 
//  folder (or folders within the portflio folder ). The important stored in here
//  includes the reading of the cookie, reading of the filename selected, size of
//  the video, file extension, and default player information.
function openPlayer(){
	//  The folowing reads info on the name of the file.
  	var the_video = location.search.substring(2, location.search.length-1);
	//  The following line sets the default player
	if (document.cookie == "" ){ real(the_video,"hi",320,240,".rm"); }
	//  The following 4 lines reads the cookie
	var the_cookie = document.cookie;
	var broken_cookie = the_cookie.split(":");
	var the_name = broken_cookie[1];
	var the_name = unescape(the_name);
	//  The following sets the extensions, sizes and speeds an calls the appropriate embed function
	if (the_name == "reallo") { real(the_video,"lo",240,180,".rm"); }
	if (the_name == "realmed"){ real(the_video,"med",320,240,".rm"); }
	if (the_name == "realhi") { real(the_video,"hi",320,240,".rm"); }
	if (the_name == "pclo")   { windows(the_video,"lo",240,180,".wax"); }
	if (the_name == "pcmed")  { windows(the_video,"med",320,240,".wax"); }
	if (the_name == "pchi")   { windows(the_video,"hi",320,240,".wax"); }
	if (the_name == "mac")    {	quicktime(the_video,320,240,".mov"); 	}	
	}

//  This function writes the embedded player for Windows Media player. 
//  This stores the information on where the  Windows media is 
//  located and what size to resize the popup.
//  This function is called by the openPlayer function().
function windows(video_name,speed,awidth,aheight,extension) {
 var location_windows = "http://www.arrowire.com/wmp/";
 var thesource = location_windows + video_name + "_" + speed + extension;
	document.write("<center>");
	document.write("  <EMBED TYPE='application/x-mplayer2' ");
    document.write("  PLUGINSPAGE='http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&'");
    document.write("  SRC='" + thesource + "'");
    document.write("  NAME='MediaPlayer' AUTOSTART=1 SHOWCONTROLS=0 width=320 height=240>");
  	document.write("  </EMBED>");
	document.write("  </center>"); }
	
//  This function writes the embedded player for Real player. 
//  This stores the information on where the Real media is 
//  located and what size to resize the popup.
//  This function is called by the openPlayer function().
function real (video_name,speed,awidth,aheight,extension) {
 var location_real = "http://easylink.playstream.com/microdocs/";
 var thesource = location_real + video_name + "_" + speed + extension;
	document.write(" <center>");
	document.write(" <EMBED SRC='" + thesource + "'");
	document.write(" name='RealPlayer' controls='ImageWindow' autostart=true");
	document.write(" width=320 height=240></EMBED>");
	document.write(" <NOEMBED>Your browser cannot embed a Real Player.<br><A HREF='" + thesource + "'>Click here to play with RealPlayer.</A></NOEMBED></center>"); }

//  This function writes the embedded player for the quicktime player. 
//  This stores the information on where the quicktime media is 
//  located and what size to resize the popup.
//  This function is called by the openPlayer function().
function quicktime (video_name,awidth,aheight,extension) {
 var location_quicktime = "http://www.arrowire.com/qt/";
 var thesource = location_quicktime + video_name + "_" + "mstr" + extension;
	document.write(" <center>");
	document.write(" <embed src='" + thesource + "' bgcolor='black' ");
	document.write(" width=320 height=240 autoplay='true' controller='false' cache='true' scale='tofit'>");
	document.write(" </embed></center>"); }
