var _HTTP_PATH_ = document.domain;
var loader_timer = 0;

var Flash = {
	insert : function(element, src, version, width, height, properties, callback) {
		callback = callback || null;
		properties = properties || {};
		var flashObj = null;

		jQuery.extend(flashObj = {
			src : src,
			width : width || 320,
			height : height || 240,
			name: "flashContent",
			id: "flashContent",
			allowscriptaccess: "samedomain",
			swliveconnect: true
		}, properties);
		jQuery(element)
			.flash(flashObj, { version : version || 9 });
		try {
			with(Flash.getInstance(element + ' embed')) {
				TSetProperty("/",7, 0);
				//if (StopPlay())
					//StopPlay();
			}
		} catch (Exception) {}
	},
	getInstance : function(element) {
		return jQuery(element)[0];
	},
	checkLoaded: function(element, options) {
		var flashElement = this.getInstance(element),
			percent = 0;
		try {
			 percent = flashElement.PercentLoaded() ? parseInt(flashElement.PercentLoaded(), 10) : 0;			 
		} catch (Exception) {}
		
		jQuery('div#progress_bar')
			.find('p.bar_container span.bar')
				.css('width', percent * 5.6 + "px")
			.parent()
			.parent()
				.find('div.percentage_loaded span.progress')
				.html(percent + "%");
		if ((percent < 100))			
			loader_timer = setTimeout('Flash.checkLoaded("' + element +  '", {width: ' + options.width + ', height: ' + options.height + '});', 1);
		else {
			clearTimeout(loader_timer);
			try {
				with(flashElement) {
					TSetProperty("/",7, 1);					
					width = options.width || "320";
					height = options.height || "240";
				}
			} catch (Exception) {				
				flashElement.width = options.width || "320";
				flashElement.height = options.height || "240";
			}
			jQuery('div#progress_bar').remove();			
			jQuery(element).parent().css('height', flashElement.height + "px");
//			jQuery("#comp_game").css('display', 'block');
//			jQuery("#comp_game").css('padding', '2%');
//			jQuery(".jogohome").css('background-color', '#F5F5F5');
		}
	}
};

function getFlashObj(movie){
   if (window.document[movie]) {
      return window.document[movie];
   }
   if (navigator.appName.indexOf("Microsoft Internet")==-1) {
      if (document.embeds && document.embeds[movie]) {
         return document.embeds[movie]; 
      }
   } else {
      return document.getElementById(movie);
   }
}