try{
	
$(function(){

	var imgLoader = new Image();// preload image
	imgLoader.src = waiting_gif_url;
	
	$.justWaiting = {
		loading_time: 0,
		show: function(){
			this.loading_time++;
			if( this.loading_time==1 )
			{
				if (typeof document.body.style.maxHeight === "undefined") 
				{//if IE 6
					$("body","html").css({height: "100%", width: "100%"});
					$("html").css("overflow","hidden");
					if (document.getElementById("TB_HideSelect") === null) 
					{//iframe to hide select elements in ie6
						$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
					}
				}
				else
				{//all others
					if(document.getElementById("TB_overlay") === null)
					{
						$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
					}
				}
				
				var userAgent = navigator.userAgent.toLowerCase();
				if( userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1 )
				{
					$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
				}
				else
				{
					$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
				}
				
				$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
				$('#TB_load').show();//show loader
			}
		},
		hide: function(){
			if( this.loading_time>0 )
			{
				this.loading_time--;
			}
			if( this.loading_time==0 )
			{
				$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
				$("#TB_load").remove();
				if (typeof document.body.style.maxHeight == "undefined") 
				{//if IE 6
					$("body","html").css({height: "auto", width: "auto"});
					$("html").css("overflow","");
				}
			}
		}
	};
	
	jQuery.easing.def = 'easeInOutQuad';
	var time = 'normal';
	var $loading = $.justWaiting;	
		

	//for the news title link click effect
	$('a.news,#ajax_content .navigation a').live('click',function(){
		var $this = $(this);
		
		//hide project
		$('#project_c .entry[is_show="yes"]').parent().find('h2 a').click();
		
		$('#ajax_content').slideUp(time,function(){
			$loading.show();
			var current_url = $this.attr('href');
			if( 'ajax' != current_url.substring(current_url.length-4) )
			{
				current_url = current_url + '?from=ajax';
			}
			$.get( current_url, function( data ){
				$('#ajax_content').slideUp(time,function(){
					$('#ajax_content').html( data ).slideDown(time,function(){
						change_url( 'ne', $this.attr('href') );
						$loading.hide();
						hide_promotion();
					});
				});
			});
		});
		 
		return false;
	});
	//for the page title link click effect
	$('li.page_item a').live('click',function(){
		var $this = $(this);
		
		//hide project
		$('#project_c .entry[is_show="yes"]').parent().find('h2 a').click();
		
		$('#ajax_content').slideUp(time,function(){
			$loading.show();
			var current_url = $this.attr('href');
			if( 'ajax' != current_url.substring(current_url.length-4) )
			{
				current_url = current_url + '?from=ajax';
			}
			$.get( current_url, function( data ){
				$('#ajax_content').slideUp(time,function(){
					$('#ajax_content').html( data ).slideDown(time,function(){
						change_url( 'pe', $this.attr('href') );
						$loading.hide();
						hide_promotion();
					});
				});
			});
		});
		 
		return false;
	});
	
	// for the project title link click effect
	$('.post-content h2 a').live('click',function(){
		var $post_c = $(this).parent().parent();
		var $this_post = $('.entry', $post_c);
		var $this = $(this);
		
		if( $this_post.attr('is_show')!='yes' )
		{
			$('#ajax_content').slideUp();
			var is_loaded = $post_c.find('.entry').attr('is_loaded') ;
			if( is_loaded!='yes' )
			{
				$loading.show();
				var current_url = $this.attr('href');
				if( 'ajax' != current_url.substring(current_url.length-4) )
				{
					current_url = current_url + '?from=ajax';
				}
				$.get( current_url , function( data ){
					$loading.hide();
					$('.post-content .entry[is_show="yes"]').attr('is_show','').slideUp();
					$this_post.html( data ).attr('is_loaded','yes').slideDown(time,function(){
						change_url( 'pe', $this.attr('href') );
						$this_post.attr('is_show','yes');
						hide_promotion();
					});
				});
			}
			else
			{
				$('.post-content .entry[is_show="yes"]').attr('is_show','').slideUp();
				$this_post.slideDown(time, function(){
					change_url( 'pe', $this.attr('href') );
					$(this).attr('is_show','yes');
					hide_promotion();
				});
			}
		}
		else
		{
			$this_post.attr('is_show','').slideUp(time,function(){
				change_url( 'pe', '');
				hide_promotion();
			});
		}
		
		return false;
	});
	// for the blog title link click effect
	$('#blog_c h3 a').live('click',function(){
		var $post_c = $(this).parent().parent();
		var $this_post = $('.entry', $post_c);
		var $this = $(this);
		
		if( $this_post.attr('is_show')!='yes' )
		{
			var is_loaded = $post_c.find('.entry').attr('is_loaded') ;
			if( is_loaded!='yes' )
			{
				$loading.show();
				var current_url = $this.attr('href');
				if( 'ajax' != current_url.substring(current_url.length-4) )
				{
					current_url = current_url + '?from=ajax';
				}
				$.get( current_url, function( data ){
					$loading.hide();
					$('#column-right .entry[is_show="yes"]').attr('is_show','').slideUp();
					$('.entry', $post_c).html( data ).attr('is_loaded','yes').slideDown(time,function(){
						change_url( 'be', $this.attr('href') );
						$(this).attr('is_show','yes');
					});
				});
			}
			else
			{
				$('#column-right .entry[is_show="yes"]').attr('is_show','').slideUp();
				$this_post.slideDown(time, function(){
					change_url( 'be', $this.attr('href') );
					$(this).attr('is_show','yes');
				});
			}
			$('#blog_archive').slideUp(time);
		}
		else
		{
			$this_post.attr('is_show','').slideUp(time,function(){
				change_url( 'be', '' );
			});
		}
		
		return false;
	});
	
	
	//for the news pager click effect
	$('.news_c .navigation a').live('click',function(){
		var $c = $('.news_c_wrap');
		var $this = $(this);
		
		$loading.show();
		var current_url = $this.attr('href');
		if( 'ajax' != current_url.substring(current_url.length-4) )
		{
			current_url = current_url + '?from=ajax';
		}
		$.get( current_url , function( data ){
			$loading.hide();
			$('.news_c_wrap').prepend(data);
			change_url( 'np', $this.attr('href') );
			$('.news_c').eq(0).css('top','+530px'); //Julian 210809 - changed from -510 to +530
			$('.news_c').animate({top: '-=530px'},1000,function(){ //Julian 190809 - changed from +=510 to -=530
				$('.news_c').eq(1).remove();
			});
		});
		return false;
	});
	//init .news_c
	// $('.news_c').css('top','0px');
	
	//for the project pager click effect
	$('#project_c .navigation a').live('click',function(){
		var $c = $('#project_c');
		var $this = $(this);
		
		$c.slideUp(time,function(){
			$loading.show();
			var current_url = $this.attr('href');
			if( 'ajax' != current_url.substring(current_url.length-4) )
			{
				current_url = current_url + '?from=ajax';
			}
			$.get( current_url, function( data ){
				$loading.hide();
				$c.html( data ).slideDown(time,function(){
					change_url( 'pp', $this.attr('href') );
				});
			});
		});
		
		return false;
	});
	//for the blog order and newest click effect,and init
	$('.blog_archive_nav .navigation .alignleft a').live('click',function(){
		$('#blog_archive').slideDown(time);
		
		var $post_c = $('#column-right .entry[is_show="yes"]').parent();
		$( 'h3 a', $post_c ).click();
		return false;
	});
	$('.blog_archive_nav .navigation .alignright a').live('click',function(){
		var archive_url = $(this).attr('href');
		var $c = $('#blog_c');
		$loading.show();
		var current_url = archive_url;
		if( 'ajax' != current_url.substring(current_url.length-4) )
		{
			current_url = current_url + '?from=ajax';
		}
		$.get( current_url, function( data ){
			$loading.hide();
			$('.blog_archive_nav .navigation .alignright').toggle();//hide the newest link
			$('#blog_archive').slideUp(time,function(){
				$c.html( data ).slideDown(time,function(){
					change_url( 'ba', archive_url );
				});
			});
		});
		return false;
	});
	//for archive anywhere click ajax
	$('.archive').click(function(){
		var archive_url = $(this).attr('archive_url');
		var $c = $('#blog_c');
		$loading.show();
		var current_url = archive_url;
		if( 'ajax' != current_url.substring(current_url.length-4) )
		{
			current_url = current_url + '?from=ajax';
		}
		$.get( current_url , function( data ){
			$loading.hide();
			$c.html( data ).slideDown(time,function(){
				// $('#blog_archive').toggle(time);
				$('.blog_archive_nav .navigation .alignright').show();
				change_url( 'ba', archive_url );
			});
		});
	});
	
	var init_url_times = 0;
	function hide_promotion()
	{
		if( init_url_times<=0 )
		{
			$('#promotion').slideUp(time);
		}
		init_url_times--;
	}
	
	var url = {
		pe: '',
		ne: '',
		ne: '',//or page_entry,
		
		pp: '',
		pe: '',
		
		bp: '',
		be: ''
	};
	
	var init_url_array = '';
	init_url();
	function change_url(type,to_url)
	{		
		to_url = to_url.substring(siteurl.length);
		url[type] = to_url;
		
		// type=='news_page' ? url['news_entry']='' : '';
		// type=='project_page' ? url['project_entry']='' : '';
		// type=='blog_page' ? url['blog_entry']='' : '';
		
		// type=='page_entry' ? url['news_entry']='' : '';
		// type=='news_entry' ? url['page_entry']='' : '';
		type=='np' ? url['ne']='' : '';
		type=='pp' ? url['pe']='' : '';
		type=='ba' ? url['be']='' : '';
		
		type=='pe' ? url['ne']='' : '';
		type=='ne' ? url['pe']='' : '';
			
		switch( type )
		{
			case 'np':
			case 'pp':
			case 'ba' :
				if( '/' == to_url.substring(to_url.length-1) )
				{
					url[type] = '';
				}
				break;
		}
		var the_hash = '';
		for( var _type in url )
		{
			if( ''!=url[_type] )
			{
				var t_url = url[_type];
				if( '/?from=ajax' == t_url.substring( t_url.length-'/?from=ajax'.length, t_url.length ) )
				{
					url[_type] = t_url.substring( 0,t_url.length-'/?from=ajax'.length );
				}
				the_hash += '|'+_type+'='+url[_type];
			}
		}
		the_hash = the_hash.substring(1);
		window.location.hash = the_hash;
		init_url_one_by_one();
//		Cufon.replace('#column-right h3');
		Cufon.replace('h3');
		Cufon.replace('h4');
		$.scrollTo( 0, 1500 );
	}
	
	function init_url()
	{
		var hash = window.location.hash;
		hash = hash.substring(1);
		hash = hash.split('|');
		init_url_array = hash;
		if( init_url_array=='' )
		{
			init_url_times = 1;
			$('.post-content h2 a').eq(0).click();
			$('#column-right h3 a').eq(0).click();
		}
		else
		{
			init_url_one_by_one();
		}
	}
	
	function init_url_one_by_one()
	{
		var t = init_url_array.shift();
		if( null != t && ''!=t )
		{
			t = t.split('=');
			switch( t[0] )
			{
				case 'np':
					$('.news_c .navigation').append('<a href="'+siteurl+t[1]+'"></a>');
					break;				
				case 'pp':
					$('#project_c .navigation').append('<a href="'+siteurl+t[1]+'"></a>');
					break;
				case 'ba':
					break;
				case 'ne':
				case 'pe':
				case 'be':
					break;
			}
			if( $('a[href*="'+t[1]+'"]').size() == 0 && t[0]!='ba' )
			{
				var url = siteurl + t[1];
				$loading.show();
				var current_url = url;
				if( 'ajax' != current_url.substring(current_url.length-4) )
				{
					current_url = current_url + '?from=ajax';
				}
				$.get( current_url, function( data ){
					var url   = $(data).find('.hide_link').html();
					var title = $(data).find('.hide_title').html();
					var title_attribute = $(data).find('.hide_title_attribute').html();
					var content = $(data).find('.hide_content').html();
					
					// console.log( t[0]);
					switch( t[0] )
					{
						case 'ne':
							var new_html = '<li><span><a href="'+url+'" title="' + title_attribute + '" class="news">' + title + '</a></span>'+ content + '</li><li class="bbar"><span class="btimg"></span></li>';
							$('.news_c ul').eq(0).prepend( new_html );
							break;
						case 'pe':
							var new_html = '<div class="post-content"><h2><a href="'+url+'">'+title+'</a></h2><div class="entry"></div></div>';
							$('#project_c .post-content').eq(0).before( new_html );
							break;
						case 'be':
							var new_html = '<div class="post_blog"><h3 class="right-title"><a href="' + url + '">' + title + '</a></h3><div class="entry"></div></div>';
							$('#blog_c').eq(0).prepend( new_html );
							break;
					}
					
					$('a[href*="'+t[1]+'"]').click();
					$loading.hide();
				});
			}
			else
			{
				if( t[0]=='ba' )
				{
					console.log( $('.archive[archive_url*="'+t[1]+'"]').size() );
					console.log( $('.archive[archive_url*="'+t[1]+'"]').html() );
					$('.archive[archive_url*="'+t[1]+'"]').click();
				}
				else
				{
					$('a[href*="'+t[1]+'"]').click();
				}
				if( init_url_array.length==0 )
				{
					init_url_times = 1;
				}
			}
		}
	}
});

}catch( e ){
		// alert( e );
}