//===================================================
var hide  = true;

function showhide(obj)
{
	var x = document.getElementById('testP');
	hide = !hide;
	x.style.visibility = (hide) ? 'hidden' : 'visible';
	setLyr(obj,'testP');
}

function FixPos(obj,id)
{
	var coors = findPos(obj);
	dfr = document.getElementById('fr');
	if (dfr) {
		var fr = findPos(dfr);
		if ((coors[0] - fr[0]) < 60) {
			var x = document.getElementById('D'+id);
//			x.style.top = 50+coors[1] + 'px';
			x.style.left = (-30+(coors[0] - fr[0])) + 'px';
		}
	}
}

function setLyr(obj,lyr)
{
	var coors = findPos(obj);
	if (lyr == 'testP') coors[1] -= 50;
	var x = document.getElementById(lyr);
	x.style.top = 50+coors[1] + 'px';
	x.style.left = 50+coors[0] + 'px';
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


//===================================================
var cid;
function DelayPhoto(id) {
	if (cid == id)	
	document.getElementById(id).style.display='block';
}
function ShowPhoto(obj, id) {
		setLyr(obj, id);
		cid = id;
		window.setTimeout("DelayPhoto('"+id+"');", 500);
}
function HidePhoto(obj, id) {
	cid = 0;
	window.setTimeout("document.getElementById("+id+").style.display='none';", 200);
}

function UpdateSt(id, get){
var http = getHTTPObject();
http.open("http://www.soundlondon.com/GET", get, true);
http.onreadystatechange = function() {
	if (http.readyState == 4) {
		document.getElementById(id).style.display='block';	
		document.getElementById(id).innerHTML = http.responseText;
	}
}
http.send(null);
}


function Accept (id) {
	
	get = '?gallery=APhotos&status=1&return=2&id='+document.getElementById("gid").innerHTML
	get2 = '?gallery=APhotos&status=2&return=2&id='+document.getElementById("gid").innerHTML
	document.getElementById("A"+id).innerHTML = 'Wait...';
	var success	= function(){UpdateSt("visible", get); UpdateSt("invisible", get2);}
	var failure	= function(){Failed(date);}
	
	var url = '?gallery=Accept';
	var pars = 'id='+id;
	new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	
}
function Delete (id) {
	
	get = '?gallery=APhotos&status=1&return=2&id='+document.getElementById("gid").innerHTML
	get2 = '?gallery=APhotos&status=2&return=2&id='+document.getElementById("gid").innerHTML
	document.getElementById("A"+id).innerHTML = 'Wait...';
	var success	= function(){UpdateSt("visible", get); UpdateSt("invisible", get2);}
	var failure	= function(){Failed(date);}
	
	var url = '?gallery=DeletePhoto';
	var pars = 'id='+id;
	new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	
}

var XX;
var YY;
var WW;
var HH;
var pid;
	var viewco;
	var imgco;

function locationB (stepX, stepY, id) {
	imgco[0] = imgco[0] - stepX;
	imgco[1] = imgco[1] - stepY;
	HH = HH + 40;
	WW = WW + 40;
	document.getElementById('B'+id).style.left = imgco[0]+'px';
	document.getElementById('B'+id).style.top = imgco[1]+'px';
	document.getElementById('B'+id).style.width = WW+'px';
	document.getElementById('B'+id).style.height = HH+'px';
	if (((stepX == 0) ||  ( Math.abs(imgco[0] - viewco[0]) > Math.abs(stepX))) && (( Math.abs(imgco[1] - viewco[1])>Math.abs(stepY) ) || (stepY == 0)) ) {
	window.setTimeout("locationB("+stepX+", "+stepY+", "+id+");", 10);
	} else {
	document.getElementById('B'+id).style.left = viewco[0]+'px';
	document.getElementById('B'+id).style.top = viewco[1]+'px';
	document.getElementById('B'+id).style.width = 549+'px';
	document.getElementById('B'+id).style.height = 427+'px';
//	alert(imgco[1]+' '+viewco[1]+' '+stepY);
	}
}

function view(id){
	vi = document.getElementById('view');
	im = document.getElementById('S'+id);
	viewco = findPos(vi);
	imgco = findPos(im);
	x = ((imgco[0] - viewco[0]));
	y = ((imgco[1] - viewco[1]));
	stepX = x/10;
	stepY = y/10;
 WW = 40;
 HH = 40;
 if (pid) {document.getElementById('B'+pid).style.display='none';	
	 document.getElementById('S'+pid).style.left = 0+'px';
	 document.getElementById('S'+pid).style.top = 0+'px';
 }
 pid = id;
document.getElementById('B'+pid).style.display='block';
document.getElementById('S'+id).style.left = -10+'px';
document.getElementById('S'+id).style.top = -10+'px';
//	if (imgco[0] >= viewco[0]) 
	locationB(stepX, stepY, id);
	
	
//	alert(viewco[0]+' '+viewco[1]+' '+imgco[0]+' '+imgco[1]);
		
}
//================ FILES ======================================

function SelFile(file) {
	s = file.value;
	$tmp = '<img src="file:///D|/samagono_aparatas.jpg" width="160" />';	
	document.getElementById("file").innerHTML = $tmp;
	alert(file.value);	
}
//================= MOVING BAR =====================================
var posA = 0;
var posB = 0;
var wA =1;
var wB =1;
var pause = false;
var BarStep;
var BarSpeed;
function BarPos(){
	objA = document.getElementById('A');
	objB = document.getElementById('B');
	wA =  findPos(objA);
	wB =  findPos(objB);
}
function BarPause(){
	BarStep = 0;
}
function BarPlay(val){
	BarStep = val;
}
function BarMove(){
	posA = posA - BarStep;
	posB = posB - BarStep;
	dif =(wB[0]-wA[0]);
	if (BarStep-posA > dif+BarStep) 
		posA = Math.abs(posA)-BarStep;// (wB[0]-wA[0]);
	if (BarStep-posB > 2*dif+BarStep) 
		posB = 0;//dif%BarStep;
	document.getElementById('A').style.left = posA+'px';
	document.getElementById('B').style.left = posB+'px';
//	document.getElementById('AA').innerHTML= posA+'px';
//	document.getElementById('BB').innerHTML= posB+'px';
	if (!pause) window.setTimeout("BarMove();", BarSpeed);	
}
function Bar(step, speed){
	BarStep = step;
	BarSpeed = speed;
	BarPos();
	rnd = 0-Math.round((wB[0]-wA[0])*Math.random());
	posA = 0;//rnd; 
	posB = 0;//rnd;
	pause = false;
	BarMove();
//	alert(wB[0]-wA[0]);
}
