function PopupWindow(URL) {
h=360;
w=435;
window.open(URL,'Title','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,top='+Math.floor(screen.height/2-h/2)+',left='+Math.floor(screen.width/2-w/2)+',resizable=0,width='+w+',height='+h);
}
function displayMap( link ) {
	window.open(link,"Map","location=no,status=no,menubar=no,resizable=yes,width=435,height=360,toolbar=no"); 
}
/*******************LightBox Moving and Zoom*************************/
function loadImage() {
		
		$outer_container=jQuery(".mages-gallery-popup");
		$imagePan_panning=jQuery("#imagepan .panning");
		$imagePan=jQuery("#imagepan");
		$imagePan_container=jQuery("#imagepan .largeimage");

		$outer_container.css("top", (jQuery(window).height()-($outer_container.outerHeight()))/2);
		$imagePan_panning.css("margin-top",($imagePan.height()-$imagePan_panning.height())/2+"px");
		containerWidth=$imagePan.width();
		containerHeight=$imagePan.height();
		totalContentW=$imagePan_panning.width();
		totalContentH=$imagePan_panning.height();
		$imagePan_container.css("width",totalContentW).css("height",totalContentH);
		
		$imagePan_panning.css("margin-left",($imagePan.width()-$imagePan_panning.width())/2).css("margin-top",($imagePan.height()-$imagePan_panning.height())/2);

		jQuery('#zoomTarget').zoomable();
	}

function createPopup() {
	maskOverlay = jQuery("<div>").attr("class","maskimage");
	jQuery("body").append(maskOverlay);
	
	popupContainer = jQuery('.images-gallery-popup');	
	
	var imageWidth = 900;
	var imageHeight = 900; //jQuery(window).height();
	
	var windowWidth = jQuery(window).width();
	var documentHeight = jQuery(document).height();
	var windowHeight = jQuery(window).height();
	
	jQuery('.maskimage').css({'opacity':'0.5', 'display':'block', 'height':documentHeight, 'z-index': 10});
	jQuery(popupContainer).css({'left': (windowWidth - imageWidth)/2,'top': 0,'width': imageWidth,'height':imageHeight}).show();
	
	jQuery('#loadingpopupimage').css({'left': (windowWidth - 32)/2,'top': (windowHeight - 32)/2});
	
	loadImage();
	jQuery('.leftarrow, .rightarrow').css('top',((imageHeight/2)-51))
	jQuery('div.largeimage').css({left: '-11px', top: '0'});
}
function loadImg(url, obj, loading, msg)
{	
	var windowWidth = jQuery(window).width();
	var windowHeight = jQuery(window).height();
	
	jQuery(loading).css({'display':'block','left': (windowWidth - 32)/2,'top': (windowHeight - 32)/2}).stop(true,true).animate({opacity:1},1000);			//display the loading in progress image	
	jQuery(obj).html("<img src='"+url+"' class=\"panning\" id=\"zoomTarget\" />").css({opacity: 0});				//throw in the image into the div block
	
	var tmp = jQuery(obj).children();											//gets the image obj we just thrown in
		tmp[0].onload = function(){												//when the image has complete loaded
			jQuery(obj).stop(true,true).animate({opacity:1},1000);								//display the image
			jQuery(loading).stop(true,true).animate({opacity:0},1000).css({"display":"none"});	//hide the loading in progress image			
			jQuery('.leftarrow, .rightarrow').css({"display":"block"}).stop(true,true).animate({opacity:1},1000);
			jQuery('.images-gallery-popup').show();
			jQuery('.maskimage').remove();
			createPopup();
		}
		tmp[0].onerror = function(){											//when the image fail to load for various reason
			jQuery(this).css({"display":"none"});											//we hide the image that fail
			jQuery(obj).html(jQuery(obj).html()+"<div>"+msg+"</div>").stop(true,true).animate({opacity:1},1000);	//provides a message to the user instead
			jQuery(loading).stop(true,true).animate({opacity:0},1000).css({"display":"none"});	//hide the loading in progress image
		}
}
var thumbIndex = 0;
var numberImage = 0;

var popupImagesGallery = {
		
		setupEvents : function() {
			this.setupEventForShowPopup();
			this.setupPreviousButton();
			this.setupNextButton();
			this.setupClosePopopEvent();
		},
		
		setupEventForShowPopup : function() {		
			jQuery('.thumb_slide a').click(function(e){
				
				jQuery('.maskimage').remove();
				
				thumbIndex = jQuery('.thumb_slide a').index(this);
				
				var ele = '.largeimage';
				var popupContainer = '.images-gallery-popup';
				var loadingpopupimage = '#loadingpopupimage';
				var image = jQuery(this).attr('href'); 					
				loadImg(image,ele, loadingpopupimage, 'error');
				
				e.preventDefault();
			});
		
		},
		setupPreviousButton : function() {
			jQuery('div.images-gallery-popup .leftarrow').click(function(){
				jQuery('.images-gallery-popup').hide();
				popupImagesGallery.movingImage(false);				
			});		
		},
		setupNextButton : function() {
			jQuery('div.images-gallery-popup .rightarrow').click(function(){
				jQuery('.images-gallery-popup').hide();
				popupImagesGallery.movingImage(true);				
				
			});		
		},
		movingImage : function(move) {
			imageCount = jQuery('.thumb_slide img').length;			
			if(move) {
				thumbIndex = (thumbIndex+1)%imageCount;
				
			} else {
				thumbIndex = (imageCount + thumbIndex-1)%imageCount;
			}
			jQuery('.thumb_slide img').each(function(index, item){			
				if(index == thumbIndex) {
					
					popupImagesGallery.displayImagePopup(jQuery(this).attr('src'));
				}
			});			
		},
		displayImagePopup : function(image) {
			
			var ele = '.largeimage';
			var popupContainer = '.images-gallery-popup';
			var loadingpopupimage = '#loadingpopupimage';
			
			loadImg(image,ele, loadingpopupimage, 'error');			
		},
		setupClosePopopEvent : function() {			
			jQuery('a.close, .maskimage').live('click',function(e){
				jQuery('.images-gallery-popup').hide();
				jQuery('.maskimage').remove();
				e.preventDefault();
			});	
		}
		
}
jQuery(window).resize(function() {
	$imagePan.unbind("mousemove");
	$imagePan_container.css("top",0).css("left",0);
	jQuery(window).load();
});
jQuery(document).ready(function(){	
	//navigation
	jQuery("ul.dropdown li").hover(function(){
    
		jQuery(this).addClass("hover");
		jQuery('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
    	jQuery(this).removeClass("hover");
    	jQuery('ul:first',this).css('visibility', 'hidden');
    
    });
    
	jQuery("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

		
	// loop id show in list
	var num =0;
	jQuery("ul.dropdown li").each(function (i) {		
	 
	   var item = jQuery(this).parent().attr("class");
	   if(item == "dropdown"){
		   
		   jQuery(this).attr("id","item" + num)
		   num += 1;
		}
	 });	
	
	// set class active in a tag
	jQuery('ul.dropdown li.current_page_item a').attr("class",'active');
	jQuery('ul.dropdown li.current_page_ancestor a').attr("class",'active');
	
	
	if(jQuery('#pane2').length)
	{
		jQuery('#pane2').jScrollPane({showArrows:true});
	}
	/*//Zoom
	jQuery('.zoom').loupe();

	//zoom action
	jQuery('.zoom').click(function(e){
		e.preventDefault();
	});
	jQuery('.loupe').mousedown( function () { 
      jQuery(this).css('display','none');
    });*/
	popupImagesGallery.setupEvents();
});
