/* utils.js
 * Collection of tools
 * Version 1.0
 */

function getElement(id){
	var elem
	if( document.getElementById ) // this is the way the standards work    
		elem = document.getElementById( id );  
	else if( document.all ) // this is the way old msie versions work      
	 	elem = document.all[id];  
	else if( document.layers ) // this is the way nn4 works    
	 	elem = document.layers[id];
	return elem; 	
	 	
}

function toggle(elem){
	var vis;

	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';

}
function showVideo(videoCode){
	var elem;
	
	elem = getElement('videoPlayer');
	elem.innerHTML = '';
	
	elem = getElement('videoPanel');  
	toggle(elem);
	
	if (elem.style.display == 'block')
	{
		var videoPadding;
		var playerString;
		var panelHeight;

		panelHeight = elem.offsetHeight;
		videoPadding = (panelHeight - 526) / 2; // 450 is the video height + 76 which is other offests
		elem = getElement('videoBackground');
		elem.style.paddingTop = videoPadding + 'px';
		elem.style.height = panelHeight - 76 - videoPadding + 'px';
		//toggle(elem);
		elem = getElement('videoPlayer');
	
		playerString = "<object width='539' height='450'>";
		playerString = playerString + "<param name='movie' value='http://www.youtube.com/v/" + videoCode + "?version=2&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&fs=1&cc_load_policy=1&feature=player_embedded'></param>";
		playerString = playerString + "<param name='allowFullScreen' value='true'></param>";
		playerString = playerString + "<param name='allowScriptAccess' value='always'></param>";
		playerString = playerString + "<embed src='http://www.youtube.com/v/" + videoCode + "?version=2&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&fs=1&cc_load_policy=1&feature=player_embedded'";
		playerString = playerString + "type='application/x-shockwave-flash'";
		playerString = playerString + "allowscriptaccess='always'";
		playerString = playerString + "width='539' height='450'";
		playerString = playerString + "allowfullscreen='true'>";
		playerString = playerString + "</embed>";
		playerString = playerString + "</object>";
		
		elem.innerHTML = playerString;
		
		scroll(0,0);
	}
}	


