a=function(module,mode){if(mode==null||mode!=true)var mode=false;if(window.XMLHttpRequest)xmlhttp=new XMLHttpRequest;else if(window.ActiveXObject)xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open('POST',module,mode);xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){var r=xmlhttp.responseText;}}};xmlhttp.send('ajax=1'); return xmlhttp.responseText;};
loadXML=function(txt){try{xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(txt);return(xmlDoc);}catch(e){try{parser=new DOMParser();xmlDoc=parser.parseFromString(txt,"text/xml");return(xmlDoc);}catch(e){}}return(null);};
in_array=function(needle,haystack){var found=false,key;for(key in haystack){if(haystack[key]==needle){found=true;break;}}return found;};
is_array=function(value){var key='';if(!value)return false;if(typeof value==='object'){if(value.hasOwnProperty){for(key in value){if(false===value.hasOwnProperty(key)){return false;}}return true;} return false;}};
urlencode=function(str){string=encodeURIComponent(str).replace(/~/g,'%7E');return string.replace(/%20/g,'+');};
urldecode=function(str){return decodeURIComponent(str.replace(/\+/g, '%20'))};

var globalActiveSlide=0;
var stop=false;
var w=727;
var ns=150;

function navigate(li,speed){
	var wSum=0;
	var num=0;
	$('#objects>li').each(function(){
		if($(li).attr('id')==$(this).attr('id')){return false;}
		num++;
		wSum+=$(this).width();
	});
	globalActiveSlide=num;
	$('#center').animate({'scrollLeft':wSum}, speed);
	stop=false;
}
$(document).ready(function(){
	$('#rightSpace').width($(document).width()-733);
	$('.target').attr({'target':'_blank'});
	if(location.hash!=''){
		$('#infofield').html(a(String(location.hash).replace('#',''),0));
	}
	
	$('.item').each(function(){
		var id=$(this.parentNode).attr('id');
		if(id!=undefined){
			var g=$('#'+id+'>.item>.preview').get(0);
			if(g){
				$($('#'+id+'>.item>.preview').get(1)).css({'left':$(g).css('left'),'top':$(g).css('top')});
				$($('#'+id+'>.item>.content').get(0)).css({'left':$(g).css('left'),'top':$(g).css('top')});			
			}
		}
	});
///////////////////////////////1

	var tm;
	$('.item').hover(function(){
			var o=$(this.parentNode).offset();
			if(!o.left || o.left==315){
				var id=$(this.parentNode).attr('id');
				tm=setTimeout(function(){$($('.item>.preview').get(1)).fadeOut()},1)
				$($('#'+id+'>.item>.preview').get(1)).fadeOut()
			}
		},function(){
			var id=$(this.parentNode).attr('id');
			$($('#'+id+'>.item>.preview').get(1)).fadeIn();
			clearTimeout(tm);
		});

///////////////////////////////1
	var w=0;
	$('#objects>li').each(function(){w+=$(this).width()});
	$('#objects').width(w);
	
	$('.middle').height($(document).height()-32);
	$('.fade').height($('.middle').height()-17);
///////////////////////////////2
	
	var isOpera=/Opera/.test(navigator.userAgent);
	$('.item').click(function(){
		if($(this.parentNode).attr('id')==$($('#objects>li').get(globalActiveSlide)).attr('id')){
			var next=$($('#objects>li').get(globalActiveSlide+1)).attr('id');
			if(next!=undefined){navigate($('#'+next),180)}
		}else{
			navigate($(this.parentNode),180);
		}
	});
	/*
	$(document).mousewheel(function(objEvent, intDelta){
		if(stop) return;
		stop=true;
		if(isOpera){
			if(intDelta>0 && $('#objects>li').size()>(globalActiveSlide+1)){
				globalActiveSlide++;
			} else if(intDelta<0 && globalActiveSlide>0) {
				globalActiveSlide--;
			}		
		}else{
			if(intDelta>0 && globalActiveSlide>0){
				globalActiveSlide--;
			} else if(intDelta<0 && $('#objects>li').size()>(globalActiveSlide+1)) {
				globalActiveSlide++;
			}
		}
		if(globalActiveSlide>=0 && $('#objects>li').size()>=globalActiveSlide){
			navigate($('#objects>li').get(globalActiveSlide),ns);
		}
	});
	*/
///////////////////////////////2
	$('.navigate-home').click(function(event){
		event.preventDefault();
		globalActiveSlide=0;
		navigate($('#objects>li').get(globalActiveSlide),ns*($('#objects>li').size()*0.5));
	});

});
