var loginWindow = null;
var registerWindow = null;
var reminderWindow = null;
var errorWindow = null;
var profileWindow = null;
var cartWindow = null;
var adminWindow = null;
var commentWindow = null;
var uploadWindow = null;

function doShowProfile() {
	if(getCookie(profileWindow.getId() + '_left') && getCookie(profileWindow.getId() + '_top')) {
		var x = getCookie(profileWindow.getId() + '_left').replace('px','');
		var y = getCookie(profileWindow.getId() + '_top').replace('px','');
	}
	if( x && y) {
		profileWindow.setLocation(y,x);
		profileWindow.show();
	} else {
		profileWindow.showCenter();
	}
}

function showLogin() {
	if(getCookie(loginWindow.getId() + '_left') && getCookie(loginWindow.getId() + '_top')) {
		var x = getCookie(loginWindow.getId() + '_left').replace('px','');
		var y = getCookie(loginWindow.getId() + '_top').replace('px','');
	}
	if( x && y) {
		loginWindow.setLocation(y,x);
		loginWindow.show();
	} else {
		loginWindow.showCenter();
	}
	registerWindow.hide();
	reminderWindow.hide();
}

function showRegister() {
	if(getCookie(registerWindow.getId() + '_left') && getCookie(registerWindow.getId() + '_top')) {
		var x = getCookie(registerWindow.getId() + '_left').replace('px','');
		var y = getCookie(registerWindow.getId() + '_top').replace('px','');
	}
	if( x && y) {
		registerWindow.setLocation(y,x);
		registerWindow.show();
	} else {
		registerWindow.showCenter();
	}
	loginWindow.hide();
	reminderWindow.hide();
}

function showReminder() {
	if(getCookie(reminderWindow.getId() + '_left') && getCookie(reminderWindow.getId() + '_top')) {
		var x = getCookie(reminderWindow.getId() + '_left').replace('px','');
		var y = getCookie(reminderWindow.getId() + '_top').replace('px','');
	}
	if( x && y) {
		reminderWindow.setLocation(y,x);
		reminderWindow.show();
	} else {
		reminderWindow.showCenter();
	}
	loginWindow.hide();
	registerWindow.hide();
}

function createWindowsPicture() {
	commentWindow = openWindow('commentFormWin',0,0,415,150,100,false,'cForm','Write a comment');
}

function createWindowsLogon() {
	profileWindow = openWindow('profileFormWin',0,0,455,445,100,false,'profilew','Profile'); 
}

function createWindows() {
	errorWindow = openWindow('errorWin',200,200,427,100,200,false,'ew','System message');
}

function _showCart() {
	$('hiddencart').style.display = 'none';
	setCookie('shopcartvisible',1,new Date('January 1, 3000'),'/');
}

function showCart() {
	if(getCookie('cart_left') && getCookie('cart_top')) {
		var x = getCookie('cart_left').replace('px','');
		var y = getCookie('cart_top').replace('px','');
	}
	if( x && y) {
		cartWindow.setLocation(y,x);
		cartWindow.show();
	} else {
		cartWindow.showCenter();
	}
	new Effect.Opacity('hiddencart',{to:0, afterFinish: _showCart});
}

function __hideCart() {
	$('hiddencart').style.display = 'block';
	$('hiddencart').style.opacity = 1.0;
}

function _movecart() {
	//alert(cartWindow.getLocationLeft() + ' ; '+cartWindow.getLocationTop());
	setCookie('cart_left',cartWindow.getLocationLeft(),new Date('January 1, 3000'),'/');
	setCookie('cart_top',cartWindow.getLocationTop(),new Date('January 1, 3000'),'/');
}

function _hideCart() {
	$('hiddencart').style.display = 'block';
	new Effect.Opacity('hiddencart',{to:1, afterFinish: __hideCart});
	setCookie('shopcartvisible',0,new Date('January 1, 3000'),'/');
}

function hideCart() {
	cartWindow.hide();
	$('hiddencart').style.display = 'block';
	new Effect.Opacity('hiddencart',{to:1, afterFinish: __hideCart});
	setCookie('shopcartvisible',0,new Date('January 1, 3000'),'/');
}

function createWindowsCart() {
	cartWindow = new Window('cartWin', {top: 0, left:0, zIndex:30,width:330, height:141,minHeight: 15, resizable: false,title:'Shopping Cart',onclose: _hideCart,onmoved:_movecart, showEffectOptions:{duration:0.5},hideEffectOptions:{duration:0.5} });
	temp = $('basket').innerHTML;
	xajax.remove('basket');
	cartWindow.getContent().innerHTML = temp;
	temp = null;
	Droppables.add('cartWin_content', {accept:'picthumb', onDrop:function(element){dropped=true;addToCart(element);}});
	Droppables.add('cartWin_content', {accept:'picthumb_active', onDrop:function(element){dropped=true;addToCart(element);}});
	Droppables.add('hiddencart', {accept:'picthumb', onDrop:function(element){dropped=true;showCart();addToCart(element);}});
	Droppables.add('hiddencart', {accept:'picthumb_active', onDrop:function(element){dropped=true;showCart();addToCart(element);}});
}

function createWindowsAdmin() {
	adminWindow = openWindow('adminWin',200,200,700,550,200,true,'aWin','Admin'); 
}

function createWindowsLogout(logon) {
	loginWindow = openWindow('loginFormWin',200,200,427,100,200,false,'lf','Login');
	
	registerWindow = openWindow('registerFormWin',200,200,427,220,200,false,'rf','Registration');
	reminderWindow = openWindow('reminderFormWin',200,200,427,158,200,false,'remf','Reminder');
	//$('loginF').innerHTML = '';
	//$('loginUsername').id='hello';
}


function _onclosewin(element) {
	//alert(element.getId());
	setCookie(element.getId()+'_left',element.getLocationLeft(),new Date('January 1, 3000'),'/');
	setCookie(element.getId()+'_top',element.getLocationTop(),new Date('January 1, 3000'),'/');
	//element.showCenter();
}

function openWindow(id,top,left,width,height,zIndex,resizable,innerH, title) {
	var win = new Window(id, {top: top, left:left, zIndex:zIndex,width:width, height:height, resizable: resizable,title:title,minHeight:1, onclose:_onclosewin, showEffectOptions:{duration:0.5},hideEffectOptions:{duration:0.5}})
	if($(innerH)) {
		temp = $(innerH).innerHTML;
		xajax.remove(innerH);
		win.getContent().innerHTML = temp;
		temp = null;
	} else {
		win.getContent().innerHTML = innerH;
	}
	return win;
}

// ---------------------- OLD


	function showWindow( titleText ) {
		$('adminWin_title').innerHTML = titleText;
		adminWindow.show();
		$('popupContent').style.display = 'block';
		$('editorWindow').style.display = 'none';
	}

	function hideWindow() {
		adminWindow.hide();
	}
	
	function changeTitle( titleText ) {
		$('adminWin_title').innerHTML = titleText;
	}