var elementclicked = Class.create();
var bioclicked = Class.create();

elementclicked.prototype = {
  initialize: function(element) {
     var p_window = $(element).rel;
     
     if (Element.hasClassName($(p_window), 'hidden')) {
        var pos = Position.page($(element));
        var posX = (pos[1] / 1.2) + 'px';
        var posY = (pos[0] + 10) + 'px';
        if (p_window == 'all_designers_main_popup') {var posX = (pos[1] / 2) + 'px'; }
        Element.setStyle(p_window, {
           top: posX,
           left: posY
        });
        close_all();
        Element.removeClassName($(p_window), 'hidden');                                         
     } else {
        close_me(p_window);
     }             
  }
};

bioclicked.prototype = {
  initialize: function(element) {
     var p_window = $(element).rel;
	  openOverlay();

     if (Element.hasClassName($(p_window), 'hidden')) {
        close_all();
        Element.removeClassName($(p_window), 'hidden');   
		  Element.removeClassName($('bio_overlay'), 'hidden');                                      
     } else {
        close_me(p_window);
     }             
  }
};

function close_all() {
  Element.getElementsByClassName(document.body,'dti_popup').each( function(c) {
     if(!Element.hasClassName($(c),'hidden')) { close_me(c); };
  });
}   
function close_me(element) {
   Element.addClassName($(element), 'hidden'); 
}
function close_bio(element) {
	 if (!Element.hasClassName($('designer_bio_popup'))) {	close_me($('designer_bio_popup')); }
	 if (!Element.hasClassName($('bio_overlay'))) {	Element.remove($('bio_overlay')); }
}
function product_detail_popup_close() {
	// This is an alternative to the effect:
	
	$('popup').style.display = 'none';
	$('overlay').style.display = 'none';
	Element.remove($('lbContent'));
	
	/*
	// This is much nicer, but IE pukes:
	Effect.Shrink(
		'popup', 
		{
		duration: 1.25,
		beforeStart: function() {Element.remove($('lbContent'));},
		afterFinish: function(){ $('overlay').style.display = 'none'; } 
		}
	);
	*/
}
function openOverlay() {
	var overlayOpacity = 0.6;	// controls transparency of shadow overlay
	overlayDuration = 0.2;	// shadow fade in/out duration
	var arrayPageSize = getPageSize();
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	
	objOverlay.setAttribute('id','bio_overlay');
	objOverlay.setAttribute('class','hidden');
	objBody.appendChild(objOverlay);

	Element.setWidth('bio_overlay', arrayPageSize[0]);
	Element.setHeight('bio_overlay', arrayPageSize[1]);

	new Effect.Appear('bio_overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });
}	
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}	

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}