﻿/**
 * @autor Dennin Dalke Onório
 * @version 0.4 - 04/09/2009
 */
function assignSWF( url, opt )
{
	/** Parâmetros:
	 * url			: url do swf;
	 * elementID	: id do elemento dom;
	 * width		: largura inicial;
	 * height		: altura inicial;
	 * minWidth		: largura mínima;
	 * minHeight	: altura mínima;
	 * version		: versão do flash player;
	 * express		: caminho do instalador express do flash player;
	 * flashvars	: [Object] contendo as variáveis a serem passadas ao flash;
	 * params		: [Object] parâmetros para os elementos object e embed;
	 * attributes	: [Object] atributos do elemento;
	 */
	
	//valores padrão:
	if( ! opt )	opt = {};
	
	if( ! opt.elementID )	opt.elementID	= "flashContent";
	if( ! opt.width )		opt.width		= "100%";
	if( ! opt.height )		opt.height		= "100%";
	if( ! opt.version)		opt.version		= "9.0.0";
	if( ! opt.express )		opt.express		= "swf/expressInstall.swf";
	if( opt.transparent )
	{
		if ( opt.params == null ) opt.params = {};
		
		opt.params.wmode = "transparent";
	}
	if( ! opt.params )		opt.params		= null;
	
	var b	=	browserSize();
	var	w	=	b.width;
	var	h	=	b.height;
	var fW	=	opt.width;
	var fH	= 	opt.height;

	//se houver altura e largura mínima.
	if( opt.minWidth && opt.minHeight )
	{
		if( w < opt.minWidth )	fW	= opt.minWidth;
		if( h < opt.minHeight )	fH	= opt.minHeight;		
		window.onresize = resize;
	}
	
	//adiciona o swf:
	swfobject.embedSWF( url +".swf", opt.elementID, fW, fH, opt.version, opt.express, opt.flashVars, opt.params, opt.attributes);
	
	//função resize chamada apenas se for especificado alutra e largura mínima.
	function resize( event )
	{
		var b	=	browserSize();
		var	w	=	b.width;
		var	h	=	b.height;
		var nW	=	opt.width;
		var nH	= 	opt.height;
		if( w < opt.minWidth )	nW	= opt.minWidth;
		if( h < opt.minHeight )	nH	= opt.minHeight;
		
		var element = document.getElementById( opt.elementID );
		element.height	= nH;
		element.width	= nW;
	}
}
 
function browserSize()
{
	var w, h, d=document;
	
	if ( typeof window.innerWidth!='undefined' )
	{
		w = window.innerWidth;
		h = window.innerHeight;
	} 
	else if (d.documentElement && typeof d.documentElement.clientWidth!='undefined'	&& d.documentElement.clientWidth!=0)
	{
		w = d.documentElement.clientWidth;
		h = d.documentElement.clientHeight;
	}
	else if (d.body	&& typeof d.body.clientWidth!='undefined')
	{
		w = d.body.clientWidth;
		h = d.body.clientHeight;
	}
	var	obj	=	{
		"width": w,
		"height":	h		
	}
	return obj;
}
