//set all "refbox" to hide, when document load then set to show
document.write('<style type="text/css">');
document.write('div.refbox{visibility:hidden;}');
document.write('</style>');


//make all refbox visible when the document is load
jQuery(document).ready(function($) {
	$j('div.refbox').css('visibility','visible');
});

var examplelinkrunning = false;

jQuery.fn.hashValue = function() {
    var href = this.attr('href');
	return href ? href.replace(/^.*#/, '') : href;
}

/*
function sociallinkWordpress(object){
	var wordpressurl=prompt('Bitte geben Sie die Ihre Wordpress-URL ein?','http://myblog.wordpress.com/');
	if(wordpressurl!='' && wordpressurl!=null){
		window.open(wordpressurl+object.href.replace('http://'+window.location.host+'/', ''),'_blank'); 
	}
	return false;
}
*/

function reflistFunctions(){
	var reflistpath_booklet = '/booklet/de/referenzen/';
	var reflistpath_project = '/project/de/referenzen/';
	this.lastUrl;
	this.lastExampleUrl;
	this.isExample = false;
	this.exampleURLs = {};
	this.historyUrls = [];
	this.historyUrlsLast = [];
	this.historyLevel = 0;
	this.consoleDebuging = false;
	
	this.getCompatibleMediaType =function(){
		if(typeof(F1)=='undefined'){
			var F1=new NetvClientDetect();
		}
		if(F1.clientInfo['flash_ver'] >= 9){
			return 'swf';
		}
		return 'html';
	},
	this.getCurrentRefitemId = function(obj){
		////console.info("###START###");	
		var correctRefitemId = $j(obj).parents('.demo-panel-container').children('.current-location-info-id').text();
		if(correctRefitemId){
			////console.info("first="+correctRefitemId);	
			return correctRefitemId;
		}
		if(this.isExample){
			////console.info("examplerandom");	
			return this.getRandomNumber(5000);
		}
		var current_location_hash = this.getLocationHash();
		var current_location_info = current_location_hash.split(',');
		////console.info("hashID="+current_location_info[1]);
		////console.info("###END###");	
		return current_location_info[1];
	},
	this.getLocationHash = function(){
		////alert('getLocationHash='+window.location.hash);
		return (window.location.hash).replace(/^#/, '');
	},
	this.getReflistId = function(location){
		var reflistId = false;
		$j('.refbox .text-overlay a').each(function(index, object){
			var reflistlink = object.href.split(',');
			if(reflistlink[0].lastIndexOf(location)!= -1){
				reflistId = reflistlink[1];
				//return false break the while
				return false;
			}
		});
		return reflistId;
	},
	this.redirectWithReflistId = function(location){
		reflistId = this.getReflistId(location);
		if(reflistId){
			window.location.hash = location+','+reflistId;
			return false;
		}
	},
	this.examplelinkClickHandler = function(linkObj){
		var hash = $j(linkObj).hashValue();
		

		if(this.lastExampleUrl==undefined){
			var locationhash = this.getLocationHash();
			if(locationhash.length>0){
				this.lastExampleUrl = locationhash;
			}
		}
		if(this.lastExampleUrl!=undefined){
			var mylastUrl = this.lastExampleUrl.split(/,/);
			if(mylastUrl[0]==hash){
				//break to call again the same hash
				if (window.console && window.console.firebug && this.consoleDebuging) {
					console.info('break to call again:'+hash);
				}
				examplelinkrunning = false;
				return false;
			}
		}
		this.lastExampleUrl = hash;
		
		hash = this.setHistoryPages(hash,'');
		$j.history.load(hash);
		return false;
	},
	this.reflistitemClickHandler = function(linkObj){
		var hash = $j(linkObj).hashValue();
		var infos_refitem = hash.split(/,/);
		if(infos_refitem.length < 2 && infos_refitem[0]!='close'){
			//prepare link and add refitem id for PROJECTS
			var info = hash.split(/\//);
			
			currentRefitemId = this.getCurrentRefitemId(linkObj);
			hash = info[info.length-2]+'/'+info[info.length-1].substr(0,info[info.length-1].length-5)+','+currentRefitemId;
		}
		if(this.isExample  && infos_refitem[0]!='close'){
			var overridehash = hash;
			var hash = this.getLocationHash();
			var overridehashposition = $j(linkObj).parents('.demo-panel-container').nextAll('.demo-panel-container').length;
			hash = this.setHistoryPages(hash,overridehash,overridehashposition);
		}
		$j.history.load(hash);
		return false;
	},
	this.setHistoryPages = function(hash,overridehash,overridehashposition){
		this.setHistoryPagesLast(hash,overridehash);
		hash = hash.split(',');
		var level = this.getHistoryLevel();
		if(overridehash==''){
			var pages = eval('this.exampleURLs.'+hash[0]);
		}
		else{
			var pages = this.getHistoryPages(hash[0],parseFloat(hash[1]));
			pages[parseFloat(overridehashposition)] = overridehash+','+(parseFloat(overridehashposition)+parseFloat(1));
		}
		this.historyUrls[parseFloat(level)] = pages;
		this.setHistoryLevel((parseFloat(level)+parseFloat(1)));
		return hash[0]+','+level;
	},
	this.getHistoryPages = function(identificator, level){
		if(this.historyUrls[level]){
			var pages = this.historyUrls[level];
		}
		else{
			var pages = eval('this.exampleURLs.'+identificator);
		}
		var copypages = $j.extend(true, [], pages);
		return copypages;
	},
	this.setHistoryPagesLast = function(hash,overridehash){
		if(overridehash!=''){
			hash = hash.split(',');
			var level = this.getHistoryLevel();
			var pages = this.getHistoryPages(hash[0],parseFloat(hash[1]));
			
			this.historyUrlsLast[parseFloat(level)] = pages;
		}
	},
	this.getHistoryPagesLast = function(level){
		if(this.historyUrlsLast[level]){
			var pages = this.historyUrlsLast[level];
			var copypages = $j.extend(true, [], pages);
			return copypages;
		}
		return false;
	},
	this.setHistoryLevel = function(number){
		this.historyLevel = number;
	},
	this.getHistoryLevel = function(){
		return this.historyLevel;
	},
	this.closeBookletID = function(id,callback){
		////console.info("DEBUG: closeBookletID="+id);
		
		currentClass = this;
		$j('#'+id).slideUp('fast',function(){
			$j('#'+id).remove();
			currentClass.showAllRefitems(callback);
		});
	},
	this.closeAllBooklets = function(callback){
		currentClass = this;
		var total = $j('.demo-panel-container').length;
		if(total>0){
			$j('.demo-panel-container').each(function(index){
				//check if last, than add also the callback func	
				if((index+1)==total){
					currentClass.closeBookletID($j(this).attr('id'),callback);
				}
				else{
					currentClass.closeBookletID($j(this).attr('id'));
				}
			});
		}else{
			callback();
		}
	},
	this.showAllRefitems = function(callback){
		//$j('.demo-panel-title-container').slideUp('fast',function(){
			$j('.demo-panel-title-container').remove();
		//});
		
		$j('div.refbox-outter').show();
		$j('div.refbox').css('visibility','visible');
		$j('div.refbox').find('.inactive').removeClass('inactive').mouseleave();
//		$j('div.refbox-spacer-temp').remove();
		if(jQuery.isFunction(callback)){
			callback();
		}
	},
	this.logUrlAccess = function (title){
		try {
			var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
			piwikTracker.setDocumentTitle(title);
			piwikTracker.trackPageView();
			piwikTracker.enableLinkTracking();
		} catch( err ) {}
	},
	this.loadBooklet = function(url, refbox_outter, userAction,addOpenFunc,callback){
		//console.info("DEBUG: loadBooklet");
		this.logUrlAccess("Booklet: "+url);
		//make ajax-request for booklet
		reflistFunctions = this;
		
		$j.ajax({
			async: false,
			type: "POST",
			url: url,
			data: ({
				loadType: this.getCompatibleMediaType(),
				autoplay: (this.isExample ? false : true)
			}),
			success: function(html){
				//on success:
				
				var currentRefitemId = reflistFunctions.getCurrentRefitemId();
				
				
				if(reflistFunctions.isExample){
					html = '<script type="text/javascript">var currentRefitemIdOverride=false;</script>'+html;
					//add the html from ajax-request in the refbox_outter('example-holder'), set them to hidden and save the "id" in a var.
					var currentOpenId = refbox_outter.append(html).children(".demo-panel-container:last").prepend('<div style="display:none" class="current-location-info-id">'+currentRefitemId+'</div>').hide().attr('id');
					currentOpenId = currentOpenId+'-'+currentRefitemId;
					refbox_outter.children('.demo-panel-container:last').attr('id',currentOpenId).find('a.ajax-link-close').remove();
				}
				else{
					//add the html from ajax-request after the last ref-item, set them to hidden and save the "id" in a var.
					if(refbox_outter.hasClass('fourth-item')){
						var currentOpenId = refbox_outter.after(html).next(".demo-panel-container").prepend('<div style="display:none" class="current-location-info-id">'+currentRefitemId+'</div>').hide().attr('id');
						currentOpenId = currentOpenId+'-'+currentRefitemId;
						refbox_outter.next(".demo-panel-container").attr('id',currentOpenId);
					}
					else{
						var currentOpenId = refbox_outter.nextAll('.fourth-item:first').after(html).next(".demo-panel-container").prepend('<div style="display:none" class="current-location-info-id">'+currentRefitemId+'</div>').hide().attr('id');
						currentOpenId = currentOpenId+'-'+currentRefitemId;
						refbox_outter.nextAll('.fourth-item:first').next(".demo-panel-container").attr('id',currentOpenId);
					}
				}
				
				var openDemoPanelFound = false;
				if(!reflistFunctions.isExample){
					////console.info("DEBUG: pass 1");	
					//with this each close all open demo-panel, but not the just now loaded!
					$j(".demo-panel-container").each(function(index) {
						var testId = $j(this).attr('id');
						////console.info("DEBUG: pass="+testId);	
						if(testId!=currentOpenId){
							openDemoPanelFound = true;
							//make close action and a callback function for open the just now loaded demo-panel
							reflistFunctions.closeBookletID(testId,function(){
								////console.info("DEBUG: close="+testId);	
								if($j('#'+currentOpenId+':hidden').length){
									if(jQuery.isFunction(addOpenFunc)){
										addOpenFunc();
									}
									// pauseBgAnim();  // console.info("DEBUG: pause1");
									$j('#'+currentOpenId).slideDown('fast',function(){
										reflistFunctions.netvMediaSlider(currentOpenId);
										
										//callback from loadBooklet...
										if(jQuery.isFunction(callback)){
											callback();
										}	
									});
								}
							});
						}
					});
				}
				
				if(!openDemoPanelFound){
					if(jQuery.isFunction(addOpenFunc)){
						addOpenFunc();
					}
					
					// Pause background animation as soon as the circles are visible
					pauseBgAnim();
					
					$j('#'+currentOpenId).slideDown('fast',function(){
						reflistFunctions.netvMediaSlider(currentOpenId);
						
						//callback from loadBooklet...
						if(jQuery.isFunction(callback)){
							callback();
						}			
					});
				}
			}
		});
	},
	this.loadProject = function(url,getCurrentRefitemIdentifyObj, callback){
		//console.info("DEBUG: loadProject");
		this.logUrlAccess("Project: "+url);
		
		reflistFunctions = this;
		
		$j.ajax({
			async: false,
			type: "POST",
			url: url,
			data: ({
				loadType : this.getCompatibleMediaType(),
				autoplay: (this.isExample ? false : true)
			}),
			success: function(html){
				var currentRefitemId = reflistAction.getCurrentRefitemId(getCurrentRefitemIdentifyObj);
				html = '<script type="text/javascript">var currentRefitemIdOverride='+currentRefitemId+';</script>'+html;
				
				if(reflistFunctions.isExample){
					$j('#booklet-refitemdetail-'+currentRefitemId+' .detail-content-col-inner').html(html).find('a.ajax-link-close').remove();
				}
				else{
					$j('#booklet-refitemdetail-'+currentRefitemId+' .detail-content-col-inner').html(html);
				}
				
				reflistFunctions.netvMediaSlider('booklet-refitemdetail-'+currentRefitemId);
				if(jQuery.isFunction(callback)){
					callback();
				}
			}
		});
	},
	this.netvMediaSlider = function(currentRefitemId){
		$j(document).ready(function(){
			// Media Slider
			if($j('#'+currentRefitemId).find('ul.slideshow').length > 0){
				/*
				$j('#'+currentRefitemId).find('ul.slideshow').NetvMediaSlider({
					transitiontime: 0.6,  // duration of move in seconds
					displayduration: 4,  // how many seconds is a slide visible
					autoplay: true,  // true|false
					label_forward: "n&auml;chstes Bild",  // title of the forward link
					label_backward: "vorheriges Bild"  // title of the backward link
				});
				*/
				$j('#'+currentRefitemId).find('ul.slideshow').NetvMediaSlider({
					slide_width: null,  /* int | null - width of a single slide (null for size of first li) */
					slide_height: null,  /* int | null - height of a single slide (null for size of first li) */
					displayduration: 4,  /* number - how many seconds is a slide visible */
					autoplay: true,  /* true | false */
					randomstart: false,  /* true | false */
					controls: true,  /* true | false */
					transitiontype: 'none',  /* none | slide | fade | crossfade */
					transitiontime: 0.6,  /* number - duration of transition in seconds; only relevant if transitiontype is slide, fade or crossfade */
					fadebgcolor: '#ffffff',  /* color | transparent - against what color will be faded; only relevant if transitiontype is crossfade */
					label_forward: "n&auml;chstes Bild",  /* string - title of the forward link */
					label_backward: "vorheriges Bild"  /* string - title of the backward link */
				});
			}
		});	
	},
	this.openTitle = function(hashinfos,callback){
		var titlebarHTML = $j('#demo-panel-title-'+hashinfos[0]+'-copyassist').html();
		$j(titlebarHTML).removeClass('demo-panel-title-container-copyassist').addClass('demo-panel-title-container').insertBefore('#example-holder');
		
		if(jQuery.isFunction(callback)){
			callback();
		}
	},
	this.scrollToObj = function(obj,callback){
		var offsets = obj.offset();
		if(this.isExample){
			var top = offsets.top+4;
		}
		else{
			var top = offsets.top-8;
		}
		$j("html, body").animate(
			{
				scrollTop: top
			}, 
			'fast', 
			function(){
				if(jQuery.isFunction(callback)){
					callback();
				}
			} //callback
		);
	},
	this.restoreHeaderTitle = function(){
		if(documenttitle!=undefined){
			document.title = documenttitle;
		}
	},
	this.restoreReflist = function(hash){
		////alert("restoreReflist="+this.lastUrl+" :::::::: "+hash);
		if(this.lastUrl === hash){
			if (window.console && window.console.firebug && this.consoleDebuging) {
				console.info('break to call again:'+hash);
			}
			
			//brack a second ajax-call
			return true;
		}
		this.lastUrl = hash;
		var hashinfos = hash.split(/,/);
		if((hash=='' && typeof(netvprojects_beUserLogin)==='undefined') || hashinfos[0]=='close'){
			if(hashinfos.length > 1){
				var id = 'booklet-refitemdetail-'+hashinfos[1];
				if($j('#'+id).length > 0){
					reflistAction.closeBookletID(
						id,
						function(){
							reflistAction.restoreHeaderTitle();
							resumeBgAnim();  // console.info("DEBUG: resume1");
						} //callback
					);
				}
				else{
					resumeBgAnim();  // console.info("DEBUG: resume2");
				}
			}
			else{
				reflistAction.closeAllBooklets(
					function(){
						reflistAction.restoreHeaderTitle();
						resumeBgAnim();  // console.info("DEBUG: resume3");
					} //callback
				);
			}
			$j('a.examplelink.act').removeClass('act');
			return true;
		}
		if(hashinfos.length==1){
			this.redirectWithReflistId(hashinfos[0]);
			return false;
		}
		
		var refbox_outter = $j('#refitem-'+hashinfos[1]);
		var loadProjectByExample = false;
		if($j('div.tx-netvprojects-pi2-examplelinks a[href$="'+hashinfos[0]+'"]').hasClass('act') && this.isExample){
			loadProjectByExample = true;
		}
		if(loadProjectByExample || refbox_outter.css('display')=='none' || refbox_outter.css('visibility')=='hidden' ||  refbox_outter.children(".refbox").css('display')=='none' ||  refbox_outter.children(".refbox").css('visibility')=='hidden' || refbox_outter.find(".text-overlay").hasClass('inactive')){
			if(this.isExample){
				currentClass = this;
				var urlparts = this.getHistoryPages(hashinfos[0],hashinfos[1]);
				var urlpartsLast = this.getHistoryPagesLast(hashinfos[1]);
				jQuery.each(urlparts,function(index,urlpart){
					if(urlpartsLast[index] !== urlparts[index]){
						var getCurrentRefitemIdentifyObjs = $j('div.demo-panel-container > div.demo-panel-content').toArray();
						getCurrentRefitemIdentifyObjs.reverse();
					
						var urlinfos = urlpart.split(/,/);
						var url = reflistpath_project+urlinfos[0]+'.html';
						currentClass.loadProject(
							url,
							getCurrentRefitemIdentifyObjs[index],
							function(){
								reflistAction.restoreHeaderTitle();
								// resumeBgAnim();  // console.info("DEBUG: resume4");
							} //callback
						);
					}
				});
			}
			else{
				var url = reflistpath_project+hashinfos[0]+'.html';
				this.loadProject(
					url,
					'',
					function(){
						reflistAction.restoreHeaderTitle();
						// resumeBgAnim();  // console.info("DEBUG: resume5");
					} //callback
				);
			}
		}
		else{
			if(this.isExample){
				$j('a.examplelink.act').removeClass('act');
				$j('a[href$="'+hashinfos[0]+'"]').addClass('act').blur();
				
				if($j('#example-holder').length == 0){
					$j('#content-containers').append('<div style="clear: both;" id="example-holder"></div>');
				}				
				var exampleHolder = $j('#example-holder');
				currentClass = this;
				var urlparts = this.getHistoryPages(hashinfos[0],hashinfos[1]);
				jQuery.each(urlparts,function(index,urlpart){
					var urlinfos = urlpart.split(/,/);
					var url = reflistpath_booklet+urlinfos[0]+'.html';
					if(index==0){
						currentClass.closeAllBooklets(function(){
							currentClass.openTitle(hashinfos,function(){
								currentClass.loadBooklet(
									url,
									exampleHolder,
									true,
									function(){}, //addOpenFunc
									function(){
										if(urlparts.length == 1){
											currentClass.scrollToObj(
												$j('.demo-panel-title-container'),
												function(){
													examplelinkrunning=false;
													reflistAction.restoreHeaderTitle();
													// resumeBgAnim();  // console.info("DEBUG: resume6");
												} //callback
											); 
										}
										else{
											jQuery.each(urlparts,function(index2,urlpart){
												var urlinfos = urlpart.split(/,/);
												var url = reflistpath_booklet+urlinfos[0]+'.html';
												if(index2==0){
													//skip first item
												}
												else if(index2 == urlparts.length-1){
													//callback by last item
													currentClass.loadBooklet(
														url,
														exampleHolder,
														true,
														function(){}, //addOpenFunc
														function(){
															currentClass.scrollToObj(
																$j('.demo-panel-title-container'),
																function(){
																	examplelinkrunning=false;
																	// resumeBgAnim();  // console.info("DEBUG: resume7");
																} //callback
															);
															reflistAction.restoreHeaderTitle();
														} //callback
													);
												}
												else{
													//not first and not last item
													currentClass.loadBooklet(
														url,
														exampleHolder,
														true,
														function(){}, //addOpenFunc
														function(){reflistAction.restoreHeaderTitle();} //callback
													);
												}
											});
										}
										reflistAction.restoreHeaderTitle();
									} //callback
								);
							});
						});
						return false;
					}
				});
			}
			else{
				currentClass = this;
				var url = reflistpath_booklet+hashinfos[0]+'.html';
				this.loadBooklet(
					url,
					refbox_outter,
					true,
					function(){reflistFunctions.modifyReflist(refbox_outter);}, //addOpenFunc
					function(){
						currentClass.scrollToObj(
							refbox_outter,
							function(){
								reflistAction.restoreHeaderTitle();
								// resumeBgAnim();  // console.info("DEBUG: resume8");
							} //callback
						); 
					} //callback
				);
			}
		}
		
		return false;
	},
	
	
	this.modifyReflist = function(refbox_outter){
		var refbox = refbox_outter.children(".refbox");
		this.hiddeThisObject(refbox,'');
	},
	this.getNumberOfElemtsHasSpacer = function(cObjCurrent,numberOfElemtsToCheck,checkmode){
		numberOfSpacers = 0;
		if(numberOfElemtsToCheck>0){
			if(checkmode=='before'){
				var mode = 'prevAll';
			}
			else{
				var mode = 'nextAll';
			}
			
			var refbox_outer_objects = eval('cObjCurrent.'+mode+'(\'.refbox-outter:lt('+numberOfElemtsToCheck+')\')');
			refbox_outer_objects.each(function(index) {
				if($j(this).hasClass('refbox-spacer')){
					numberOfSpacers++;
				}
			});
		}
		return numberOfSpacers;
	},
	this.hiddeThisObject = function(refitemObj,mode){
		if(mode=='display'){
			refitemObj.css('display','none');
		}
		else if(mode=='visibility'){
			refitemObj.css('visibility','hidden');
		}
		else{
			refitemObj.find("a img").hide();
			refitemObj.find(".text-overlay").addClass('inactive').show();
		}
	},
	/***********************************
	* helper functions 
	***********************************/
	this.getRandomNumber = function(end){
		return Math.floor(Math.random() * end)+1;
	}
};

var reflistAction = new reflistFunctions();

jQuery(document).ready(function($) {

	// ----- Controllers -----
	//observe document for links with class "ajax-link", thats only project links
	$j('a.ajax-link').live('click', function(e){
		reflistAction.reflistitemClickHandler(this);
		return false;
	});
	
	//observe document for links with class "ajax-link-close", thats only close-links in project-detail
	$j('a.ajax-link-close').live('click', function(e){
		if(reflistAction.isExample){
			this.href='close';
		}
		else{
			var currentRefitemId = reflistFunctions.getCurrentRefitemId(this);
			this.href='close,'+currentRefitemId;
		}
		reflistAction.reflistitemClickHandler(this);
		return false;
	});
	
	
	//has curretn page the example option
	if(reflistAction.isExample){
		//observe document for links with class "examplelink", thats only links with multiple project loads
		$j('a.examplelink').live('click', function(e){
			if(examplelinkrunning)return false;
			examplelinkrunning = true;
			pauseBgAnim();	// console.info("DEBUG: pause2");
			reflistAction.examplelinkClickHandler(this);
			return false;
		});
	}
	
	// ----- Initializes history plugin -----
   	$j.history.init(
		function(hash) {
			//if(hash!=''){
				pauseBgAnim();	// console.info("DEBUG: pause2");
			
				reflistAction.restoreReflist(hash);
			//}
		},
		{
			unescape: ",/"
		}
	);
	
	
	//**********************************************
	// REFITEMS ACTION OBSERVER
	//**********************************************
	var allRefboxs = $j('.refbox');
	var lastRefboxIndes =  -1;
	
	allRefboxs.each(function(index){
		//init mouse-event Elements
		var jQueryImgElement = $j(this).find('a img');
		var jQueryTextElement = $j(this).find('.text-overlay');
		
		jQueryTextElement.click(function(event){
			
			if(jQueryTextElement.children('a:first').hasClass('link-to-reflistpage')){
				pauseBgAnim();	// console.info("DEBUG: pause3");
				
				var mythis = this;
				$j(window).bind('unload',function(){$j(mythis).mouseout();});
				window.location = $j(this).children('a:first').attr('href');
			}
			else{
				reflistAction.reflistitemClickHandler($j(this).children('a:first'));
			}
			return false;
		});
		
		var F=new NetvClientDetect();
		if(F.clientInfo['os_name']=='iPad' || F.clientInfo['os_name']=='iPhone' || F.clientInfo['os_name']=='iPod'){
			//**********************************************
			// special handling for mobile-browsers
			//**********************************************
			// set mouseover and mouseout function for image
			jQueryImgElement.mouseover(function(){
				jQueryImgElement.hide();
				jQueryTextElement.show();
			}).mouseout(function(){
				jQueryTextElement.hide();
				jQueryImgElement.show();
			});
			
			// set mouseover and mouseout function for textbox
			jQueryTextElement.mouseover(function(){
				jQueryTextElement.click();
			}).mouseout(function(){
				jQueryTextElement.hide();
				jQueryImgElement.show();
			});
		}
		else{
			//**********************************************
			// default handling for normal browsers
			//**********************************************
			// set mouseenter function for image
			jQueryImgElement.mouseenter(function(){
				if(lastRefboxIndes > -1){
					if($j(allRefboxs[lastRefboxIndes]).find('.inactive').length == 0){
						$j(allRefboxs[lastRefboxIndes]).find('.text-overlay').hide();
						$j(allRefboxs[lastRefboxIndes]).find('a img').show();
					}
				}
				lastRefboxIndes = index;
				jQueryImgElement.hide();
				jQueryTextElement.show();
			});
			
			// set mouseleave function for textbox
			jQueryTextElement.mouseleave(function(){
				if(!jQueryTextElement.hasClass('inactive')){
					jQueryTextElement.hide();
					jQueryImgElement.show();
					lastRefboxIndes = -1;
				}
			});
		}		
	});
	
});

