// Sets up trailers
//
// Requires a global gOverlay for show/close functions to work

var movieWidth = 640
var movieHeight = 480
var mainDiv = 'trailerdiv'

// init function...
window.addEvent('domready', initTrailer)

function flvSize(w, h){
	movieWidth = w
	movieHeight = h + 45
}

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

function initTrailer() {
	// create the trailer DIV
	var mainDivObj = new Element('div').setStyles({
		width: movieWidth,
		height: movieHeight,
		display: 'none',
		position: 'absolute',
		zIndex: 11,
		left: Math.round(Math.abs((window.getWidth() / 2) - (movieWidth / 2))),
		top: Math.round(Math.abs((window.getHeight() / 2) - (movieHeight / 2)))
	}).setProperty('id', mainDiv).injectInside(document.body)

	// needed for full overlay compatibility
	mainDivObj.hide = function() { this.style.display = 'none' }
}

function prepTrailer(mId, mType) {
	$(mainDiv).setHTML('<div id="trailertitle"><img src="/images/site_design/close.gif" id="clsbtn" onclick="javascript:closeTrailer()" /></div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+movieWidth+'" height="'+movieHeight+'" id="trailer_player"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/trailers/trailer_player.swf?movie_id='+mId+'&movie_type='+mType+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="scale" value="noborder" /><embed src="/trailers/trailer_player.swf?movie_id='+mId+'&movie_type='+mType+'" quality="high" wmode="transparent" scale="noborder" width="'+movieWidth+'" height="'+movieHeight+'" name="trailer_player" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>')
}

function closeTrailer() {
	thisMovie('trailer_player').stopVideo()
	gOverlay.hide()
	$(mainDiv).style.display = 'none'
}

function showTrailer() {
	var trailerTimer = setTimeout("$(mainDiv).style.display='block'", 1000);
	$(mainDiv).style.display = 'block'
	gOverlay.show($(mainDiv))
}