// AFFILIATE SEARCH PREVIEWER
/*

*/

var cOverlay;// global var to hold reference
var ActiveInput;// used to target where to store query

     
	
	function buildSearch_overlay(t, i,u){

		//ActiveInput = q;
		cOverlay = new BuildSearchOverlay({name:'Srch', img:i, url:u}); 
	}  

	
	
	// -----------------------------------
	// CLASS  
var BuildSearchOverlay = new Class({
	Implements:[Options,Events],
	options:{
	   img: null,
	   url: null
	},
	initialize : function(p){
		this.setOptions(p);
		this.active = true;  
		
		this._build();// prepare canvas content
		this._open()
	},
	_build : function(b){
		// build interface elements   
		this.holder = new Element('div', { 'id':'afs_holder','styles':{'display':'block','left':0 }}).inject($(document.body));
		this.overlay = new Element('div', {'id':'afs_overlay'}).inject(this.holder); //'visibility':'none',
		this.contentholder = new Element('div', {'id':'afs_contentholder'}).inject(this.holder); 
		
		
		this.content = new Element('div', {'id':'afs_content'}).inject(this.contentholder);   
		this.close = new Element('a',{'id':'afs_closebtn','text':'Close'}).inject(this.contentholder);
		//var clr = new Element('div', {'class':'clear'}).inject(this.contentholder);
		this._addContent();// based on type need to build the variou search forms 
		
		$$(this.overlay,this.close).addEvent('click',function(){ this._remove();}.bindWithEvent(this));
	
		window.addEvent('resize',function(){			
			if(null == this.overlay || this.overlay.getStyle('opacity') == 0){ return; };//resize only if visible
			var scrollSize = $(window).getScrollSize().y;
			var scrollTop = $(window).getScroll().y;
			this.overlay.setStyles({ 'height':scrollSize+scrollTop,'top':-scrollTop });
		}.bindWithEvent(this));
	},
	_open : function(bol){
		var scrollSize = $(window).getScrollSize().y;
		var scrollTop = $(window).getScroll().y;
			//this.holder.setStyles({'top':-scrollTop},{'display':'block'});//
			this.overlay.setStyles({'height':scrollSize+scrollTop}, {'top':-scrollTop});//		
	},
	_addContent : function(){
		// could we build the html in sep files and just load into a div?  
		//var eFormHolder = new Element('div', {'id':'afs_formHolder'}).inject(this.content);//, 'text':'loading...'
		//var eResultsHolder = new Element('div', {'id':'afs_results', 'text':'*results will appear here*'}).inject(this.content);
		//var clr = new Element('div', {'class':'clear'}).inject(this.content);  
		var myA = this.content;
 		if(this.options.url != "") myA = new Element('a',{href:this.options.url,target:'_blank'});
		var url, fcn, frmCls;
		var myImg = new Element('img',{'src':this.options.img,'id':'afs_img'}).inject(myA);
		myA.inject(this.content);
		// switch(this.options.searchType){
		   // case 'amazon':
				// frmCls = new FormBuilder({holder:eFormHolder, inputs: aAmazonForm});
		   	// break;
		   // case 'itunes':
				// frmCls = new FormBuilder({holder:eFormHolder, inputs: aITunesForm});
				// populateMediaDropMenus();
		   	// break;			
		// }
		//eFormHolder.innerHTML += '';// REQUIRED for IE to work
	
	},
	_remove : function(){
		this.holder.destroy();
	}
});
