/*********************************************************
	DHTML Effects and Tools (c) 2007, David Emerson
	Emerson Media :: www.emersonmedia.com
*********************************************************/

var FADE_SPEED = 10;  // the higher, the slower
var FADE_UNTIL = 80;  // the higher, the more opaque
var FLASH_WIDTH = 780;
var FLASH_HEIGHT = 524;

/********************************************************/

flash_image = new Image();
flash_image.src = "uploads/images/flash_bg.gif";

var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
var opacity_in = 0;
var opacity_out = FADE_SPEED;
var opacity_mult = FADE_UNTIL / FADE_SPEED;
var arr_size_pos = new Array();

function play_flash(file_num) {
	fade_flash('in',1,file_num);
}
function exit_flash() {
	fade_flash('out',0,'0');
}
function alert_flash_vars() {
}

// fade background in and out
function fade_flash(direction, first_time, file_num) {
	if(direction == "in") {
		if(first_time == 1) {
			arr_size_pos = get_window_size_pos();
			document.getElementById('flash_wrapper_outer').style.display = "block";
			document.getElementById('flash_wrapper_outer').style.top = arr_size_pos[3];
			document.getElementById('flash_wrapper_outer').style.height = "100%";
			document.getElementById('flash_fader').style.display = "block";
			document.getElementById('flash_wrapper_inner').style.display = "block";
			document.getElementById('flash_wrapper_inner').style.top = (arr_size_pos[1] - FLASH_HEIGHT) / 2;
			document.getElementById('flash_wrapper_inner').style.left = (arr_size_pos[0] - FLASH_WIDTH) / 2;

			// if dropdown boxes appear through the Flash (IE), unhide them
			if(document.getElementById('id_of_dropdown'))
				document.getElementById('id_of_dropdown').style.display = "none";
		}
		if(opacity_in < FADE_SPEED) {
			opacity_in += 1;
			opacity_calc = opacity_in * opacity_mult;
			if(ie5) {
				document.getElementById('flash_fader').filters.alpha.opacity = opacity_calc;
				document.getElementById('flash_wrapper_inner').filters.alpha.opacity = opacity_calc;
			}
			if(ns6) {
				document.getElementById('flash_fader').style.MozOpacity = opacity_calc * 0.01;
				document.getElementById('flash_wrapper_inner').style.MozOpacity = opacity_calc * 0.01;
			}
			setTimeout("fade_flash('in', 0, '" + file_num + "')", 1);
		} else {
			// stop fading; set flash background to 100%
			if(ie5)
				document.getElementById('flash_wrapper_inner').filters.alpha.opacity = 100;
			if(ns6)
				document.getElementById('flash_wrapper_inner').style.MozOpacity = 1;

			// configure the flash to play
			var flash_vars;
			if(file_num == 100)
				flash_vars = "";
			else
				flash_vars = "?current_file_html=" + file_num;
			var flash_string = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"760\" height=\"504\" id=\"shell\" align=\"middle\">";
			flash_string += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
			flash_string += "<param name=\"movie\" value=\"uploads/Flash/shell_r.swf" + flash_vars + "\" />";
			flash_string += "<param name=\"loop\" value=\"false\" />";
			flash_string += "<param name=\"menu\" value=\"true\" />";
			flash_string += "<param name=\"quality\" value=\"high\" />";
			flash_string += "<param name=\"wmode\" value=\"opaque\" />";
			flash_string += "<param name=\"bgcolor\" value=\"#ffffff\" />";
			flash_string += "<embed src=\"uploads/Flash/shell_r.swf" + flash_vars + "\" loop=\"false\" menu=\"true\" quality=\"high\" wmode=\"opaque\" bgcolor=\"#ffffff\" width=\"760\" height=\"504\" name=\"shell\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
			flash_string += "</object>";

			document.getElementById('flash_container').style.display = "block";
			document.getElementById('flash_container').innerHTML = flash_string;
		}

	} else {

		document.getElementById('flash_container').style.display = "none";
		if(opacity_out > 0) {
			opacity_out -= 1;
			opacity_calc = opacity_out * opacity_mult;
			if(ie5) {
				document.getElementById('flash_fader').filters.alpha.opacity = opacity_calc;
				document.getElementById('flash_wrapper_inner').filters.alpha.opacity = opacity_calc;
			}
			if(ns6) {
				document.getElementById('flash_fader').style.MozOpacity = opacity_calc * 0.01;
				document.getElementById('flash_wrapper_inner').style.MozOpacity = opacity_calc * 0.01;
			}
			setTimeout("fade_flash('out', 0, '0')", 1);
		} else {
			// if dropdown boxes appear through the Flash (IE), unhide them
			if(document.getElementById('id_of_dropdown'))
				document.getElementById('id_of_dropdown').style.display = "block";

			document.getElementById('flash_fader').style.display = "none";
			document.getElementById('flash_wrapper_inner').style.display = "none";
			document.getElementById('flash_wrapper_outer').style.display = "none";
			// reset variables
			opacity_in = 0;
			opacity_out = FADE_SPEED;
		}
	}
}


function get_window_size_pos() {

	var win_width = 0;
	var win_height = 0;
	var scroll_x = 0;
	var scroll_y = 0;

	// get window size
	if(typeof(window.innerWidth) == 'number') {
		//Non-IE
		win_width = window.innerWidth;
		win_height = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		win_width = document.documentElement.clientWidth;
		win_height = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		win_width = document.body.clientWidth;
		win_height = document.body.clientHeight;
	}

	// get scrolled position
	if(typeof(window.pageYOffset) == 'number') {
		//Netscape compliant
		scroll_y = window.pageYOffset;
		scroll_x = window.pageXOffset;
	} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scroll_y = document.body.scrollTop;
		scroll_x = document.body.scrollLeft;
	} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scroll_y = document.documentElement.scrollTop;
		scroll_x = document.documentElement.scrollLeft;
	}
	return [win_width,win_height,scroll_x,scroll_y];
}
