var $jQ=jQuery.noConflict();
var gBigWindows = new Array();
var gBigOpenWindow=false


henworx.MapCms.BigWindow= function(_loc,init_data){
	/*
	Adds click events on the li that works as tabs in popup detail page
	*/
	
	if(typeof(init_data)=='undefined'){
		init_data=true;
	}
	
	var _container=document.getElementById('henworx_mapcms_detail_container_hideshow');
	_lang = henworx.MapCms.Lang;
	this.location=_loc
	this.stem=""
	this.noStem = ""
	this.stemPosition=""
	/*
	this.closeIcon='<img src="'+gPluginUrl+'/includes/ewindow/icon_close.png" class="cntrl" />';
	this.minIcon='<img src="'+gPluginUrl+'/includes/ewindow/icon_min.gif" class="minimise_big_window" />';
	*/
	this.closeIcon=_lang.getWord('Close');
	this.minIcon=_lang.getWord('Minimize');
	
	_stem="";
	
	/*if(_container.style.background){
		_stem=_container.style.background;
		this.stem=_stem;
	}*/
	

	gBigWindows[_loc.id]=this;
	
		
	
	this.reLoad=function(){
		
		this.html=requestURL(gPluginUrl+'/includes/get-big-window.php?id='+this.location.id,false,false);
		emblem=this.location.emblem.split("*");  //replace(/\s/g,"_"); ///^\s*|\s*$/g
		emblem=emblem[0];
		emblem=emblem.replace(" ","_");
		emblem=emblem.toLowerCase();
		this.html='<div class="popup_block '+emblem+'"> <div class="popup"> <a href="javascript:void(0)" onclick="henworx.MapCms.BigWindow.minimize(); return false;" title="'+_lang.getWord('Minimize')+'" class="min_icon" >'+this.minIcon+'</a> <a href="javascript:void(0)" onclick="henworx.MapCms.BigWindow.hide(); return false;" title="'+_lang.getWord('Close')+'" class="close_bigwindow">'+this.closeIcon+'</a> '+this.html+' </div> </div>';
		//$jQ(".henworx_mapcms_tab_content").hide();
		$jQ(document).ready(function(){
	
			//On Click Event
			$jQ("ul.henworx_mapcms_tabs li").live('click',function() {
																   
				$jQ("ul.henworx_mapcms_tabs li").removeClass("active"); //Remove any "active" class
				$jQ(this).addClass("active"); //Add "active" class to selected tab

				 //Hide all tab content
				 $jQ(".henworx_mapcms_tab_content").hide();
				var activeTab = $jQ(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
				//ie 7 bug shos the host in the href
				/*		ie7 bug fix		*/
				lastPosofSlash=activeTab.lastIndexOf("#");
				if(lastPosofSlash>1){
				activeTab=activeTab.substr(lastPosofSlash)
				}
				
				/*	ie7 bug fix end			*/
				$jQ(activeTab).show(); //Fade in the active content
				
			});
					
		
		});
		
	}
	
	if(init_data){
		this.reLoad()// intialize data for the first time
	}
	
	this.show=function(hideStem){
		henworx.MapCms.BigWindow.beforeShow(this.location,hideStem)
		henworx.MapCms.BigWindow.hide(); // hide old window
		
		_container.style.display = 'block';
		
		_container.innerHTML = this.html;
		gBigOpenWindow = this;
		if(this.stem==""){
			this.stem=gPluginUrl+"/includes/ewindow/stem_mapcms_default.png"
		}
		if(this.stemPosition==""){
			this.stemPosition=" right bottom"
		}
		
			
			$jQ(".henworx_mapcms_tab_content").hide();
			$jQ("ul.henworx_mapcms_tabs li").removeClass("active"); //Remove any "active" class
			$jQ("ul.henworx_mapcms_tabs li:first").addClass("active"); //Remove any "active" class
			$jQ(".henworx_mapcms_tab_content:first").show();
			//enable lighbox effect
			$jQ(".lightbox-2").lightbox({
			    fitToScreen: true,
				fileLoadingImage: gPluginUrl+'/includes/lightbox/images/loading.gif',
				fileBottomNavCloseImage: gPluginUrl+'/includes/lightbox/images/closelabel_'+gDefaultLang+'.gif',
				strings : { image: _lang.getWord('Image')+' ' , of : _lang.getWord(' of ') , prevLinkText: _lang.getWord('&laquo; Previous') , nextLinkText : _lang.getWord('Next &raquo;'),
							closeTitle : _lang.getWord('close image gallery'), prevLinkTitle : _lang.getWord('previous image'), nextLinkTitle : _lang.getWord('next image')
							}
			});
			$jQ('#henworx_mapcms_detail_container_hideshow').removeClass()
			
			emblem=this.location.emblem.split("*");
			emblem=emblem[0];
			emblem=emblem.replace(" ","_");
			emblem=emblem.toLowerCase();
		
			if(typeof(hideStem)=='boolean'){
				if(hideStem){
					$jQ('#henworx_mapcms_detail_container_hideshow').addClass('hide_stem_'+emblem)
					$jQ('#henworx_mapcms_detail_container_hideshow').addClass('hide_stem')
					
				}
				else{
					$jQ('#henworx_mapcms_detail_container_hideshow').addClass('show_stem_'+emblem)
					$jQ('#henworx_mapcms_detail_container_hideshow').addClass('show_stem')
					//$jQ('#henworx_mapcms_detail_container_hideshow').removeClass()
				}
			}
			else{
					$jQ('#henworx_mapcms_detail_container_hideshow').addClass('show_stem_'+emblem)
					$jQ('#henworx_mapcms_detail_container_hideshow').addClass('show_stem')
					//$jQ('#henworx_mapcms_detail_container_hideshow').removeClass()
			}
			henworx.MapCms.BigWindow.afterShow(this.location,hideStem)
	}
	
}

//static function
henworx.MapCms.BigWindow.hide=function(){
	_container=document.getElementById('henworx_mapcms_detail_container_hideshow');
	_container.style.display = 'none'; 
	if(typeof(gBigOpenWindow.location)!='undefined'){
		gBigOpenWindow.html=_container.innerHTML; // the inner html may cahnge
		gBigOpenWindow = false;
	}
	if(typeof(henworx.MapCms.BigWindow.afterHide)=='function'){
		henworx.MapCms.BigWindow.afterHide();
	}
	
}

//static function
henworx.MapCms.BigWindow.minimize=function(){
	_loc=gMapCms.findLocation(gBigOpenWindow.location.id);
	MarkerEventPause.loc=_loc
	MarkerEventPause.marker=_loc.marker
	MarkerEventPause.map=gMapCms.map
	henworx.MapCms.Ewindow.hide('immediate'); //hide if old ewindow is open
	henworx.MapCms.BigWindow.hide();
	MarkerEventPause.onMousePause(true);
	if(typeof(henworx.MapCms.BigWindow.afterMinimize)=='function'){
		henworx.MapCms.BigWindow.afterMinimize();
	}
	
}

//static function
henworx.MapCms.BigWindow.maximize=function(id){		
	
	if(!gBigWindows[id]){
			_loc=gMapCms.findLocation(id)
			gBigWindows[id]= new henworx.MapCms.BigWindow(_loc)			
	}
	gBigWindows[id].show(hide_stem=false);
	gMapCms.map.panTo(_loc.marker.getLatLng());
}

henworx.MapCms.BigWindow.beforeShow=function(_loc,hideStem){};
henworx.MapCms.BigWindow.afterShow=function(_loc,hideStem){};