//
// these routines are written and (c) by Gregory Mertens, unless noted otherwise
// if you can't help it but to copy them
// please give me credit, i worked hard on them
//
//	pop up quicktime routines
//---------------------------------------------------------------------------


function zoom_qt_window( image_name, width, height, image_title, video_scale)
	{
	//alert("test")
	// this is for callbacks within the pop up window

	write_qt_window (image_name, width, height, image_title,video_scale);
	}
//---------------------------------------------------------------------------


function open_qt_window( image_name, width, height, image_title)
{

	
	//alert("in open window" + image_name + width + height + image_title);

	// this function checks the quicktime status
	// if it's not installed or the wrong version, it warns and does not run

	// ------------------ find out if quicktime is installed
	var qt_status = getCookie('qt_status');
	//var browser_version = getCookie('browser_version');
	//var browser_type    = getCookie('browser_type');


//	alert(qt_status);

	// for people with cookies off
	if (qt_status == null) 	
		{
		write_qt_window (image_name, width, height, image_title,'1x');
		}


	
	// for quicktime 6 users
	if (qt_status == "6") 	
		{
		write_qt_window (image_name, width, height, image_title,'1x');
		}

	// for quicktime 5 or earlier users (ok if the file is an avi)
	if (   (image_name.indexOf ('.avi') > 0)
		&&
		(qt_status == "5")
	  )
		{
		write_qt_window (image_name, width, height, image_title,'1x');
		}
	
	// for quicktime 5 or earlier users and it needs qt 6 (ie, not an avi)
	if (   (image_name.indexOf ('.mov') > 0)
		&&
		(qt_status == "5")
		)
		{
		location.href = '../check/info_check_qt_5.htm';
		}
	
	// for users with no quicktime 
	if (qt_status == "no") 
		{
//		alert('No quicktime found');
		location.href = '../check/info_check_qt_no.htm';
		}
		
//		|| (qt_status == null)) 
// i need to add a warning if there is null in the qt status that means cookies are probably turned off
// so i can't tell if they have it or not

}


//---------------------------------------------------------------------------
function write_qt_window( image_name, width, height, image_title,video_scale){





	// this script is for writing a seperate qt window for qt video
	// (c) 2002 by gregory mertens
	// if you use it in parts or whole, please give me credit
	// i worked hard to create it
		
	// --------------------- constants
	// set the window size outside the image size
	// so that we have a black border

//	alert('opeing qt name = ' + image_name + ' width = ' + width + ' height = ' + height + ' title = ' + image_title);
//	alert(image_name);
	

	var border_size = 20;
	var half_border_size = border_size / 2;

	var logo_width = 355;
	var logo_height = 50;
	// ----------------------------



	// --------- variables
	var window_x = 0;
	var window_y = 0;
	var extra_height = 0;
	var extra_width = 0;
	// ----------------------------


	if (video_scale == null) video_scale = "1x";
		
		

	var sub_name = image_name.length - 4;
	var window_name = image_name.substring(0,sub_name) + video_scale;




	// get the screen size so we can center it
	var screen_width = screen.availWidth;
	var screen_height = screen.availHeight;

	if (video_scale == "1x"){
		scaled_height = height;
		scaled_width = width;
		extra_height = 0;
	}; 

	//alert ("ver c - gregory") ;


	if (video_scale == "2x"){
		scaled_height = height * 2;
		scaled_width  = width * 2;
		extra_height = 0;

		// check the height, make sure there is enough room for the logo and controllers and such
		if (scaled_height > (screen_height - 50)){
			var factor = (screen_height - 50)/ scaled_height;
			scaled_width = width * factor;
			scaled_height = height * factor;
		} // end if

	}// en if 2x


	if (video_scale == "fullx"){
		// get the screen size , less 90 % (so they have some land outside of the window)
		//scale the video to the width (the extra is for the window edge)
		video_factor = (screen_width - border_size - border_size - 10) / width;
	
		scaled_height = height * video_factor;
		scaled_width  = width * video_factor;
	
		// check the height, make sure there is enough room for the logo and controllers and such
		if (scaled_height > (screen_height - 250)){
			var factor = (screen_height - 250) / scaled_height;
			scaled_width = scaled_width * factor;
			scaled_height = scaled_height * factor;
		} // end if
		

		extra_height = Math.ceil ((screen_height - scaled_height) / 4);
		
	}// end if fullx




//	file_prefix = location.host;
	file_prefix = location.protocol;
	//alert(file_prefix);		
	
	if (file_prefix == "www.mertens3d.com")
		full_image_name =  "http://" + file_prefix + '/images_b/animations/' + image_name;
	else
		full_image_name = '/images_b/animations/' + image_name;
	

	var controller_height = 16;

	//height = height + controller_height; // for the controller


	var logo_factor = (width / logo_width )* 0.5;
	logo_height = Math.ceil(logo_height * logo_factor);
	logo_width = Math.ceil(logo_width * logo_factor);
	
	var window_width =  Math.ceil (border_size + scaled_width + border_size + 1);
	//var window_height = Math.ceil (border_size + scaled_height + controller_height + border_size + border_size + half_border_size + logo_height + half_border_size + 1);
	var window_height = Math.ceil (border_size + scaled_height + controller_height + half_border_size + logo_height + half_border_size + 1);
	

	// must be signed for the titlebar option to work
	//	window_controls = window_controls + ',scrollbars=' + (0 - 0);
	//	window_controls = window_controls + ',titlebar=1';
	//alert(window_controls);
	



	if (video_scale == "1x")
	{
		window_x = (screen_width - window_width) / 2;
		window_y = (screen_height / 2) - window_height;
	}; 


	if (video_scale == "2x")
	{
		window_x = (screen_width - window_width) / 2;
		window_y = (screen_height  - window_height) / 3;
	}// end if 2x
		

	if (video_scale == "fullx")
	{
		window_x = 0;
		window_y = 0;
		window_height = screen_height - 50;
		window_width  = screen_width - 15;
		var extra_width = (window_width - scaled_width - border_size - border_size) / 2;
	}// end if fullx

	//----------------------------------------
	// put together the window string

	var window_controls = 'width=' + window_width;

	// tack on extra height for netscape avi when playing from web..i don't know why, but it works

	var window_coords = ',screenX=' + window_x + ',screenY=' + window_y + ',left=' + window_x + ',top=' + window_y;
	window_controls = window_controls + ',height=' + (window_height + 18) + window_coords;




	//--------------------- open the window and draw it

	myWindow = window.open('',window_name,window_controls);
	//myWindow.focus();	 	

//	myWindow.document.writeln('<SCRIPT language="JavaScript" SRC="../qt_window.js"></script>');
	myWindow.document.writeln('<html>');
	myWindow.document.writeln('<head>');
	myWindow.document.writeln("<link href='/mertens_style_b.css' rel='stylesheet' media='screen' />");
//	myWindow.document.writeln('<title>' + image_title + ' - Mertens3d '+ '</title>');
	myWindow.document.writeln('<title>Mertens3d</title>');
	myWindow.document.writeln('</head>');
	myWindow.document.writeln("<body class='qt_body'>");
	//--------------------------------------------------------------------------------------------
	// build the table
	myWindow.document.write  ('<table ');
	myWindow.document.writeln(" border='0' cellspacing='0' cellpadding='0' >");
	//leftmargin="0"
	//--------------------------------------------------------------------------------------------
	// first row
	myWindow.document.writeln('<tr>');
	myWindow.document.writeln("<td><img class='qt_img' alt='' src='/images_b/spacers/coldlight_1x1.gif' width='" + (extra_width + border_size) + "' height='" + (extra_height + border_size) + "' /></td>");
	myWindow.document.writeln("<td colspan='3'><img class='qt_img' alt='' src='/images_b/spacers/coldlight_1x1.gif' width='" + scaled_width + "' height='20' /></td>");
	myWindow.document.writeln("<td><img class='qt_img' alt='' src='/images_b/spacers/coldlight_1x1.gif' width='" + border_size + "' height='" + border_size + "' /></td>");
	myWindow.document.writeln('</tr>');
	//--------------------------------------------------------------------------------------------     
	//second row
	myWindow.document.writeln('<tr>');
	myWindow.document.writeln('<td></td>');	
	myWindow.document.writeln('<td colspan="3">');
	//--------------------------------------------------------------------------------------------
	// here is where we start writing the code for the images 
	myWindow.document.write   (' <object ');
	myWindow.document.write   (' classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ');

	// only write this line if they are using ie 6 or higher
	// it seems to crash ie 5
	// and xp


	//if (browser_type == "explorer" && browser_version == "6")
	//	{
			myWindow.document.write (' codebase="http://www.apple.com/qtactivex/qtplugin.cab" ');
	//	} // end if

	myWindow.document.write   (" height='" + (scaled_height + controller_height) + "'");
	myWindow.document.write   (" width='" + scaled_width + "'");
	myWindow.document.writeln (' >');
	myWindow.document.writeln (" <param name='scale'      value='tofit' />");
	myWindow.document.write   (" <param name='src'        value='");
	myWindow.document.write   (full_image_name);
	myWindow.document.writeln ("' />");
	myWindow.document.writeln (" <param name='autoplay'   value='false' />");
	myWindow.document.writeln (" <param name='controller' value='true' />");

	// ----------------- the embed code
	// do not use writeln on the embed, it needs to be one line 
	myWindow.document.write   (' <embed ');
	myWindow.document.write   (' height="');
	myWindow.document.write   (scaled_height+controller_height);
	myWindow.document.write   ('" ');
	myWindow.document.write   (' pluginspage="http://www.apple.com/quicktime/download/"');
	myWindow.document.write   (' src="');
	myWindow.document.write   (full_image_name);
	myWindow.document.write   ('" ');

	myWindow.document.write   (" type='video/quicktime'");
	myWindow.document.write   (" width='" + scaled_width + "'");
	myWindow.document.writeln (' controller="true" autoplay="false"  scale="tofit" bgcolor="#000000" /> ');
	myWindow.document.writeln (' </object>');
	//------------------------------------------------------------------------	
	// finish the table
	myWindow.document.writeln ('</td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('</tr>');
     	//------------------------------------------------------------------------	
	//third row
	myWindow.document.writeln ('<tr>');
	myWindow.document.writeln ("  <td><img class='qt_img' alt='' src='/images_b/spacers/coldlight_1x1.gif' width='" + half_border_size + "' height='" + half_border_size + "' /></td>");
	myWindow.document.writeln ('  <td colspan="3"></td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('</tr>');
     	//------------------------------------------------------------------------	
	//row - 
	myWindow.document.writeln ('<tr>');
	myWindow.document.writeln ('  <td></td>');
	//myWindow.document.write   ('  <td valign="top"><a href="#" onClick="zoom_qt_window(' );
	//myWindow.document.write   ('  <td valign="top"><form><a href="javascript:zoom_qt_window(' );
	myWindow.document.write   ('  <td>');
	
//	myWindow.document.write   ('\'' + image_name + '\', ' +  width + ' , ' + height + ' , \'' + image_title + '\' , \'1x\'  );window.close()" ');
//	myWindow.document.writeln ('><img border="0" src="/images_b/qt_1x.gif" width=80 height=20></a></form>');
	myWindow.document.writeln ('</td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.write   ("  <td rowspan='4' valign='top' align='right'>");
	myWindow.document.write   ("<img class='qt_img' src='/images_b/black_logo.gif' alt=''" )
	//name="black_logo"');
	myWindow.document.write   (" width='" + logo_width + "'");
	myWindow.document.write   (" height='" + logo_height + "'");
	myWindow.document.writeln (" /></td>");
// this causes a problem
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('</tr>');
     	//------------------------------------------------------------------------	
	//row - 4 columns
	myWindow.document.writeln ('<tr>');
//	myWindow.document.writeln ('<td>');
	myWindow.document.writeln ('  <td></td>');
//	myWindow.document.write   ('  <td><a href="#" onClick="zoom_qt_window(');
	myWindow.document.write   ('  <td>');
//	myWindow.document.write	('<form><a href="javascript:zoom_qt_window(');

//	myWindow.document.write   ('\'' + image_name + '\', ' +  width + ' , ' + height + ' , \'' + image_title + '\' , \'2x\'  );window.close()" ');
//	myWindow.document.writeln ('><img border="0" src="/images_b/qt_2x.gif" width=80 height=20></a></form>');
	myWindow.document.write 	('</td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('</tr>');
     	//------------------------------------------------------------------------	
	//row - 4 columns
	myWindow.document.writeln ('<tr>');
	myWindow.document.writeln ("  <td><img class='qt_img' src='/images_b/spacers/coldlight_1x1.gif' width='" + half_border_size + "' height='" + half_border_size + "' alt='' /></td>");
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('  <td></td>');
	myWindow.document.writeln ('</tr>');
     	//------------------------------------------------------------------------
	//row - 4 columns
	//myWindow.document.writeln ('<tr>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('  <td>');
//	myWindow.document.write	('<p><a href="../pages_b/quicktime.help.htm" target="index_big_frame" ><img border="0" src="/images_b/qt_help.gif" width=80 height=20></a></p>');
	//myWindow.document.write	('</td>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('</tr>');
     	//------------------------------------------------------------------------
	//row - 5 columns
	//myWindow.document.writeln ('<tr>');
	//myWindow.document.writeln ('  <td><img border="0" src="/images_b/spacers/coldlight_1x1.gif" width=' + (border_size + ' ')  + ' height=' + (border_size + ' ') + ' ></td>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('  <td></td>');
	//myWindow.document.writeln ('</tr>');
    	//------------------------------------------------------------------------	
	myWindow.document.writeln ('</table>');
	//------------------------------------------------------------------------
	myWindow.document.writeln ('</body>');
 	myWindow.document.writeln ('</html>');
	

  

	// maybe only close if it is explorer
	myWindow.document.close();
	
	//myWindow.moveTo (window_x,window_y);
  	
// return true;
}
//---------------------------------------------------------------------------

