// -----------------------------------------------------------------------------------
//
//	Lightbox v2.02
//	by Lokesh Dhakar - http://www.huddletogether.com
//	3/31/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------



//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
   		element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});


// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	showFlashBoxes();
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	hideFlashBoxes();
}

// ---------------------------------------------------

function showFlashBoxes(){
	selects = document.getElementsByTagName("object");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlashBoxes() {
	selects = document.getElementsByTagName("object");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}



/**
*	LOCK SCREEN
*/
function lockscreen_lock_(){
	
	hideSelectBoxes();

	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	new Effect.Appear('overlay', { duration: 0.1, from: 0.0, to: 0.4 });
	$('overlay').innerHTML = '<div id="overlay_inner"></div>';
	
	Element.setHeight('overlay_white', arrayPageSize[1]);
	$('overlay_white').style.display = 'block';
	$('overlay_white').innerHTML = '<div id="overlay_white_inner"></div>';

}

function lockscreen_unlock_(){
				
	new Effect.Fade('overlay', { duration: 0.2});
	$('overlay_white').style.display = 'none';
	showSelectBoxes();	
}
function lockscreen_popup_(el){
	el.style.zIndex = 99;
	//alert(el.style.left);
}
/**
*	lockscreen show block
*/
function lockscreen_show_(which)
{	
	var aid = 'aframe_' + which;
	ls.lock();
	
	switch (which)
	{
		case "cm_1":
		case "cm_2":
		case "cm_4":
			
			if(CRNT_BROWSER == 'ie')
			{
				this.last_parent = $(aid).parentNode;
				
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '170px';
				$(aid).style.left = '170px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}
			
			var postfix = "";
			if ($('catalog_list_root') != null)
			{
				postfix = "&group_id=" + $('catalog_list_root').value;
			}
			$(aid).style.display = 'block';
			
			
			if (($('catalog_id') != null))
			{
				postfix += "&expand_id=" + $('catalog_id').value;
			}
			if (dynamicMenuLoaded == 0)
			{
				aframe_get(aid, base_url + 'index.php?module=elements&action=catalogs_menu' + postfix, true);
			}
		break;
			
		case "exifWindow":

			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '900px';
				$(aid).style.left = '300px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}

			$(aid).style.display = 'block';	
			var phid = $('hidden_photo_id').value;
			aframe_get(aid, base_url + 'index.php?module=elements&action=exif_info&phid='+phid, true);
		break;	


		case "divaskurismirga":

			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '500px';
				$(aid).style.left = '300px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}

			$(aid).style.display = 'block';	
			//var phid = $('hidden_photo_id').value;
			//aframe_get(aid, 'index.php?module=elements&action=exif_info&phid='+phid, true);
		break;	

		case "recommend_email":
			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '255px';
				$(aid).style.left = '212px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}
			$(aid).style.display = 'block';	
		
		break;
		
		case "recommend":
			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '500px';
				$(aid).style.left = '200px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}

			$(aid).style.display = 'block';	
			//var phid = $('hidden_photo_id').value;
			//aframe_get(aid, 'index.php?module=elements&action=exif_info&phid='+phid, true);
		break;	
		
		
		case "offer_price":
			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '750px';
				$(aid).style.left = '480px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}

			$(aid).style.display = 'block';	
			//var phid = $('hidden_photo_id').value;
			//aframe_get(aid, 'index.php?module=elements&action=exif_info&phid='+phid, true);
		break;			
		
		case "choose_quotes":
			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.top = '350px';
				$(aid).style.left = '280px';
				$(aid).style.position = 'relative';
				$(aid).style.zIndex = 99;
			}

			$(aid).style.display = 'block';	
		break;
		
		case "makeloginform":
			$(aid).style.display = 'block';
			$(aid).style.top = '-350px';
			$(aid).style.left = '200px';
			$(aid).style.position = 'relative';
			$(aid).style.zIndex = 99;
			
			if(CRNT_BROWSER == 'ie'){
				this.last_parent = $(aid).parentNode;
				$('overlay_white_inner').appendChild( $(aid) );
				$(aid).style.display = 'block';
				$(aid).style.top = '350px';
				$(aid).style.left = '400px';
			}
		break;
			
		default:
			
			if(CRNT_BROWSER == 'ie')
			{
				this.last_parent = $(which).parentNode;
				
				$('overlay_white_inner').appendChild( $(which) );
				switch (which){
					case "gaminti_tree":
						//$(which).style.top = '272px';
						//$(which).style.left = '815px';
					break;
					case "folder_tree":
						//$(which).style.top = '282px';
						//$(which).style.left = '212px';
					break;
					case "swfupl_folder_tree":
						//$(which).style.top = '382px';
						//$(which).style.left = '212px';
					break;
					case "swfupl_create_folder":
						//$(which).style.top = '382px';
						//$(which).style.left = '212px';
					break;
				}
				//$(which).style.position = 'relative';
				$(which).style.zIndex = 5001; 
			}
			$(which).style.display = 'block';
		break;
	}
}


/**
*	lockscreen hide block
*/
function lockscreen_hide_(which){
	var aid = 'aframe_' + which;
	switch (which){
		case "cm_1":
		case "cm_2":
		case "cm_4":
				if(CRNT_BROWSER == 'ie'){
	
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;
		case "exifWindow":
		
				if(CRNT_BROWSER == 'ie'){
	
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;	
		case "divaskurismirga":
		
				if(CRNT_BROWSER == 'ie'){
	
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;

		
		case "recommend_email":
		case "recommend":
		
				if(CRNT_BROWSER == 'ie'){
	
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;	

		case "offer_price":
		
				if(CRNT_BROWSER == 'ie'){
	
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;	
		
		case "choose_quotes":
				if(CRNT_BROWSER == 'ie'){
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;	
		
		case "makeloginform":
				if(CRNT_BROWSER == 'ie'){
					$(this.last_parent).appendChild( $(aid) );
				}
				
			$(aid).style.display = 'none';
		break;
		
		default:

				if(CRNT_BROWSER == 'ie'){
	
					$(this.last_parent).appendChild( $(which) );
				}			
			
			$(which).style.display = 'none';
		break;
	}
	ls.unlock();	
}
function lockscreen(){
	this.lock = lockscreen_lock_;
	this.unlock = lockscreen_unlock_;
	this.popup = lockscreen_popup_;
	this.show = lockscreen_show_;	
	this.hide = lockscreen_hide_;	
}


var ls = new lockscreen();
