var b_version = "na";
var is_ie = false;
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=3)
  b_version=("FF3")
 else
  b_version=("FF2")
} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 is_ie = true;
 if (version>=8)
  b_version=("IE8")
 else if (version>=7)
  b_version=("IE7")
 else
  b_version=("IE6")
} else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=10)
  b_version=("Opera10")
 else
  b_version=("Opera9")
} else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=530)
  b_version=("Safari4")
 else
  b_version=("Safari3")
}
var mouseX = 0;
var mouseY = 0;
var temp_html = "";
	var alpha = 0.9;


$(document).ready(function(){
						   
	$('#preloader').hide();
	$('body').removeClass();
	$('#panel').show();
	var canvasW = $(window).width(); 
	var canvasH  = $(window).height();
	var winWidth = canvasW; 
	var winHeight  = canvasH;
	var imgW, imgH, imgW_init, imgH_init; 
	var img_margin = 40;
	var img_border = 20;
	var img_border_t = 60;
	var img_border_b = 60;
	var is_bg = false;
	var slideshow_speed = 5600;
	var minH = 668;
	var minW = 1160;
	var bg_lbl;
	
	
	
	
	jQuery.fn.resize_bg = function() {	
	
			
			
			canvasW = $(window).width(); 
			canvasH  = $(window).height();
					
			if (canvasW<minW) {
				canvasW=minW;
			}
			if (canvasH<minH) {
				canvasH=minH;
			}
			
			var contentW = canvasW-180-(40*2);
			//$("#content").css("width",contentW+"px");
			
			
			winWidth = canvasW; 
			winHeight  = canvasH;
			
			
			if (winWidth/winHeight>4/3) {
				winHeight = winWidth*3/4;
			} else if (winWidth/winHeight<4/3) {
				winWidth = winHeight*4/3;		
			}		
			$("#bg_img").css("width",winWidth+"px");
			$("#bg_img").css("height",winHeight+"px");
			$("#canvas").css("width",canvasW+"px");
			$("#content").css("display","inline");
			$("#content .bg").css("display","block");
			//$("#panel").css("display","inline");
			//$("#mainmenu").css("display","inline");	
			
			if (b_version!="IE6") {
				$("#bg").css("display","inline");
			}
			
			if ($("#content").height()+80+0<canvasH) {
			$("#content").css("padding-bottom",(canvasH-$("#content").height()-80)+"px");
			} else {
			$("#content").css("padding-bottom",0+"px");
			}
			
			if ($("#content .table_0").width()+178>$("#content").width()) {
				$("#content").css("width",($("#content .table_0").width()+178)+"px");
				
			}
			
			//$('#overlay').css('width',winWidth);
			//$('#overlay').css('height',winHeight);
			$('#overlay').css('width',$(document).width());
			$('#overlay').css('height',$(document).height());
			
			
			
			imgW = imgW_init;
			imgH = imgH_init;
			if (imgW_init>canvasW-img_margin*2-img_border*2) {
				imgW = canvasW-img_margin*2-img_border*2;
				imgH = imgW*imgH_init/imgW_init;
			}
			if (imgH_init>canvasH-img_margin*2-img_border_t-img_border_b) {
				imgH = canvasH-img_margin*2-img_border_t-img_border_b;
				imgW = imgH*imgW_init/imgH_init;
			}
			
			//$('#overlay .overlay_img').css('width', imgW+'px');
			//$('#overlay .overlay_img').css('height', imgH+'px');
			//$('#overlay .overlay_info_box').css('width', imgW+'px');
			//$('#overlay .overlay_info_box').css('height', imgH+'px');
			//$('#overlay .overlay_container').css('left', (canvasW/2-imgW/2-img_border)+'px');
			//$('#overlay .overlay_container').css('top', (canvasH/2-imgH/2-img_border_t)+'px');
			
			//$("#canvas").css("height",canvasH+"px");
			
			
			//if ($(document).width()>contentW+100) {
			//$("#content").css("width",($(document).width()-100)+"px");
			//}
			if (b_version==("IE6")) {
				$('#content .bg').each(function (i) {
					$(this).height($(this).parent().height()+Number($(this).parent().css('padding-top').replace('px',''))+Number($(this).parent().css('padding-bottom').replace('px','')));
					$(this).width($(this).parent().width()+Number($(this).parent().css('padding-left').replace('px',''))+Number($(this).parent().css('padding-right').replace('px','')));
				});
			}
			
			jQuery.fn.move_panel();
			//jwplayer("mov_player").setup({ flashplayer: "js/player.swf" });
			/*
			$('.vid img').each(function() {
									 $(this).parent().prepend('<div id="'+$(this).attr('id').replace('vid_','mov_')+'"></div>');
									swfobject.embedSWF('videoplayer.swf', $(this).attr('id').replace('vid_','mov_'),  $(this).attr('width'), $(this).attr('height'), '10', 
									'expressinstall.swf', {img_path: $(this).attr('src'),mov_path:$(this).attr('alt')}, {allowscriptaccess: 'always', bgcolor: '#000000', menu: 'false', wmode: 'opaque',allowFullScreen:'true'}, {id: $(this).attr('id').replace('vid_','mov_')},null);
									 $(this).remove();
									 });
			*/
			
			if ($('#overlay .overlay_img').length>0) {
				imgW = (canvasW-parseInt($('#overlay .overlay_container').css('padding-left'))-parseInt($('#overlay .overlay_container').css('padding-right')))-parseInt($('#overlay .overlay_container').css('padding-right'))*2;
				imgH = (canvasH-parseInt($('#overlay .overlay_container').css('padding-top'))-parseInt($('#overlay .overlay_container').css('padding-bottom')))-parseInt($('#overlay .overlay_container').css('padding-right'))*2;
				
				var screenW = imgW;
				var screenH = imgH;
				var screenX = 0;
				var screenY = 0;
				if (imgW_init/imgH_init>imgW/imgH) {
					if (imgW_init>imgW) {
						screenW = imgW;
						screenH = imgH_init/imgW_init*screenW;
					} else {
						screenW = imgW_init;
						screenH = imgH_init;
					}
				} else {
					if (imgH_init>imgH) {
						screenH = imgH;
						screenW = imgW_init/imgH_init*screenH;
					} else {
						screenW = imgW_init;
						screenH = imgH_init;
					}
				}
				if (imgW>screenW) {
					screenX = imgW/2-screenW/2;
				}
				if (imgH>screenH) {
					screenY = imgH/2-screenH/2;
				}
				
				
				
				//alert(screenX+"|"+screenY);
				$('#overlay .overlay_img').width(screenW);
				$('#overlay .overlay_img').height(screenH);
				$('#overlay .overlay_img').css('left',screenX+'px');
				$('#overlay .overlay_img').css('top',screenY+'px');
				$('#overlay .overlay_info_box').width(imgW);
				$('#overlay .overlay_info_box').height(imgH);
				$('#overlay .overlay_row_b').width(imgW);
				//$('#overlay .overlay_container').css('left', (canvasW/2-imgW/2-img_border)+'px');
				//$('#overlay .overlay_container').css('top', (canvasH/2-imgH/2-img_border_t+scrollH)+'px');
				$('#overlay .overlay_container').width(imgW);
				$('#overlay .overlay_container').height(imgH);
				$('#overlay .overlay_img_box').width(imgW);
				$('#overlay .overlay_img_box').height(imgH);
			}
		
	};
	
	//jQuery.fn.move_panel();
	
	
	
	//$('.thumbbox .cell_2 .cell_but').bind("click",jQuery.fn.img_click);
	jQuery.fn.event_thumb_click = function() {	
		$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_event_img(this.id.replace("img_", ""));
	};
	jQuery.fn.setup_event_img = function(id) {
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		var query_common = $('#query_common').val();
		var page_id = $("#page_id").val();
		var event_id = $("#event_id").val();
		$('#overlay .overlay_container').hide();
		$('#overlay .overlay_box').load("incl/backend.php", {func:'setup_event_img', id:id, page_id:page_id, event_id:event_id},
			function() {
				$('#overlay .overlay_container').hide();
				var filename = $('#filename_'+id).html();
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', 'data/event/'+event_id+'/'+filename, 'overlay_img', '', jQuery.fn.loaded_img_data);
				//alert('data/event/'+event_id+'/'+filename);
				jQuery.fn.setup_alpha();
			}
		);
	}
	jQuery.fn.news_thumb_click = function() {	
		$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_news_img(this.id.replace("img_", ""));
	};
	jQuery.fn.setup_news_img = function(id) {
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		var query_common = $('#query_common').val();
		var page_id = $("#page_id").val();
		var news_id = $("#news_id").val();
		$('#overlay .overlay_container').hide();
		$('#overlay .overlay_box').load("incl/backend.php", {func:'setup_news_img', id:id, page_id:page_id, news_id:news_id},
			function() {
				$('#overlay .overlay_container').hide();
				var filename = $('#filename_'+id).html();
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', 'data/news/'+news_id+'/'+filename, 'overlay_img', '', jQuery.fn.loaded_img_data);
				//alert('data/event/'+event_id+'/'+filename);
				jQuery.fn.setup_alpha();
			}
		);
	}
	jQuery.fn.project_thumb_click = function() {	
		$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_project_img(this.id.replace("img_", ""));
		
	};
	jQuery.fn.setup_project_img = function(id) {
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		var page_id = $("#page_id").val();
		var project_id = $("#project_id").val();
		$('#overlay .overlay_container').hide();
		$('#overlay .overlay_box').load("incl/backend.php", {func:'setup_project_img', id:id, page_id:page_id, project_id:project_id, thumb_no:id},
			function() {
				$('#overlay .overlay_container').hide();
				var filename = $('#filename_'+id).html();
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', 'data/project/'+project_id+'/'+filename, 'overlay_img', '', jQuery.fn.loaded_img_data);
				//alert('data/event/'+event_id+'/'+filename);
				jQuery.fn.setup_alpha();
			}
		);
	}
	
	jQuery.fn.thumb_click = function() {	
		//if($('body').width()>canvasW) {
			//$('#overlay').css('width', $(window).innerWidth());
		//} else {
		//	$('#overlay').css('width', canvasW);
		//}
		//if($('body').height()>canvasH) {
		//	$('#img_big_box').css('height', $('body').height());
	//	} else {
			//$('#overlay').css('height', $(window).innerHeight());
			
			//$('#img_big_box').css('width', $('body').offset().width);
			is_bg = false;
			$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_img(this.id.replace("img_", ""),is_bg);
		//}
		//big_img = ($(this).parent().find("img").eq(0).attr('src')).replace("thumb_","big_");
	};
	jQuery.fn.thumb_bg_click = function() {	
			is_bg = true;
			$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_img($(this).attr('id').replace("img_", ""),is_bg);
	};
	jQuery.fn.thumb_rollover = function() {	
		$('.thumb_pop').css('display', 'none');
		$(this).parent().find(".thumb_pop").eq(0).css('display', 'block').css('left', '0px').css('top', '0px');
			//alert(($(this).offset().top+$(this).height())+"|"+($('#content').height()-40));
		if(($(this).offset().top+$(this).height())>($('#content').height())) {
			$(this).parent().find(".thumb_pop").eq(0).css('top', '-160px');
		}
		if(($(this).offset().left+$(this).width())>($('#content').width())) {
			$(this).parent().find(".thumb_pop").eq(0).css('left', '-180px');
		}
		$(this).parent().find(".thumb_pop").eq(0).hide().fadeIn("normal");
		//$('.thumbbox .cell_2').css('z-index', '1');
		$(this).parent().css('z-index', '100');
	};
	jQuery.fn.thumb_rollout = function() {	
		$('.thumb_pop').css('display', 'none');
		$(this).parent().css('z-index', '1');
	};
	
	jQuery.fn.setup_img = function(id, bg) {
		var my_id = id;
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		if ($('#overlay_thumb_'+id).length > 0) {
			var thumb_no = $('#overlay_thumb_'+id).val();
		} else  {
			var thumb_no = $('#thumb_'+id).val();
		}
		if (bg) {
			my_id = $('#thumb_bg_id').val();
			var query_common = $('#query_common_bg').val();
			var thumb_no = $('#thumb_bg').val();
		} else {
			if (is_bg) {
				var query_common = $('#query_common_bg').val();
			} else {
				var query_common = $('#query_common').val();
			}
		}
		
		//alert(thumb_no+"|"+query_common);
		var page_id = $("#page_id").val();
		$('#overlay .overlay_container').hide();
		var my_func = 'setup_img';
		var my_path = 'data/location/big/';
		$('#overlay .overlay_box').load("incl/backend.php", {func:my_func, id:my_id, thumb_no:thumb_no, query_common:query_common, page_id:page_id},
			function() {
				$('#overlay .overlay_container').hide();
				//var filename = $('#filename_'+my_id).val().toLowerCase();
				var filename = $('#filename_'+my_id).html();
				//alert($('#filename_'+id).val());
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', my_path+filename+'.jpg', 'overlay_img', '', jQuery.fn.loaded_img_data);
				jQuery.fn.setup_alpha();
			}
		);
	}
	
	jQuery.fn.preload_img = function(my_target, my_loader_target, my_src, my_class, my_alt, my_func) {
		jQuery.fn.show_loader(my_loader_target,null);		
		var img = $('<img />').attr('src', my_src+'?'+Number(new Date())).attr('alt', my_alt).attr('class', my_class).load(
			function() {			
				jQuery.fn.hide_loader(my_loader_target);
				$(my_target).append( $(this) );
				my_func();
				//$(my_target).hide().fadeIn("slow");
			}
		);
		
	}
			
	jQuery.fn.loaded_img_data = function() {
		//alert($('#overlay_img').height()+"|"+$('#overlay_img').width());
		$('#overlay .overlay_container').fadeIn("slow");
		imgW_init = $('#overlay .overlay_img').width();
		imgH_init = $('#overlay .overlay_img').height();
		imgW = imgW_init;
		imgH = imgH_init;
		/*
		if (imgW/imgH > canvasW/canvasH) {
			if (imgW<640) {
				imgW = 640;
				imgH = imgH_init/imgW_init*imgW;
			}
		} else {
			if (imgH<480) {
				imgH = 480;
				imgW = imgW_init/imgH_init*imgH;
				if (imgW<480) {
					imgW = 480;
					imgH = imgH_init/imgW_init*imgW;
				}	
			}		
		}
		*/
		var scrollH=$(window).scrollTop();
		
		
		imgW = (canvasW-parseInt($('#overlay .overlay_container').css('padding-left'))-parseInt($('#overlay .overlay_container').css('padding-right')))-parseInt($('#overlay .overlay_container').css('padding-right'))*2;
		imgH = (canvasH-parseInt($('#overlay .overlay_container').css('padding-top'))-parseInt($('#overlay .overlay_container').css('padding-bottom')))-parseInt($('#overlay .overlay_container').css('padding-right'))*2;
		
		var screenW = imgW;
		var screenH = imgH;
		var screenX = 0;
		var screenY = 0;
		if (imgW_init/imgH_init>imgW/imgH) {
			if (imgW_init>imgW) {
				screenW = imgW;
				screenH = imgH_init/imgW_init*screenW;
			} else {
				screenW = imgW_init;
				screenH = imgH_init;
			}
		} else {
			if (imgH_init>imgH) {
				screenH = imgH;
				screenW = imgW_init/imgH_init*screenH;
			} else {
				screenW = imgW_init;
				screenH = imgH_init;
			}
		}
		if (imgW>screenW) {
			screenX = imgW/2-screenW/2;
		}
		if (imgH>screenH) {
			screenY = imgH/2-screenH/2;
		}
		
		
		
		//alert(screenX+"|"+screenY);
		$('#overlay .overlay_img').width(screenW);
		$('#overlay .overlay_img').height(screenH);
		$('#overlay .overlay_img').css('left',screenX+'px');
		$('#overlay .overlay_img').css('top',screenY+'px');
		$('#overlay .overlay_info_box').width(imgW);
		$('#overlay .overlay_info_box').height(imgH);
		$('#overlay .overlay_row_b').width(imgW);
		//$('#overlay .overlay_container').css('left', (canvasW/2-imgW/2-img_border)+'px');
		//$('#overlay .overlay_container').css('top', (canvasH/2-imgH/2-img_border_t+scrollH)+'px');
		$('#overlay .overlay_container').width(imgW);
		$('#overlay .overlay_container').height(imgH);
		$('#overlay .overlay_img_box').width(imgW);
		$('#overlay .overlay_img_box').height(imgH);
		
		
		$('#overlay .overlay_info_box').hide();
		$('#overlay #overlay_but_info_close').hide();
		//$('#overlay #overlay_but_info_open').hide();
		
		$('#overlay #overlay_but_close').bind("click",function() {$('#overlay').fadeOut("slow");});
		$('#overlay .bg').bind("click",function() {$('#overlay').fadeOut("slow");});
		
		
		$('#overlay #overlay_but_info_close').bind("click",function() {$('#overlay .overlay_info_box').fadeOut("slow");$('#overlay #overlay_but_info_close').hide();$('#overlay #overlay_but_info_open').show();});
		$('#overlay #overlay_but_info_open').bind("click",function() {$('#overlay .overlay_info_box').fadeIn("slow");$('#overlay #overlay_but_info_open').hide();$('#overlay #overlay_but_info_close').show();});
		if (is_bg) {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_page_", ""),false);});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_arrow_", ""),false);});
		} else if (template=="project_list") {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_project_img(this.id.replace("overlay_page_", ""));});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_project_img(this.id.replace("overlay_arrow_", ""));});
		} else if (template=="event_list") {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_event_img(this.id.replace("overlay_page_", ""));});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_event_img(this.id.replace("overlay_arrow_", ""));});
		} else if (template=="news_list") {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_news_img(this.id.replace("overlay_page_", ""));});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_news_img(this.id.replace("overlay_arrow_", ""));});
		} else {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_page_", ""),false);});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_arrow_", ""),false);});
		}
	}
	
	jQuery.fn.show_loader = function(my_target,my_template) {
		jQuery.fn.hide_loader(my_target);
		var target_w = $(my_target).width()+parseInt($(my_target).css('padding-left'))+parseInt($(my_target).css('padding-right'));
		var target_h = $(my_target).height()+parseInt($(my_target).css('padding-top'))+parseInt($(my_target).css('padding-bottom'));
		if (my_template) {
			$(my_target).append('<img src="images/'+my_template+'.gif" alt="" class="loader" width="16" height="16" style="left:'+(target_w*0.5-8)+'px;top:'+(target_h*0.5-8)+'px"/>');
		} else {
			$(my_target).append('<img src="images/loader_0.gif" alt="" class="loader" width="32" height="32" style="left:'+(target_w*0.5-16)+'px;top:'+(target_h*0.5-16)+'px"/>');
		}
	}
	jQuery.fn.hide_loader = function(my_target) {
		$(my_target+' .loader').remove();
	} 
	jQuery.fn.change_page = function() {
		var my_href = $(this).attr('href');
		if (my_href) {
			var page_no = my_href.split("page_no=")[1];
			$(this).attr('href', '#');		
			jQuery.fn.show_loader('#location_list',null);
			$('#location_page').load("incl/backend.php", {func:'change_page', page_no:page_no, page_tot:$('#page_tot').val(), page_max:$('#page_max').val(), url:$('#url').val(), thumb_max:$('#thumb_max').val(), result_no:$('#result_no').val()},function() {$('#location_page a').bind("click",jQuery.fn.change_page);});
			$('#location_list').load("incl/backend.php", {func:'change_list', page_no:page_no, page_tot:$('#page_tot').val(), thumb_max:$('#thumb_max').val(), query_common:$('#query_common').val()},
				function() {
					//alert($('.thumb_but').length);
					jQuery.fn.hide_loader('#location_list');
					$('.thumb_but').bind("mouseenter",jQuery.fn.thumb_rollover);
					$('.thumb_but').bind("mouseleave",jQuery.fn.thumb_rollout);
					$('.thumb_but').bind("click",jQuery.fn.thumb_click);
					jQuery.fn.setup_alpha();
					jQuery.fn.resize_bg();
				}
			);
		}
	}
	
	jQuery.fn.move_panel = function() {
		
		var targetH=$(window).scrollTop();
		var my_h = $("#mainmenu").height()+4;
		if ((my_h)>($("#content").height())) {
			targetH=0;
		} else {
			
			if ((targetH+(my_h))>($("#content").height())) {
				targetH=($("#content").height())-(my_h);
			}
		}
		$("#mainmenu").css("top",targetH);
		
	}
	
	jQuery.fn.change_calendar = function() {
		var tDate = $(this).attr('id');
		jQuery.fn.show_loader('#calendar','loader_1');
		var page_id = $("#page_id").val();
		$('#calendar').load("incl/backend.php", {func:'change_calendar', tDate:tDate, page_id:page_id},function() {jQuery.fn.hide_loader('#calendar');$('.calendar_arrow').bind("click",jQuery.fn.change_calendar);jQuery.fn.calendar_cell_populated();});
	}
	jQuery.fn.change_event_calendar = function() {
		if ($(this).find("a").length>0) {
			if ($(this).attr('class')=="but_1") {
				$("#cal_type").val($(this).find("a").eq(0).attr('id').replace("cal_type_",""));
			} else {
				$("#cal_type").val("");
			}
		}
		var tDate = $(this).attr('id');
		jQuery.fn.show_loader('#calendar_event',false);
		var page_id = $("#page_id").val();
		var cal_type = $("#cal_type").val();
		$('#calendar_event').load("incl/backend.php", {func:'change_event_calendar', tDate:tDate, page_id:page_id, cal_type:cal_type},function() {jQuery.fn.hide_loader('#calendar_event');$('#calendar_event_but .but_1').bind("click",jQuery.fn.change_event_calendar);$('#calendar_event_but .but_1_selected').bind("click",jQuery.fn.change_event_calendar);jQuery.fn.setup_alpha();jQuery.fn.calendar_cell_populated(); setup_popup();});
	}
	jQuery.fn.close_panel_up = function() {
		$('#panel_up table').hide();
		$('#panel_up_open').show();
	}
	jQuery.fn.open_panel_up = function() {
		$('#panel_up table').show();
		$('#panel_up_open').hide();
	}
	jQuery.fn.close_panel_dn = function() {
		$('#panel_up table').hide();
		$('#panel_dn_container').hide();
		$('#panel_dn_open').show();
		$('#panel_dn_close').hide();
		$('#news_scroll').cycle('stop');
	}
	jQuery.fn.open_panel_dn = function() {
		$('#panel_up table').show();
		$('#panel_dn_container').show();
		$('#panel_dn_open').hide();
		$('#panel_dn_close').show();
		$('#news_scroll').cycle({fx:'scrollLeft',startingSlide: 0, timeout:slideshow_speed});
	}
	jQuery.fn.initial_news_col = function(this_news) {
		if ($('#open_title').length==0) {
			var col_no = this_news.parent().find(".col_no").val();
			var row_no = this_news.parent().find(".row_no").val();
			this_news.parent().find(".body").show();
			this_news.parent().find(".title_long").show();
			this_news.parent().find(".title").hide();
			this_news.parent().find(".title").css('opacity', 1);
			this_news.parent().find(".status").val('y');
			$('#news_slideshow_'+col_no).cycle(Number(row_no));
		} else {
			if ($('#open_title').val()=="showall") {
				this_news.parent().parent().find(".body").show();
				this_news.parent().parent().find(".title_long").show();
				this_news.parent().parent().find(".title").hide();
				this_news.parent().parent().find(".title").css('opacity', 1);
				this_news.parent().parent().find(".status").val('y');
			} else if ($('#open_title').val()=="title_only") {
				
			} else if (!isNaN($('#open_title').val())) {
				this_news.parent().find(".body").hide();
				this_news.parent().find(".title_long").hide();
				this_news.parent().find(".title").show();
				this_news.parent().find(".title").css('opacity', 1);
				this_news.parent().find(".status").val('y');
				
				this_news.parent().find(".body").eq($('#open_title').val()).show();
				this_news.parent().find(".title_long").eq($('#open_title').val()).show();
				this_news.parent().find(".title").eq($('#open_title').val()).hide();
				this_news.parent().find(".title").eq($('#open_title').val()).css('opacity', 1);
				this_news.parent().find(".status").eq($('#open_title').val()).val('y');
			} else if ($('#open_title').val()=="nochange") {
				this_news.parent().find(".body").show();
				this_news.parent().find(".title_long").show();
				this_news.parent().find(".title").show();
			}
			//this_news.parent().parent().find(".body").show();
			//this_news.parent().parent().find(".title_long").show();
			//this_news.parent().parent().find(".title").hide();
			//this_news.parent().parent().find(".title").css('opacity', 1);
			//this_news.parent().parent().find(".status").val('y');
		}
		jQuery.fn.resize_bg();
	};
	jQuery.fn.setup_news_col = function() {
		var this_news = $(this);
		
		if ($('#open_title').length==0 || !isNaN($('#open_title').val())) {
			var col_no = this_news.parent().find(".col_no").val();
			var row_no = this_news.parent().find(".row_no").val();
			var classname = this_news.parent().attr('class');
			this_news.parent().parent().find(".body").hide();
			this_news.parent().parent().find(".title_long").hide();
			this_news.parent().parent().find(".title").show();
			this_news.parent().parent().find(".title").css('opacity', alpha);
			if (classname!='selected') {
				this_news.parent().parent().find('li').removeClass();
				this_news.parent().find(".body").show();
				this_news.parent().find(".title_long").show();
				this_news.parent().find(".title").hide();
				this_news.parent().find(".title").css('opacity', 1);
				this_news.parent().addClass('selected');
			} else {
				this_news.parent().parent().find('li').removeClass();
			}
			$('#news_slideshow_'+col_no).cycle(Number(row_no));
		} else {
			if ($('#open_title').val()=="showall") {
				this_news.parent().parent().parent().find('li').removeClass();
				this_news.parent().parent().find(".body").show();
				this_news.parent().parent().find(".title_long").show();
				this_news.parent().parent().find(".title").hide();
				this_news.parent().parent().find(".title").css('opacity', 1);
				this_news.parent().parent().addClass('selected');
			} else if ($('#open_title').val()=="title_only") {
				
			}		 	
		}
		
		
		jQuery.fn.resize_bg();
	};
	jQuery.fn.rollover_news_col = function() {
		var this_news = $(this);
		this_news.css('opacity', 1);
	};
	jQuery.fn.rollout_news_col = function() {
		var this_news = $(this);
		var classname = this_news.parent().attr('class');
		if (classname!='selected') {
			this_news.css('opacity', alpha);
		}
	};
	jQuery.fn.rollover_news_list = function() {
		var this_news = $(this);
		this_news.css('opacity', 1);
	};
	jQuery.fn.rollout_news_list = function() {
		var this_news = $(this);
		if (!this_news.is('.selected')) {
			this_news.css('opacity', alpha);
		}
	};
	jQuery.fn.initial_news_list = function() {
	}
	jQuery.fn.setup_news_list = function() {
		var this_news = $(this);
		var href = this_news.find("a").attr("href");
		window.location = href;
		
	};
	
	jQuery.fn.calendar_cell_populated = function() {
		$('.events').parent().bind("mouseenter",function() {
							var my_h = $('.events',this).height();
							var my_margintop =  parseInt($(this).css('margin-top'));
							$('.events',this).css('margin-top',-my_h-my_margintop-8);
							$('.events',this).show();
							$('#panel').css('z-index',99999);
							$('#menuitem').css('z-index',9999);
							$('.events').parent().css('z-index',1);							
							$(this).css('z-index',999);
												});
		$('.events').parent().bind("mouseleave",function() {
							$('.events',this).hide();
												});
	}
	jQuery.fn.rollover_table_0 = function() {
		var this_row = $(this);
		var color1 = $('#color1').val();
		var color2 = $('#color2').val();
		this_row.not('.title').not('.selected').find('td').css("background-color",color2);
	};
	jQuery.fn.rollout_table_0 = function() {
		var this_row = $(this);
		var color1 = $('#color1').val();
		var color2 = $('#color2').val();
		this_row.not('.title').not('.selected').find('td').css("background-color",color1);
	};
	jQuery.fn.click_table_0 = function() {
		var this_row = $(this);
		var my_href = this_row.not('.title').find('a').eq(0).attr('href');
		if (this_row.not('.title').length>0 && my_href) {
			window.location = my_href;
		}
	};
	jQuery.fn.rollover_but_1 = function() {
		var this_news = $(this);
		this_news.css('opacity', 1);
	};
	jQuery.fn.rollout_but_1 = function() {
		var this_news = $(this);
		this_news.css('opacity', alpha);
	};
	
	
	jQuery.fn.view_list = function() {
		$('#but_view_list').attr('class','but_1_selected');
		$('#but_view_thumb').attr('class','but_1');
		$('#view_thumb').hide();
		$('#view_list').show();
		jQuery.fn.setup_alpha();
		
		$('#but_view_list img').load("incl/backend.php", {func:'change_project_view', status:"list"},function() {jQuery.fn.resize_bg();});		
	}
	jQuery.fn.view_thumb = function() {
		$('#but_view_list').attr('class','but_1');
		$('#but_view_thumb').attr('class','but_1_selected');
		$('#view_list').hide();
		$('#view_thumb').show();
		jQuery.fn.setup_alpha();
		
		$('#but_view_list img').load("incl/backend.php", {func:'change_project_view', status:"thumb"},function() {jQuery.fn.resize_bg();});		
	}
	jQuery.fn.view_map = function() {
		//alert('test'+$(this).parent().parent().parent().attr('id')+"|"+$(this).attr('id').replace('but_view_map_',''));
		var project_id = $(this).attr('id').replace('but_view_map_','');
		$('.but_view_map').parent().hide();
		$('.but_view_info').parent().show();
		jQuery.fn.show_loader('#project_content_'+project_id,null);
		$(this).parent().parent().parent().parent().attr('class','');
		$('#project_content_'+project_id).load("incl/backend.php", {func:'project_view_map', project_id:project_id,page_id:page_id},
			function() {
				jQuery.fn.hide_loader('#project_content_'+project_id);
			}
		);
		
	}
	jQuery.fn.view_info = function() {
		var project_id = $(this).attr('id').replace('but_view_info_','');
			$('.but_view_map').parent().show();
			$('.but_view_info').parent().hide();
		jQuery.fn.show_loader('#project_content_'+project_id,null);
		$(this).parent().parent().parent().parent().attr('class','');
		$('#project_content_'+project_id).load("incl/backend.php", {func:'project_view_info', project_id:project_id,page_id:page_id},
			function() {
				jQuery.fn.hide_loader('#project_content_'+project_id);
			}
		);
	}
	
	
	jQuery.fn.event_thumb_next = function() {
		jQuery.fn.setup_event_thumb(1);
	}
	jQuery.fn.event_thumb_prev = function() {
		jQuery.fn.setup_event_thumb(-1);
	}
	
	jQuery.fn.setup_event_thumb = function(page_diff) {
		var this_page = Number($('#event_thumb_no').val());
		var total_page = Number($('#event_thumb_total').val());
		var my_page = 0;
		var max_thumb = 4;
		if (page_diff) {
			my_page = (this_page)+(page_diff);
			if (my_page<=0) {
				my_page = 0;
			}
			if (my_page>=total_page-1-max_thumb) {
				my_page=total_page-1-max_thumb;
			}
			$('#event_thumb_no').val(my_page);
		}
		
		$('#event_thumb_next').show();
		$('#event_thumb_prev').show();
		if (my_page == 0) {
			$('#event_thumb_prev').hide();
		}
		if (my_page>=total_page-1-max_thumb) {
			$('#event_thumb_next').hide();
		}
		if (total_page<max_thumb) {
			$('#event_thumb_next').hide();
		}
		
		var i=0;
		while ($('#event_thumb #img_'+i).length>0) {
			if (i>=my_page && i<my_page+max_thumb) {
				$('#event_thumb #img_'+i).show();
			} else {
				$('#event_thumb #img_'+i).hide();
			}
			i++;
		}
		
		
	}
	
	
	jQuery.fn.news_thumb_next = function() {
		jQuery.fn.setup_news_thumb(1);
	}
	jQuery.fn.news_thumb_prev = function() {
		jQuery.fn.setup_news_thumb(-1);
	}
	
	jQuery.fn.setup_news_thumb = function(page_diff) {
		var this_page = Number($('#news_thumb_no').val());
		var total_page = Number($('#news_thumb_total').val());
		var my_page = 0;
		var max_page = 1;
		if (page_diff) {
			my_page = (this_page)+(page_diff);
			if (my_page<=0) {
				my_page = 0;
			}
			if (my_page>=total_page-1-max_page) {
				my_page=total_page-1-max_page;
			}
			$('#news_thumb_no').val(my_page);
		}
		
		$('#news_thumb_next').show();
		$('#news_thumb_prev').show();
		if (my_page == 0) {
			$('#news_thumb_prev').hide();
		}
		if (my_page>=total_page-1-max_page) {
			$('#news_thumb_next').hide();
		}
		if (total_page<max_page) {
			$('#news_thumb_next').hide();
		}
		
		var i=0;
		while ($('#news_thumb #img_'+i).length>0) {
			if (i>=my_page && i<my_page+max_page) {
				$('#news_thumb #img_'+i).show();
			} else {
				$('#news_thumb #img_'+i).hide();
			}
			i++;
		}
		
		
	}
	
	
	
	jQuery.fn.setup_alpha = function() {
		$('#overlay .bg').css('opacity', 0.8);
		$('.overlay_info_box .bg').css('opacity', 0.8);
		$('#content .bg').css('opacity', alpha);
		$('#content_bg').css('opacity', 0.4);
		$('.news_col .title').css('opacity', alpha);
		$('.news_col .title_a div').css('opacity', alpha);
		$('.news_col .selected .title_a div').css('opacity', 1);
		$('.news_list li').not('.selected').css('opacity', alpha);
		//$('#fund_submenu a').not('.selected').css('opacity', alpha);
		$('.but_0').css('opacity', alpha);
		$('.but_1').css('opacity', alpha);
		$('.but_0_selected,.but_1_selected').css('opacity', 1);
		$('.but_1_disabled').css('opacity', 0.2);
		$('.but_0_disabled').css('opacity', alpha);
		$('.but_1_r').css('opacity', alpha);
		$('.but_1_l').css('opacity', alpha);
		$('.alpha').css('opacity', alpha);
		$('.textbox_2 .bg').css('opacity', alpha);
		$('.overlay_page_but').css('opacity', alpha);
		$('.overlay_arrow_but').css('opacity', alpha);
		$('.overlay_but').css('opacity', alpha);
		//$('.calendar_event_cell_populated .grid').css('opacity', alpha);
		$('.calendar_event_cell .grid').css('opacity', alpha*0.75);
		$('.but_play').css('opacity', alpha/2);
		
		
		$('.overlay_but').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.overlay_but').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.overlay_page_but').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.overlay_page_but').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.overlay_arrow_but').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.overlay_arrow_but').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_1').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1_r').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_1_r').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1_l').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_1_l').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_0').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_0').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1_selected').unbind("mouseleave");
		$('.but_1_selected').unbind("mouseenter");
	}
	

	
	function slideshow_onBefore() { 
		var my_id = this.id.replace("img_","title_");
		$('#'+my_id).parent().parent().parent().parent().find("div").css('opacity', alpha);
		$('#'+my_id).parent().parent().parent().parent().find("object").removeClass();
		$('#'+my_id).css('opacity', 1);
		$('#'+my_id).parent().addClass('selected');
	}
	
	
		$(document).mousemove(function(e){
		  mouseX = e.pageX;
		  mouseY = e.pageY;
		}); 
   
	$(window).bind("resize", jQuery.fn.resize_bg);
	$(window).bind("scroll",jQuery.fn.move_panel);
	//alert(template);
	if (template!="section_1" && template!="section_2" && template!="section_3" && template!="home") {
		//jQuery.fn.close_panel_up();
		jQuery.fn.close_panel_dn();
	} else {
		//jQuery.fn.open_panel_up();
		if (b_version=='IE6') {
			jQuery.fn.close_panel_dn();
		} else {
			jQuery.fn.open_panel_dn();
		}
	}
	
	
	$('#location_list .thumb_but').bind("mouseenter",jQuery.fn.thumb_rollover);
	$('#location_list .thumb_but').bind("mouseleave",jQuery.fn.thumb_rollout);
	$('#location_list .thumb_but').bind("click",jQuery.fn.thumb_click);
	
	
	$('#img_bg').bind("click",jQuery.fn.thumb_bg_click);
	
	$('#submit_location_keyword').bind("click",jQuery.fn.search_location_keyword);
	$('#location_page a').bind("click",jQuery.fn.change_page);
	
	$('.slideshow').cycle({fx:'fade',startingSlide: 0,timeout: slideshow_speed,cleartype:false, cleartypeNoBg:true});	
	
	
	$('.calendar_arrow').bind("click",jQuery.fn.change_calendar);
	$('#calendar_event_but .but_1').bind("click",jQuery.fn.change_event_calendar);
	
	$('#panel_up_close').bind("click",jQuery.fn.close_panel_up);
	$('#panel_up_open').bind("click",jQuery.fn.open_panel_up);
	
	$('#panel_dn_close').bind("click",jQuery.fn.close_panel_dn);
	$('#panel_dn_open').bind("click",jQuery.fn.open_panel_dn);
	
	
	$('.news_col .body').css('display', 'block').hide();
	$('.news_col .title_long').css('display', 'block').hide();
	$('.news_col .title').bind("click",jQuery.fn.setup_news_col);
	$('.news_col .title_long').bind("click",jQuery.fn.setup_news_col);
	$('.news_col .title').bind("mouseenter",jQuery.fn.rollover_news_col);
	$('.news_col .title').bind("mouseleave",jQuery.fn.rollout_news_col);
	$('.news_col .title_a div').bind("mouseenter",jQuery.fn.rollover_news_col);
	$('.news_col .title_a div').bind("mouseleave",jQuery.fn.rollout_news_col);
	
	
	$('.news_col .selected').find(".body").show();
	$('.news_col .selected').find(".title_long").show();
	$('.news_col .selected').find(".title").hide();
	$('.news_col .selected').find(".title").css('opacity', 1);
	
	
	$('.news_list li').bind("mouseenter",jQuery.fn.rollover_news_list);
	$('.news_list li').bind("mouseleave",jQuery.fn.rollout_news_list);
	$('.news_list li').bind("click",jQuery.fn.setup_news_list);
	//$('#news_page div').bind("click",jQuery.fn.setup_news_list);
	
	$('.table_0 tr').bind("mouseenter",jQuery.fn.rollover_table_0);
	$('.table_0 tr').bind("mouseleave",jQuery.fn.rollout_table_0);
	$('.table_0 tr').bind("click",jQuery.fn.click_table_0);

	$('#fund_submenu .alpha').bind("mouseenter",jQuery.fn.rollover_news_list);
	$('#fund_submenu .alpha').bind("mouseleave",jQuery.fn.rollout_news_list);

	$('#people_chart .alpha').bind("mouseenter",jQuery.fn.rollover_news_list);
	$('#people_chart .alpha').bind("mouseleave",jQuery.fn.rollout_news_list);
	
	//$('.news_slideshow').cycle({timeout: 0, fx:'fade',startingSlide: 0});
	$('.news_slideshow').cycle({fx:'fade',timeout: slideshow_speed,startingSlide: 0,before:slideshow_onBefore});
	$('.project_slideshow').cycle({fx:'fade',timeout: slideshow_speed,startingSlide: 0,before:slideshow_onBefore});
	
	$('#but_view_list').bind("click",jQuery.fn.view_list);
	$('#but_view_thumb').bind("click",jQuery.fn.view_thumb);
	$('.but_view_map').bind("click",jQuery.fn.view_map);
	$('.but_view_info').bind("click",jQuery.fn.view_info);
	
	$('#event_thumb .but_0').eq(0).bind("click",jQuery.fn.event_thumb_prev);
	$('#event_thumb .but_0').eq(1).bind("click",jQuery.fn.event_thumb_next);
	$('#event_thumb .row_cell').bind("click",jQuery.fn.event_thumb_click);
	
	$('#news_thumb .but_0').eq(0).bind("click",jQuery.fn.news_thumb_prev);
	$('#news_thumb .but_0').eq(1).bind("click",jQuery.fn.news_thumb_next);
	$('#news_thumb .row_cell').bind("click",jQuery.fn.news_thumb_click);
	
	$('#project_thumb .row_cell').bind("click",jQuery.fn.project_thumb_click);
	
	
	//jQuery.fn.initial_news_col($('#fund_list .news_col').find('.title').eq(0));
	
	jQuery.fn.initial_news_col($('#fund_list .news_col').find('.title'));
	//jQuery.fn.initial_news_col($('#fund_list .news_col .test').find('.title'));
	jQuery.fn.initial_news_col($('#textpage_list .news_col').find('.title').eq(0));
	jQuery.fn.initial_news_col($('.news_col').find('#list_selected .title_long').eq(0));
	
	jQuery.fn.setup_event_thumb();
	jQuery.fn.setup_news_thumb();
	jQuery.fn.move_panel();	
	jQuery.fn.resize_bg();
	jQuery.fn.setup_alpha();
	jQuery.fn.calendar_cell_populated();
	
	setup_popup();
	//setup_bg();
	setup_calendar();
	setup_panel();
	setup_quick_search();
	setup_bg_lbl();
	setup_row_box();
	setup_menu();
	open_vid();
});
function setup_row_box() {
	$('.splash_row').each(function() {
								var w0 = 0;
								$('>div',this).not('.clear').each(function(){w0+=$(this).width()+parseInt($(this).css('margin-left'))+parseInt($(this).css('margin-right'));});
								$(this).width(w0);
								});
}
function open_vid() {
	var hash = window.location.hash.replace("#", "");
	if (hash.indexOf('vid_')>-1) {
		$('#'+hash).hide().fadeIn(100,function(){setup_vodcast(hash)});
	} else if (hash.substr(0,1)=="c") {		
		jQuery.fn.initial_news_col($('#'+(hash)).find('.title'));
	}
}
function setup_video(id) {
	if (FlashDetect.versionAtLeast(10)) {
		if ($('.vid').length>0) {
			var obj_parent = $('.vid').parent();
			$('.vid').remove();
			obj_parent.html(temp_html);
			setup_panel ();
		}
		temp_html = $('#'+id).parent().html();
		$('#'+id+' .textbox_0').appendTo($('#'+id).parent());
		var w0 = $('#'+id+' img').css('width');
		var h0 = $('#'+id+' img').css('height');
		var mov_path = $('#'+id).attr('href');
		var img_path = $('#'+id+' img').attr('src');	
		
		swfobject.embedSWF('videoplayer.swf', id,  w0, h0, '10', 
		//'expressinstall.swf', {img_path:img_path,mov_path:mov_path,auto_start:true}, {allowscriptaccess: 'always', bgcolor: '#000000', menu: 'false', wmode: 'opaque',allowFullScreen:'true'}, {id: id},null);
		'expressinstall.swf', {img_path:img_path,mov_path:mov_path,auto_start:true}, {allowscriptaccess: 'always', bgcolor: '#000000', menu: 'false', wmode: 'opaque',allowFullScreen:'true'}, {id: id},function() {
		});
		$('#'+id).addClass('vid');
		
		$('.slideshow').cycle('stop');	
		if (!iphone) {
			return false;
		}
	} else {
		/*
		if ($('.vid').length>0) {
			var obj_parent = $('.vid').parent();
			$('.vid').remove();
			obj_parent.html(temp_html);
			setup_panel ();
		}
		temp_html = $('#'+id).parent().html();
		$('#'+id+' .textbox_0').appendTo($('#'+id).parent());
		var w0 = $('#'+id+' img').css('width');
		var h0 = $('#'+id+' img').css('height');
		var mov_path = $('#'+id).attr('href');
		var img_path = $('#'+id+' img').attr('src');	
		$('#'+id).remove();
		$('#'+id).parent().append('<div style="position:absolute;display:block;top:0px;left:0px;z-index:10;" class="vid" id="'+id+'"><embed align="middle" src="'+mov_path+'" controller="true" autoplay="true" type="video/quicktime" cache="true" loop="false" scale="ASPECT" width="'+w0+'" height="'+h0+'" BGCOLOR="BLACK" /></div>');
		
		$('.slideshow').cycle('stop');	
		
		*/
		
		return true;
	}
}
function setup_vodcast(id) {
	if (FlashDetect.versionAtLeast(10)) {
		if ($('.vid').length>0) {
			$('.vid').html(temp_html);
			$('.vid').removeClass();
			setup_panel ();
		}
		temp_html = $('#'+id).parent().html();
		$('#'+id+' .textbox_0').appendTo($('#'+id).parent());
		var w0 = $('#'+id+' img').css('max-width');
		var h0 = $('#'+id+' img').css('max-height');
		var mov_path = $('#'+id).attr('href');
		var img_path = $('#'+id+' img').attr('src');
		$('#'+id).parent().addClass('vid');
		swfobject.embedSWF('videoplayer.swf', id,  w0, h0, '10', 
		'expressinstall.swf', {img_path:img_path,mov_path:mov_path,auto_start:true,showall:true}, {allowscriptaccess: 'always', bgcolor: '#000000', menu: 'false', wmode: 'opaque',allowFullScreen:'true'}, {id: id},null);
		//$('#'+id).removeClass().addClass('vid');
		
		$('.but_play').parent().bind("mouseenter",function() {
													  $('.but_play',this).css('opacity',alpha/2);
													 $('.but_play',this).animate({opacity:1},200);
													});
		$('.but_play').parent().bind("mouseleave",function() {
													  $('.but_play',this).css('opacity',alpha/2);
													});
		window.location.hash = '#'+id;
		return false;
	} else {
		return true;
	}
}
function setup_bg_lbl() {
	if (b_version!="IE6") {
	$('#canvas').append('<div class="bg_lbl">Click to View Location Info</div>');
	bg_timer = setInterval(setup_bg_lbl_timer, 10);
	$('#bg').bind("mouseover",function() {
										$('.bg_lbl').show();
										setup_bg_lbl_timer ();
										});
	$('#bg').bind("mouseout",function() {
										$('.bg_lbl').hide();
										});
	
	$('#bg').bind("click",function() {
											$(this).thumb_bg_click();
												});
	}
}
function setup_bg_lbl_timer () {
	if ($('.bg_lbl').css('display')=='block') {
		if (mouseX+2+$('.bg_lbl').width()>$(window).width()-5+window.scrollX) {
			$('.bg_lbl').css('left',$(window).width()-$('.bg_lbl').width()-5+window.scrollX);
		} else {
			$('.bg_lbl').css('left',mouseX+2);
		}
		$('.bg_lbl').css('top',mouseY-$('.bg_lbl').height()-4);
	}
}
function setup_quick_search() {
	if (!is_ie) {
	$('#but_search').bind("mouseenter",function() {
												if ($('#search_quick',this).length==0) {
												$(this).append('<div id="search_quick"><form id="form_search_keyword" name="form_search_keyword" enctype="multipart/form-data" method="post" action="index.php?page_id=103"><input type="hidden" id="form_id" name="form_id" value="search_keyword"><input type="hidden" id="search_section" name="search_section" value="0"><input type="text" id="search_keyword" name="search_keyword" value="" /><a href="#" onclick="document.forms[\'form_search_keyword\'].submit();return false;" target="_self" title="Advanced Search" ><img src="images/icontrans_search.gif" alt="Search" border="0" /></a></form><div id="search_quick_result"></div></div>');
												$('#search_keyword',this).focus();
												$('.search_lbl',this).hide();
												setup_popup();
	
												$('#search_keyword',this).keyup(function() {quick_search();});
	
	
												} else {
													$('#search_quick_result').show();
												}
												$('#mainmenu_container').css('z-index',1);
												$('#content').css('z-index',2);
												});
	$('#but_search').bind("mouseleave",function() {
												if ( $('#search_keyword',this).val().trim()=="") {
												 $('#search_quick').remove();
												 $('.search_lbl',this).show();
												}
												$('#search_keyword',this).blur();
												$('#search_quick_result').hide();												
												$('#mainmenu_container').css('z-index',2);									
												$('#content').css('z-index',1);
												});
	}
} 
function quick_search () {
	var my_val = $('#but_search #search_keyword').val();
	$('#search_quick_result').load("incl/backend.php", {func:'quick_search', search_keyword:my_val});	
}
function setup_panel () {
	$('.panel_cell a').bind("mouseenter",function() {
												  $('.textbox_4').css('opacity',0);
												 $('.textbox_4').animate({opacity:1},200);
													$(this).parent().parent().cycle('pause');
												});
	$('.panel_cell a').bind("mouseleave",function() {
													$(this).parent().parent().cycle('resume');
												  $('.but_play',this).css('opacity',alpha/2);
												});
	
	$('.but_play').parent().bind("mouseenter",function() {
												  $('.but_play',this).css('opacity',alpha/2);
												 $('.but_play',this).animate({opacity:1},200);
												});
	$('.but_play').parent().bind("mouseleave",function() {
												  $('.but_play',this).css('opacity',alpha/2);
												});
}
function setup_calendar () {
	var d = new Date();
	var tDate = d.getDate()+'_'+(d.getMonth()+1)+'_'+d.getFullYear();
	jQuery.fn.show_loader('#calendar','loader_1');
	var page_id = $("#page_id").val();
	$('#calendar').load("incl/backend.php", {func:'change_calendar', tDate:tDate, page_id:page_id},function() {jQuery.fn.hide_loader('#calendar');$('.calendar_arrow').bind("click",jQuery.fn.change_calendar);jQuery.fn.calendar_cell_populated();});	
}
function setup_bg() {
	$("#bg_img").css('opacity',0);
	$("#bg_img").load(function() {
		$("#bg_img").animate({opacity:1},3000);
	  })	
}
function setup_popup() {
	$('a[title!=""]').each(function() {
									$(this).attr('rel',$(this).attr('title'));
									$(this).attr('title','');
									});
	$('a[rel!=""]').bind("mouseenter",function() {
												 var my_title = $(this).attr('rel');
												 var my_parent = $(this).parent();
												 $('.popup').remove();
												 my_parent.append('<div class="popup">'+my_title+'</div>');
												 var my_h =  $('.popup',my_parent).height();
												 var my_margintop =  parseInt(my_parent.css('margin-top'));
												 $('.popup',my_parent).css('margin-top',-my_h-my_margintop);
												 if ($(this).attr('id')=="panel_dn_close" || $(this).attr('id')=="panel_dn_open") {
													 $('.popup',my_parent).css('left', $('#panel_dn').width());
												 }
												});
	$('a[rel!=""]').bind("mouseleave",function() {
												 $('.popup').remove();
												});
}
function setup_menu() {
	$('#menuitem > ul').show();
	$('#content').show();;
	if (b_version!="IE6") {
		var menu_h_max = 400;
		var menu_h = 0;
		var menu_arr = Array();
		var ul_arr = Array();
		var ul_no = 0;
		var menu_class = "";
		
		$('#menuitem,#menuitem a').bind("mouseenter",function() {
							$('#menuitem').css('z-index',9999);
							$('#panel').css('z-index',9998);
							$('#mainmenu_container').css('z-index',2);
							$('#content').css('z-index',1);
													});
		//alert($('ul.mainmenu > li > ul').length);
		//$('#menuitem > ul > li').bind("mouseenter",function(){$('.panel').hide();$('.panel',this).hide().fadeIn(100)});
		//$('#menuitem > ul > li').bind("mouseleave",function(){$('.panel',this).hide()});
		
											// var output = "";
											$('body').append('<ul id="dummy_menu"></ul>');
		$('ul.mainmenu > li > .panel').each(function () {
											  menu_arr = Array();
											 $('#dummy_menu').html('');
											 ul_arr = Array();
											 ul_no = 0;
											  menu_h = $(this).height();
											  ul_arr[ul_no] = "";
											 // alert(menu_h);
											 //alert($(' > li ',this).length);
											 $(this).css('display','block');
											  $(' > ul',this).children().each(function(){
																					  $(this).css('height',$(this).height());
																				 $('#dummy_menu').append($(this));
																				// menu_arr.push($(this));
																				 });
											  $(' > ul ',this).html('');
											 //alert( menu_arr[0].get(0));
											 // for (var i=0;i<menu_arr.length;i++) {
												//alert($('#dummy_menu').children().length); 
											 // for (var i=0;i<$('#dummy_menu').children().length;i++) {
											  for (var i=0;i<$('#dummy_menu').children().length;i++) {
												  var child = $('#dummy_menu').children().eq(i);
												  var hidden = "";
												  if (child.is(':hidden')) {
													  hidden = ' style="display:none;" ';
												  }
												  //var child = menu_arr[i];
												// $(this).css('display','block');
												// output+=" | "+$(this).height();
												 //output+=" - "+menu_arr[i].html();
												 //$(' > ul ',this).append(menu_arr[i]);
												// $(' > ul ',this).append(menu_arr[i]);
												
												var node_id =child.attr('id');
												var node = '<li id="'+node_id+'" '+hidden+'>'+child.html()+'</li>';
												var node_height = parseInt(child.css('height'));
												//output+=" - "+($(this).height()+node_height);
												if (menu_h+node_height>menu_h_max) {
													$(this).append('<ul></ul>');
													ul_no++;
													$(this).css('width',(ul_no*180+10));
													$(' > ul ',this).eq(ul_no).append(node);
													menu_h = node_height;
												} else {
													$(' > ul ',this).eq(ul_no).append(node);
													menu_h+=node_height;
												}
												  
												/*
												  if ($(this).height()>menu_h_max) {
													ul_no++;
													$(' > ul ',this).html('');
													//$(' > ul ',this).append($('#dummy_menu').children(i));
													//alert($('#dummy_menu').children(i).html());
													ul_arr[ul_no] = "";
													ul_arr[ul_no]+=node;
													 //ul_arr[ul_no] += menu_arr[i].clone().wrapAll("<div><div/>").parent().html();
												  } else {
													ul_arr[ul_no]+=node;
													 //ul_arr[ul_no] += menu_arr[i].clone().wrapAll("<div><div/>").parent().html();
												  }
												  */
											  }
											 $(this).css('display','');
											  /*
											  $(this).html('');
											  //alert( $(this).html());
											  var panel_w = 0;
											  for (var i=0;i<ul_arr.length;i++) {
												 if (ul_arr[i]!='undefined') {
													 //alert('test');
													 $(this).append('<ul>'+(ul_arr[i])+'</ul>');
													 panel_w += $(this).width();
												 }
											  }
											  if (panel_w!=0) {
												  $(this).css('width',panel_w+10);
											  }
											  */
											  
											  });
		$('#dummy_menu').remove();
		//$('#footer').html(output);
		
			var menu_elem = $('#menu_'+menu_id);
			if (menu_elem.length>0) {
				while (menu_elem.attr('class')!='mainmenu') {
					if (menu_elem[0].nodeName.toLowerCase()=="li") {
						menu_elem.removeClass().addClass('link_on');
					}
					menu_elem = menu_elem.parent();
				}
			}
	}
}
	
function print_page() {	
	//$(".news_col .body").show();
	//$(".news_col .title_long").show();
	//$(".news_col .title").hide();
	//$(".news_col .title").css('opacity', 1);
	//$(".news_col .status").val('y');
	print();
}

function validate_form() {
	if ($("#form_id")) {
		switch($("#form_id").val()) {
			case 'contact_general':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_fund':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_media':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_subscribe':
				var input_arr = new Array('email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_subscribe1':
				var input_arr = new Array('fname','lname','email','subscribe','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_unsubscribe':
				var input_arr = new Array('email');
				return validate_input(input_arr);
			break;
			case 'contact_unsubscribe1':
				var input_arr = new Array('email');
				return validate_input(input_arr);
			break;
			case 'contact_property':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_feedback':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'search_keyword':
				var input_arr = new Array('search_keyword');
				return validate_input(input_arr);
			break;
			case 'location_search_quick':
				var input_arr = new Array('keyword');
				return validate_input(input_arr);
			break;
		}
		
	}
	return false;	
}

function validate_input(input_arr) {
	for (i=0; i<input_arr.length; i++) {
		switch (input_arr[i]) {
			case 'fname':			
				if (!validate_textbox("#fname",'Please fill in First Name')) {
					return false;
				}
			break;
			case 'lname':			
				if (!validate_textbox("#lname",'Please fill in Last Name')) {
					return false;
				}
			break;
			case 'email':			
				if (!validate_email("#email",'Invalid Email')) {
					return false;
				}
			break;
			case 'privacy':			
				if (!validate_checkbox("#privacy",'Please agree with the Privacy Policy')) {
					return false;
				}
			break;
			case 'subscribe':			
				if (!validate_checkbox("#subscribe",'Please agree to subscribe the newsletter')) {
					return false;
				}
			break;
			case 'search_keyword':			
				if (!validate_textbox("#search_keyword",'Please enter a keyword',3)) {
					return false;
				}
			break;
			case 'keyword':			
				if (!validate_textbox("#keyword",'Please enter a keyword')) {
					return false;
				}
			break;
		}
	}
	return true;
}

function validate_textbox(my_id,msg,my_l) {
	if (my_l&&$(my_id).val().length<=my_l) {
		$(my_id).focus();
		alert('The input at least contains '+my_l+' characters');
		return false;
	}
	if ($(my_id).val()==null||$(my_id).val()=="") {
		$(my_id).focus();
		alert(msg);
		return false;
	}
	return true;
}
function validate_checkbox(my_id,msg) {
	if($(my_id+':checked').size() == 0){
		$(my_id).focus();
		alert(msg);
		return false;
	}
	return true;
}
function validate_email (my_id,msg) {
	var str = $(my_id).val();
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var check= true;
	if (str.indexOf(at)==-1){
		check = false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		check = false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		check = false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		check = false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		check = false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		check = false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		check = false;
	 }
	 if (check) {
		return true;
	 } else {
		$(my_id).focus();
		 alert (msg);
		return false;	
	 }
				
}
function redirect(url) {
	window.location=url;
}
