// JavaScript Document

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function popupScreenshot(filename, imgWidth, imgHeight) {
	var popup = new Array()
	var winWidth
	var winHeight
	var scale
	
	popup.push("<div id='veil' class='veil'>")
	popup.push("<div id='screenshot' class='screenshot' style='width:" + imgWidth + "px; height:" + imgHeight + "px;'>")
	popup.push("<img src='img/close_button.png' class=close_btn onclick=$('popup').innerHTML='' />")
	popup.push("<img src='img/" + filename + "' style='width:100%;height:100%' />")
	popup.push("</div></div>")
	$("popup").innerHTML = popup.join("")
	
	if (isOpera) {
		winWidth = $('veil').style.pixelWidth
		winHeight = $('veil').style.pixelHeight
	} else {
		winWidth = $('veil').offsetWidth
		winHeight = $('veil').offsetHeight
	}
	
	if (imgHeight > winHeight || imgWidth > winWidth) {
		if (imgWidth > winWidth) {
			scale = winWidth/imgWidth*.9
		} else {
			scale = winHeight/imgHeight*.9
		}
			imgWidth = imgWidth * scale
			$('screenshot').style.width = imgWidth + "px";
			imgHeight = imgHeight * scale
			$('screenshot').style.height = imgHeight + "px";
	}
	$('screenshot').style.marginTop = ((winHeight - imgHeight)/2) + "px"
}

function genVidObject(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  return str;
}

function runVidContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return genVidObject(ret.objAttrs, ret.params, ret.embedAttrs);
}

function popupVideo(filename, vidWidth, vidHeight) {
	var popup = new Array()
	var winHeight
	
	popup.push("<div id=veil class=veil>")
	popup.push("<div id=video class=screenshot style='height:" + vidHeight + "px; width:" + vidWidth + "px;'>")
	popup.push("<img src='../img/close_button.png' class=close_btn onclick=$('popup').innerHTML='' />")
    
	popup.push("<noscript>")
    popup.push("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width=" +vidWidth + " height=" + vidHeight + " id='flashvid' align='middle'>")
    popup.push("<param name='allowScriptAccess' value='sameDomain' />")
    popup.push("<param name='allowFullScreen' value='false' />")
    popup.push("<param name='movie' value='" + filename + ".swf' />")
    popup.push("<param name='quality' value='high' />")
    popup.push("<param name='wmode' value='transparent' />")
    popup.push("<param name='bgcolor' value='#ffffff' />")
    popup.push("<embed src='" + filename + ".swf' quality='high' wmode='transparent' bgcolor='#ffffff' width='" + vidWidth + "' height='" + vidHeight + "' name='flashvid' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />")
    popup.push("</object>")
	popup.push("</noscript>")
	
	popup.push(runVidContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width',vidWidth,'height',vidHeight,'id','flashvid','align','middle','src',filename,'quality','high','wmode','transparent','bgcolor','#ffffff','name','flashvid','allowscriptaccess','sameDomain','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',filename ))
	
	popup.push("</div></div>")
	$("popup").innerHTML = popup.join("")
	
	if (isOpera) {
		winHeight = $('veil').style.pixelHeight
	} else {
		winHeight = $('veil').offsetHeight
	}
	$('video').style.marginTop = ((winHeight - vidHeight)/2) + "px"
}