var _ = {
	events: {
		expand: function(e) {
			e = e || window.event;
			if (!e) return;
			//if (!e) e = event;
			return {e: e, o: e.srcElement || e.target};
		}
	},
	menu: {
		mouseover: function(e) {
			e = _.events.expand(e);
			var num = e.o.id.split('_')[2];
			if (!num) return;
			$('#menu_second_' + num).css('display', 'block');
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.actual_id = num;
			_.menu.show_active();
		},
		mouseout: function(num) {
			if (!num) num = _.menu.original_id;
			$('#menu_second_' + num).css('display', 'none');
			_.menu.actual_id = null;
			_.menu.show_active();
			$('#menu_second_' + _.menu.original_id).css('display', 'block');
		},
		mousetimer: function(e) {
			e = _.events.expand(e);
			var num = e.o.id.split('_')[2];
			if (!num) return;
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.timer = setTimeout('_.menu.mouseout('+ num +')', 500);
		},
		show_active: function() {
			var i = _.menu.nodes_length, nodes = _.menu.nodes, num, actual = _.menu.actual_id;
			for (; i >= 0; --i) {
				num = nodes[i].id.split('_')[2];
				if ($('#menu_second_' + num)[0]) $('#menu_second_' + num)[0].style.display = actual == num ? 'block' : 'none';
			}
		},
		sub_mouseover: function() {
			if (_.menu.timer) clearTimeout(_.menu.timer);
		},
		mouseout_header : function() {
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.timer = setTimeout('_.menu.mouseout('+ _.menu.original_id +')', 500);
		},
		canvas_onmouseover: function(e) {
			e = _.events.expand(e);
			num = e.o.parentNode.parentNode.parentNode.id.split('_')[2];
			if (!num) return;
			$('#menu_second_' + num).css('display', 'block');
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.actual_id = num;
			_.menu.show_active();
		},
		cufon_onmouseover: function(e) {
			e = _.events.expand(e);
			num = e.o.parentNode.parentNode.id.split('_')[2];
			if (!num) return;
			$('#menu_second_' + num).css('display', 'block');
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.actual_id = num;
			_.menu.show_active();
		},
		canvas_mousetimer: function(e) {
			e = _.events.expand(e);
			var num = e.o.parentNode.parentNode.parentNode.id.split('_')[2];
			if (!num) return;
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.timer = setTimeout('_.menu.mouseout('+ num +')', 500);
		},
		cufon_mousetimer: function(e) {
			e = _.events.expand(e);
			var num = e.o.parentNode.parentNode.id.split('_')[2];
			if (!num) return;
			if (_.menu.timer) clearTimeout(_.menu.timer);
			_.menu.timer = setTimeout('_.menu.mouseout('+ num +')', 500);
		},
		original_id: null,
		actual_id: null,
		timer: null,
		nodes: null,
		nodes_length : null
	},
	clickers: {
		front: function() {
			if (_.gallery.temp) _.gallery.all = _.gallery.temp;
			$('#front_block').css('display', 'block');
			$('#back_block').css('display', 'none');
			$('#front_block_div').css('color', '#38667F');
			$('#front_block_div').css('background', '#fff');
			$('#back_block_div').css('color', '#fff');
			$('#back_block_div').css('background', '#38667F');
			$('#arrow1').attr('src', '/_/arrow_fw_small_go.png');
			$('#arrow2').attr('src', '/_/arrow_small_white.png');
			return false;
		},
		back: function() {
			_.gallery.temp = _.gallery.all;
			_.gallery.all = _.gallery.all_back;
			$('#front_block').css('display', 'none');
			$('#back_block').css('display', 'block');
			$('#front_block_div').css('color', '#fff');
			$('#front_block_div').css('background', '#38667F');
			$('#back_block_div').css('color', '#38667F');
			$('#back_block_div').css('background', '#fff');
			$('#arrow1').attr('src', '/_/arrow_small_white.png');
			$('#arrow2').attr('src', '/_/arrow_fw_small_go.png');
			return false;
		},
		temp: [],
		all: [],
		all_back: []
	},
	preview: {
		close: function(e) {
			e = _.events.expand(e);
			var num = e.o.id;
			if (num == 'preview_block' || num == 'preview_close') $('#preview_block').css('display', 'none');
		},
		open: function (e) {
			e = _.events.expand(e);
			var src = e.o.src, id = e.o.id;
			if (!src || !id) return;
			_.gallery.current = id = parseInt(id.split('_')[1], 10);
			_.preview.resize(id);
			_.preview.check_arrows();
			var temp = src.split('/');
			if (!_.gallery.all[id]) return;
			if (_.gallery.all[id]['big']) $('#preview_current')[0].src = _.gallery.all[id]['big'];
			if (_.gallery.all[id]['title']) $("#preview_title").html(_.gallery.all[id]['title']);
			$('#preview_block').css('display', 'block');
		},
		resize: function(id) {
			var width = 463, height = 404, largewidth = _.preview.extralarge_width, largeheight = _.preview.extralarge_height;
			if (!_.gallery.all[id] || !_.gallery.all[id]['size']) return;

			if (_.gallery.all[id]['width']) largewidth = parseInt(_.gallery.all[id]['width'], 10);
			if (_.gallery.all[id]['height']) largeheight = parseInt(_.gallery.all[id]['height'], 10);

			if (_.gallery.all[id]['size'] == 'extralarge') {
				$('#preview_current').css('width', largewidth +'px');
				$('#preview_current').css('height', largeheight +'px');
				$('#preview_box').css('width', largewidth +'px');
				$('#preview_box').css('height', (largeheight + 59) +'px');
				$('#preview_current').css('width', largewidth +'px');
				$('.preview_box_bottom').css('width', largewidth +'px');
			} else {
				$('#preview_current').css('width', width +'px');
				$('#preview_current').css('height', height +'px');
				$('#preview_box').css('width', width +'px');
				$('#preview_box').css('height', (height  + 59) +'px');
				$('.preview_box_bottom').css('width', width +'px');
			}
		},
		check_arrows: function() {
			var current = _.gallery.current, left = $('.preview_left'), right = $('.preview_right');
			if (!current) left.css('display', 'none');
			else left.css('display', 'block');
			if (_.gallery.all.length - current === 1) right.css('display', 'none');
			else right.css('display', 'block');
		},
		extralarge_width: 663,
		extralarge_height: 404
	},
	gallery: {
		next: function(e) {
			e = _.events.expand(e);
			var next = _.gallery.current + 1, scroll = (next + 4) % 5, id = e.o.id;
			if (id == 'gallery_left' || id == 'gallery_right') scroll = 0;
			if (!_.gallery.all[next]) return false;
			$('#preview_current')[0].src = '/_/_.png';
			_.preview.resize(next);
			$('#preview_current')[0].src = _.gallery.all[next]['big'];
			$("#preview_title").html(_.gallery.all[next]['title']);
			$('#scroller').scrollLeft($('#scroller').scrollLeft() + (scroll ? 69.5 : 278));
			_.gallery.count--;
			_.gallery.current = next;
			_.preview.check_arrows();
			return false;
		},
		previous: function(e) {
			$('#preview_current')[0].src = '/_/_.png';
			e = _.events.expand(e);
			var scroller = $('#scroller').scrollLeft();
			var previous = _.gallery.current - 1, scroll = (previous + 5) % 5, id = e.o.id;
			if (id == 'gallery_left' || id == 'gallery_right') scroll = 0;
			if (!_.gallery.all[previous]) return false;
			_.preview.resize(previous);
			$('#preview_current')[0].src = _.gallery.all[previous]['big'];
			$("#preview_title").html(_.gallery.all[previous]['title']);
			$('#scroller').scrollLeft(scroller - (scroll ? 69.5 : 278));
			_.gallery.count++;
			_.gallery.current = previous;
			_.preview.check_arrows();
			return false;
		},
		count: 0,
		all: {},
		all_back: {},
		all_temp: {},
		current: 0
	},
	houses: {
		over: function(e) {
			e = _.events.expand(e);
			var id = e.o.id;
			$('#houses_bg_title').css('display', 'block')
			if (e.o.title != '') {
				e.o.setAttribute('alt', e.o.title);
				e.o.setAttribute('title', '');
			}
			$('#houses_bg_title').html(e.o.alt);
			$('#houses_bg_title').css('left', _.houses.x + 7).css('top', _.houses.y + 7);
			id = id.split('_')[2];
			if ($('#little_map_classer')[0]) $('#little_map_classer')[0].className = 'little_map_house_'+ id;
		},
		out: function(e) {
			e = _.events.expand(e);
			var id = e.o.id;
			$('#houses_bg_title').css('display', 'none');
			id = id.split('_')[2];
			if ($('#little_map_classer')[0]) $('#little_map_classer')[0].className = 'little_map_house_0';
			if (_.houses.original_id) $('#little_map_classer')[0].className = 'little_map_house_'+ _.houses.original_id;
		},
		x: 0,
		y: 0,
		original_id : null
	},
	four_houses: {
		over: function(e) {
			e = _.events.expand(e);
			var id = e.o.id.split('_')[2];
			if (id == _.four_houses.last_id) return;
			for (var i = 4; i > 0; i--) {
				$('#show_one_house_'+ i).css('display', (i == id ? 'none' : 'block'));
				$('#show_one_house_'+ i).css('z-index', (i == id ? '0' : '10'));
			}
			clearTimeout(_.four_houses.timeout);
			e = _.events.expand(e);
			$('#show_one_house_'+ _.four_houses.last_id).css('display', 'block');
			$('#show_one_house_'+ id).css('display', 'none');
			_.four_houses.active_id = id;
		},
		out: function(e) {
			e = _.events.expand(e);
			var id = e.o.id.split('_')[2];
			_.four_houses.timeout = setTimeout(_.four_houses.hide_all, 50);
			_.four_houses.last_id = id;
		},
		hide_one: function(e) {
			clearTimeout(_.four_houses.timeout);
			e = _.events.expand(e);
			var id = e.o.id.split('_')[3];
			$('#show_one_house_'+ _.four_houses.last_id).css('display', 'block');
			$('#show_one_house_'+ id).css('display', 'none');
		},
		hide_all: function() {
			for (var i = 4; i > 0; i--) {
				$('#show_one_house_'+ i).css('display', 'none');
			}
			_.four_houses.last_id = null;
		},
		timeout: null,
		last_id: null,
		active_id: null
	},
	house_one: {
		click: function(e) {
			e = _.events.expand(e);
			var id = e.o.id.split('_')[2];
			Building.changeFloor(id);
			_.house_one.original_id = id;
			location.hash = '#'+ id;
			return false;
		},
		gohref: function(e) {
			e = _.events.expand(e);
			var id = e.o.id.split('_')[2];
			location.href = _.house_one.floor_link + id;
			return false;
		},
		over: function (e) {
			clearTimeout(_.house_one.return_timer);
			e = _.events.expand(e);
			var id = e.o.id.split('_')[2], current = _.house_one.current_id;
			if ($('#floor_' + _.house_one.original_id)[0]) $('#floor_' + _.house_one.original_id)[0].style.display = 'none';
			if ($('#floor_' + current)[0]) $('#floor_' + current)[0].style.display = 'none';
			if ($('#floor_' + id)[0]) $('#floor_' + id)[0].style.display = 'block';
			_.house_one.current_id = id;
			_.house_one.show_tooltip();
		},
		clear: function() {
			_.house_one.return_timer = setTimeout(_.house_one.out, 500);
		},
		out: function() {
			if ($('#floor_' + _.house_one.current_id)[0]) $('#floor_' + _.house_one.current_id)[0].style.display = 'none';
			if ($('#floor_' + _.house_one.original_id)[0]) $('#floor_' + _.house_one.original_id)[0].style.display = 'block';
			$('#houses_bg_title').css('display', 'none');
		},
		choose_floor: function(id, data) {
			_.house_one.original_id = id;
			if ($('#floor_' + id)[0]) $('#floor_' + id)[0].style.display = 'block';
			if (data) {
				Building.init(id, data);
			}
		},
		set_free_apartment_data: function(free_apartments) {
			_.house_one.free_apartments = free_apartments;
		},
		show_tooltip: function(e) {
			e = _.events.expand(e);
			if (!e) return;
			var floor = e.o.id.split('_')[2];
			var free_ap_cnt = '';
			var floor_i = floor - 3;
			for (var i in _.house_one.free_apartments) {
				if (floor_i == i) {
					free_ap_cnt = _.house_one.free_apartments[i];
					break;
				}
			}
			var tool_tip =  _.house_one.floor_string  + ' ' + floor + '<br>'+ _.house_one.free_apartment_string + ': ' + free_ap_cnt;
			$('#houses_bg_title').css('display', 'block').html(tool_tip).css('left', _.houses.x + 7).css('top', _.houses.y + 7);
		},
		x: 0,
		y: 0,
		floor_link: null,
		current_id: 0,
		original_id: 0,
		free_apartments: [],
		free_apartment_string: '',
		floor_string: '',
		return_timer: null
	},
	indexPage: false,
	alignIndexPage: function() {
		if (!_.indexPage && _.indexPage !== true) return;
		var h = parseInt((window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight), 10);
		if (h < 813) h = 813;
		$('#main_flash_container').css('height', h +'px');
	},
	cachedImages: [],
	common: {
		current_fade_text_id: null,
		text_scroll_interval: null,
		history_back: function() {
			history.back();
		},
		fade_text: function(e) {
			e = _.events.expand(e);
			var id = e.o.id.split('_')[1], text_id = _.common.current_fade_text_id;
			if (id != text_id && text_id !== null) $('#text_show_'+ text_id).toggle('fast');
			$('#text_show_'+ id).toggle('fast');
			$('.for_text_respawn').html(_.common.read_more_string);
			$('#text_'+ id).html((id == text_id ? _.common.read_more_string : _.common.close_string));
			setTimeout(_.common.refresh_text_scroller, 500);
			_.common.current_fade_text_id = id == text_id ? null : id;
		},
		read_more_string: null,
		close_string: null,
		refresh_text_scroller: function() {
			var h = parseInt($('#main_middle_text_left')[0].scrollHeight, 10);
			if (h < 213) {
				$('#main_middle_text_scroll_up').css('visibility', 'hidden');
				$('#main_middle_text_scroll_down').css('visibility', 'hidden');
				return;
			}
			if ($('#main_middle_text_left').scrollTop() > 0) $('#main_middle_text_scroll_up').css('visibility', 'visible');
			if (h > ($('#main_middle_text_left').scrollTop() + 212)) $('#main_middle_text_scroll_down').css('visibility', 'visible');
		},
		init_text_scroller: function() {
			_.common.refresh_text_scroller();
			var textScrollInterval = null;
			$('#main_middle_text_scroll_up')[0].onmouseover = function() {
				if (textScrollInterval) clearInterval(textScrollInterval);
				textScrollInterval = setInterval(function(){
					$('#main_middle_text_left').scrollTop($('#main_middle_text_left').scrollTop() - 5);
					if ($('#main_middle_text_left').scrollTop() > 0) $('#main_middle_text_scroll_up').css('visibility', 'visible');
					else $('#main_middle_text_scroll_up').css('visibility', 'hidden');

					if (parseInt($('#main_middle_text_left')[0].scrollHeight, 10) > ($('#main_middle_text_left').scrollTop() + 212))
						$('#main_middle_text_scroll_down').css('visibility', 'visible');
					else $('#main_middle_text_scroll_down').css('visibility', 'hidden');
				}, 25);
			}
			$('#main_middle_text_scroll_up')[0].onmouseout = function() {
				if (textScrollInterval) clearInterval(textScrollInterval);
			}
			$('#main_middle_text_scroll_down')[0].onmouseover = function() {
				if (textScrollInterval) clearInterval(textScrollInterval);
				textScrollInterval = setInterval(function(){
					$('#main_middle_text_left').scrollTop($('#main_middle_text_left').scrollTop() + 5);
					if ($('#main_middle_text_left').scrollTop() > 0) $('#main_middle_text_scroll_up').css('visibility', 'visible');
					else $('#main_middle_text_scroll_up').css('visibility', 'hidden');

					if (parseInt($('#main_middle_text_left')[0].scrollHeight, 10) > ($('#main_middle_text_left').scrollTop() + 212))
						$('#main_middle_text_scroll_down').css('visibility', 'visible');
					else $('#main_middle_text_scroll_down').css('visibility', 'hidden');
				}, 25);
			}
			$('#main_middle_text_scroll_down')[0].onmouseout = function() {
				if (textScrollInterval) clearInterval(textScrollInterval);
			}
		}
	}
}

var Building = {
	data: {},
	paint: false,
	init: function(floor, data) {
		this.data = data;
		this.paint = new CanvasPointPainter();
		this.paint.setResultAreaId('result');
		this.changeFloor(floor);
		var current_floor_id = this.getFloorIdByNumber(floor);
		$(document).ready(function() {
			Building.waitToDraw(current_floor_id);
		});
	},
	waitToDraw: function(current_floor_id) {
		if (!my$('empty_canvas') ||
			!my$('empty_canvas').getContext) {
			setTimeout('Building.waitToDraw('+ current_floor_id +')', 50);
		} else {
			Building.drawPlan(current_floor_id);
		}
	},
	getFloorIdByNumber: function(i) {
		return this.data.floor_ids[i] ? this.data.floor_ids[i] : false;
	},
	changeFloor: function(i) {
		var floor_id = this.getFloorIdByNumber(i);
		if (!floor_id) return false;
		var floor = this.data.floors[floor_id];
		$('#floor_number').html(floor.number);
		$('#free_apartment_count').html(floor.free_apartments);
		$('#result').css('background', 'url(\''+ this.data.floors[floor_id].img +'\') top left no-repeat');
		this.waitToDraw(floor_id);
	},
	drawPlan: function(id) {
		var scheme = this.data.schemes[id];
		if (!scheme) {
			$('#front_block').hide();
			return false;
		}
		else $('#front_block').show();

		this.paint.setResultData(scheme);
		this.paint.drawResult();
	},
	showFlatInfo: function(rooms, area) {
		$('.source_apartment').css('display', 'block');
		$('.source_space').css('display', 'block');

		$('#apartment_rooms').html(rooms);
		$('#apartment_area').html(area);
	},
	hideFlatInfo: function() {
		$('.source_apartment').css('display', 'none');
		$('.source_space').css('display', 'none');
	}
};


$(document).ready(function() {
	_.alignIndexPage();



	/*Cufon.replace('.main_top_address', {fontWeight: '100', fontFamily: 'Myriad'});
	Cufon.replace('.main_top_ready_text', {fontWeight: '100', fontFamily: 'Myriad'});
	Cufon.replace('.sub_menu_item', {fontWeight: '700', fontFamily: 'Myriad'});
	Cufon.replace('.sub_menu_font', {fontWeight: '700', fontFamily: 'Myriad'});
	Cufon.now();
	* */

	var nodes = _.menu.nodes = $('.main_menu_js'), i = _.menu.nodes_length = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmouseover = _.menu.mouseover;
		nodes[i].onmouseout = _.menu.mousetimer;
	}


	nodes = $('canvas'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmouseover = _.menu.canvas_onmouseover;
		nodes[i].onmouseout = _.menu.canvas_mousetimer;
	}

	nodes = $('cufon'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmouseover = _.menu.cufon_onmouseover;
		nodes[i].onmouseout = _.menu.cufon_mousetimer;
	}

	nodes = $('.sub_menu_js'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmouseover = _.menu.sub_mouseover;
		nodes[i].onmouseout = _.menu.mousetimer;
	}

	if (!$('.header')[0]) return;
	$('.header')[0].onmouseout = _.menu.mouseout_header;
	if ($('#front_block_clicker')[0]) $('#front_block_clicker')[0].onclick = _.clickers.front;
	if ($('#back_block_clicker')[0]) $('#back_block_clicker')[0].onclick = _.clickers.back;
	if ($('#preview_block')[0]) $('#preview_block')[0].onclick = _.preview.close;
	nodes = $('.scroll'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onclick = _.preview.open;
	}
	if ($('.gallery_left')[0]) $('.gallery_left')[0].onclick = _.gallery.previous;
	if ($('.gallery_right')[0]) $('.gallery_right')[0].onclick = _.gallery.next;
	if ($('.preview_left')[0]) $('.preview_left')[0].onclick = _.gallery.previous;
	if ($('.preview_right')[0]) $('.preview_right')[0].onclick = _.gallery.next;
	if ($('#preview_current')[0]) $('#preview_current')[0].onclick = _.gallery.next;
	if ($('.preview_close')[0]) $('.preview_close')[0].onclick = _.preview.close;
	nodes = $('.houses_map_area'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmousemove = _.houses.over;
		nodes[i].onmouseout = _.houses.out;
	}

	nodes = $('.four_houses_map'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmouseover = _.four_houses.over;
		nodes[i].onmouseout = _.four_houses.out;
	}

	nodes = $('.house_one_ares'), i = nodes.length - 1;
	if ($('.one_floor_link')[0]) {
		for (; i >= 0; --i) {
			nodes[i].onmousemove = _.house_one.show_tooltip;
			nodes[i].onmouseover = _.house_one.over;
			nodes[i].onmouseout = _.house_one.clear;
			nodes[i].onclick = _.house_one.gohref;
		}
	} else {
		for (; i >= 0; --i) {
			nodes[i].onmousemove = _.house_one.show_tooltip;
			nodes[i].onmouseover = _.house_one.over;
			nodes[i].onmouseout = _.house_one.clear;
			nodes[i].onclick = _.house_one.click;
		}
	}

	nodes = $('.absolute_four_houses'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onmouseover = _.four_houses.hide_one;
	}

	if ($('.main_middle_images_goback')[0]) $('.main_middle_images_goback')[0].onclick = _.common.history_back;
	
	nodes = _.cachedImages, i = nodes.length - 1;
	for (; i >= 0; --i) {
		CacheElements.store(nodes[i]);
	}
	
	if ($('#sound_image')[0]) {
		$('#sound_image')[0].onclick = function() {
			$('#sound_image').css('display', 'none');
			$('#sound_image2').css('display', 'block');
		};
	}

	if ($('#sound_image2')[0]) {
		$('#sound_image2')[0].onclick = function() {
			$('#sound_image2').css('display', 'none');
			$('#sound_image').css('display', 'block');
		};
	}
	
	nodes = $('.for_text_respawn'), i = nodes.length - 1;
	for (; i >= 0; --i) {
		nodes[i].onclick = _.common.fade_text;
	}
	
	/* I don't know why, but it works exactly that way */
	if ($('.preview')) {
		$('.preview').height($(document).height());
		$('.preview').width($('body').width());
		$('body').height($(document).height());
		$('.shadow_bottom_right_inner').height($(document).height());
	}
	
	$('.hide').css('display', 'none');

	CacheElements.now();

	$(document).mousemove(function(e) {
		_.houses.x = e.pageX;
		_.houses.y = e.pageY;
   });
});

$(window).bind('resize', function() {
	_.alignIndexPage();
	if (!$('#main_background')) return;
	var h = $('#main_background').height();
	$('#br_shadow').css('height', h+'px');
	$('#br_shadow').css('height', h+'px');
});

$(window.document).bind('mouseover', function(e) {
	e = _.events.expand(e);
	$('#text').html(e.o.className);
});


// Preload images, image cache
var CacheElements = {
	o: null,
	storage: [],
	stored: [],
	delay: 0,
	current: 0,
	interval: null,
	store: function(src) {
		var es = CacheElements.storage, i = 0, so = es.length;
		for (; i < so; i++) {
			if (es[i] === src) return;
		}
		CacheElements.storage[so] = src;
		CacheElements.stored[so] = false;
	},
	now: function() {
		if (!CacheElements.o) {
			var div = document.createElement('DIV');
			div.style.position = 'absolute';
			div.style.top = '-9999px';
			div.style.left = '-9999px';
			CacheElements.o = document.body.appendChild(div);
			div = document.createElement('DIV');
			div.style.position = 'relative';
			div.id = 'elements_image_preloader';
			CacheElements.o = CacheElements.o.appendChild(div);
		}
		var i = 0, so = CacheElements.storage.length, img;
		if (!CacheElements.delay) {
			for (; i < so; i++) {
				CacheElements.cache(i);
			}
		} else {
			CacheElements.interval = setInterval(CacheElements.cache, CacheElements.delay);
		}
	},
	cache: function(i) {
		if (!i) i = CacheElements.current;
		if (CacheElements.stored[i] || !CacheElements.storage[i]) {
			clearInterval(CacheElements.interval);
			return;
		}
		CacheElements.current++;
		img = document.createElement('IMG');
		img.style.position = 'absolute';
		img.style.top = 0;
		img.style.left = 0;
		img.src = CacheElements.storage[i];
		CacheElements.o.appendChild(img);
		CacheElements.stored[i] = true;
	}
}


function soundComplete() {
	$('#sound_image').css('display', 'block');
}
