var _strSwfID_DW = "swfDaddyViewer";
var _strDivID_DW = "divDaddyViewer";
var _strDivID_DW_Bg = "divDaddyViewerBg";

var _minWidth_DW = 0;
var _minHeight_DW = 0;
var _oSwf_DW = null;
var _divSwfStyle_DW = null;
var _divSwfStyleBg_DW = null;

var _blnDWInit = false;
var _blnDWInit = false;
var _swfObject_DW = null;

var _userAgent = null;
var _blnMac = null;
var _onMacShow = null
var _onMacHide = null;

function initDaddyViewer(swfObject, functionOnMacShow, functionOnMacHide) {
	_userAgent = navigator.userAgent.toLowerCase();
	_blnMac = (userAgent.indexOf("mac")!=-1);
	
	if ( functionOnMacHide != undefined && functionOnMacHide != null && _blnMac ) {
		_onMacHide = functionOnMacHide;
	}
	
	if ( ( functionOnMacShow != null && functionOnMacShow != undefined && !_blnMac ) ||  ( !functionOnMacShow ) ) {
		// IMPORTANT! the daddyViewer must be initiated a reference to swfObject for being able to work in Mozilla!
		_swfObject_DW = swfObject;
		
		_oSwf_DW = getObj(_strSwfID_DW);
		_divSwfStyle_DW = getStyleObj(_strDivID_DW);
		_divSwfStyleBg_DW = getStyleObj(_strDivID_DW_Bg);
		//_divSwfStyle_DW.visibility = "hidden";
		if(document.attachEvent){
			document.attachEvent("onmousewheel", positionDaddyViewer);
		} else {
			window.addEventListener("DOMMouseScroll", positionDaddyViewer, false);
		}
		
		// Add handlers
		onresize = onscroll = onmouseover = function() { positionDaddyViewer(); }
		
		// Init complete
		_blnDWInit = true;
	} else {
		// Special mac version
		_onMacShow = functionOnMacShow;
	}
}

function positionDaddyViewer() {
	_oSwf_DW = getObj(_strSwfID_DW);
	_divSwfStyle_DW = getStyleObj(_strDivID_DW);
	_divSwfStyleBg_DW = getStyleObj(_strDivID_DW_Bg);
	if (_oSwf_DW!=null && _blnDWInit) {
		var p_minwidth = _minWidth_DW;
		var p_minheight = _minHeight_DW;
		var p_width = 0;
		var p_height = 0;
		if (self.innerWidth) {
			p_width = self.innerWidth;
			p_height = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientWidth) {
			p_width = document.documentElement.clientWidth;
			p_height = document.documentElement.clientHeight;
		} else if (document.body) {
			p_width = document.body.clientWidth;
			p_height = document.body.clientHeight;
		}
		if (p_width > p_minwidth) p_minwidth = "100%";
		if (p_height > p_minheight) p_minheight = "100%";
		if (_oSwf_DW!=null) {
			_oSwf_DW.width = p_minwidth;
			_oSwf_DW.height = p_minheight;
		}
		if (document.embeds && document.embeds[_strSwfID_DW]) {
			document.embeds[_strSwfID_DW].width = p_minwidth;
			document.embeds[_strSwfID_DW].height = p_minheight;
		}

		_divSwfStyle_DW.top = getDocInfo().scrollTop;
		_divSwfStyleBg_DW.top = getDocInfo().scrollTop;
	}
}
function daddyViewerShow(strUrl) {
	if ( _onMacShow != null ) {
		_onMacShow();
	} else if ( _oSwf_DW != null ) {
		positionDaddyViewer();
		var mc = "_root";
		var functionName = "show";
		var param = strUrl;
		var strData = mc+"@@"+functionName+"@@"+param;
		if (navigator.appName.indexOf("Microsoft")>-1) {
			_oSwf_DW.SetVariable("jsWatch", strData);
		} else {
			// Mozilla hates wmode=transparent. WHHHYYYYY?
			_swfObject_DW.addVariable("loadUrl", strUrl);
			_swfObject_DW.write(_strDivID_DW);
			
			_oSwf_DW = getObj(_strSwfID_DW);
			_divSwfStyle_DW = getStyleObj(_strDivID_DW);
			_divSwfStyleBg_DW = getStyleObj(_strDivID_DW_Bg);
			
		}
		_divSwfStyle_DW.visibility = "visible";
		_divSwfStyle_DW.top = getDocInfo().scrollTop;
		_divSwfStyleBg_DW.visibility = "visible";
		_divSwfStyleBg_DW.top = getDocInfo().scrollTop;
		
		positionDaddyViewer();
	}
}
function daddyViewerHide() {
	if ( _onMacHide != null ) {
		_onMacHide();
	} else {
		_divSwfStyle_DW.visibility = "hidden";
		_divSwfStyleBg_DW.visibility = "hidden";
	}
}
function daddyViewerSetSize(width,height) {
	_minWidth_DW = width;
	_minHeight_DW = height;
}
function swfDaddyViewer_DoFSCommand(command, args) {
	if (command=="dwHide") {
		daddyViewerHide();
	} else if (command=="dwSetSize") {
		var width = args.split("||")[0];
		var height = args.split("||")[1];
		daddyViewerSetSize(width, height);
	}
}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub '+_strSwfID_DW+'_FSCommand(ByVal command, ByVal args)\n');
	document.write('	call '+_strSwfID_DW+'_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}
function getObj(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId);
	} else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId);
	} else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	} else {
		return null;
	}
}
function getStyleObj(objectId) {
	var o = getObj(objectId);
	if (o!=null && (document.getElementById || document.all)) {
		return o.style;
	} else if (o!=null) {
		return o;
	}
}
function getDocInfo() {
	var o = new Object();
	o.scrollLeft = 0;
	o.scrollTop = 0;
	o.innerWidth = 0;
	o.innerHeight = 0;
	// ---=== Scrolling
	if (document.all) {
		if (!document.documentElement.scrollLeft) {
			o.scrollLeft = document.body.scrollLeft;
		} else {
			o.scrollLeft = document.documentElement.scrollLeft;
		}
		if (!document.documentElement.scrollTop) {
			o.scrollTop = document.body.scrollTop;
		} else {
			o.scrollTop = document.documentElement.scrollTop;
		}
	} else {
		o.scrollLeft = window.pageXOffset;
		o.scrollTop = window.pageYOffset;
	}
	// Inner size
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		o.innerWidth = window.innerWidth;
		o.innerHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		o.innerWidth = document.documentElement.clientWidth;
		o.innerHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		o.innerWidth = document.body.clientWidth;
		o.innerHeight = document.body.clientHeight;
	}
	return o;
}
