function toggle_(id) {if (!window.ggg)window.ggg={};var e = id + '_'; var t = _(id).style.display;if (t!= 'block' || t == 'none'){_(id).style.display='block';window.ggg[e]=_(e).innerHTML;_(e).innerHTML='Hide'}else{_(id).style.display='none';_(e).innerHTML = window.ggg[e]}}
function path_prefix() {return window.location.protocol + '//' + window.location.hostname + '/404/'}

var lang = navigator.userLanguage || navigator.language || navigator.browserLanguage


function getSize() {
	var width = 0, height = 0;
  if(typeof(window.innerWidth) == 'number') {
	width = window.innerWidth;
	height = window.innerHeight;
  } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	width = document.documentElement.clientWidth;
	height = document.documentElement.clientHeight;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
	width = document.body.clientWidth;
	height = document.body.clientHeight;
  }
  return [width, height];
}
loader = function(name, alt, title, alt_id)
{
	window.config = {'svidetel' : 'simple', 'onotole' : 'simple', 'onotoley' : 'sinus_move', 'chuck' : 'chuck', 'coat' : 'simple_bottom', '0' : 'cordon', 'ring' : 'ring', 'mac' : 'mac', 'bed' : 'bed', 'tube' : 'tube'}

	this.name = name;
	this.alt = alt;
	this.title = (title) ? title : this.name
	if (alt_id) {this.alt_id = alt_id;}
	
	if (!_(this.name))
	{
		var nm = (this.alt_id) ? this.alt_id : this.name
		this.i = new Image();
		this.i.src = path_prefix() + nm + '.gif'
		_('title').src = path_prefix() + this.title + '_title.gif'
		a = this;

		if (!this.i.complete)
		{	 
			this.i.onload = function () { a.iwatchinyou.call(a, a);}
		}
		else
		{
			a.iwatchinyou.call(a, a);
		}
	}
}


loader.prototype.strategy = function(name)
{
a = window.config[name];
if (typeof a == 'undefined') a = 'simple';
eval(a + '(name)')
}

loader.prototype.iwatchinyou = function(obj)
{
e = document.createElement('DIV');
e.id = obj.name
e.className = 'svidetel'

e.innerHTML = "<img id='ims' src='" + obj.i.src + "' alt='" + obj.alt + "' title='" + obj.alt + "' />"
_('root').appendChild(e);

obj.strategy.call(obj, e.id)

}







function simple(id)
{
e = _(id)
var i = _('ims')
a = getSize()
wi = a[0]
hi = a[1]
lf = Math.round(Math.random() * (wi - i.width/3))
tp = Math.round(Math.random() * (hi - i.height/3)) - i.height/3
e.style.top = tp + 'px';
e.style.left = lf + 'px'

}


function chuck(id)
{
e = _(id)
var i = _('ims')
a = getSize()
wi = a[0]
hi = a[1]
lf = Math.round(wi/2 + i.width/2)
tp = Math.round(a[1] - i.height)
e.style.top = tp + 'px';
e.style.left = lf + 'px'
}


function cordon(id)
{
hide(id)
_('title').style.marginTop = '0px';
_('ptitle').style.marginTop = '0px';
hide('im')
_('im').style.marginBottom = '0px';
}

function mac(id)
{

cordon(id)
show('im')
if (lang != 'ru')
{
_('title').src = path_prefix() + id + '_en_title.gif';
}
}

function tube(id) {
bed(id)
_('title').title = (lang != 'ru') ? 'Try to look for your page there' : '404'
if (lang == 'ru') {_('title').src = path_prefix() + id + '-rus.jpg';}
}

function bed(id)
{

cordon(id)
_('title').src = path_prefix() + id + '.jpg';
_('title').title = 'Image by Che. All rights reserved'

}


function ring(id)
{
 cordon(id)
 show('ims')
show(id)
_('ims').className += ' z1';
_(id).className += ' z1';
_('im').src = path_prefix() + id + '.gif'
show('im')
if (lang != 'ru')
{
hide('ims')
_('title').src = path_prefix() + id + '_en_title.gif';
}
else
{

var ii = _('ims')

	if (!ii.complete)
	{	 
		ii.onload = function () { define_size(id, ii);}
	}
	else
	{
		define_size(id, ii);
	}
}

}

function define_size(id, i)
{

a = getSize()

_(id).style.top = Math.round(Math.random()*(a[1] - i.height)) + 'px';
_(id).style.left = '-' + i.width + 'px';

var wid = -3;
move_girl(id, wid)
}

function move_girl(id, wid)
{

if (!window.move_that_girl)
{
interv = setInterval('move_girl("' + id + '", "' + wid + '")', 150);
window.move_that_girl = true;
}
var lf = parseInt(_(id).style.left)

if (lf < wid)
{
_(id).style.left = (lf + 2 + 2*Math.round(Math.abs(Math.sin(lf)))) + 'px'
}
else {clearInterval(interv)}
}

function simple_bottom(id)
{
e = _(id)
var i = _('ims')
a = getSize()
wi = a[0]
hi = a[1]
lf = Math.round(wi/2 - i.width*2)
tp = Math.round(a[1] - i.height)
e.style.top = tp + 'px';
e.style.left = lf + 'px'
}

function sinus_move(id)
{
var e = _(id)
var a = getSize()
	if (typeof window.startPointX == 'undefined')
	{
		window.startPointY = Math.round(a[1]/2) + Math.round(a[1]/4);
		window.startPointX = 0;
		setInterval('sinus_move("' + id + '")', 15);
	}
lf = Math.round(window.startPointX*100)
tp = Math.sin(window.startPointX)*150 + Math.round(a[1]/4)

window.startPointX+=0.02

if (window.startPointX*100 >= (a[0]))
{
window.startPointX = 0;
}

e.style.top = tp + 'px';
e.style.left = lf + 'px'
}
