var element_y;
var swiffy;
var cur_groupid;
var group_sortable = new Array();
var lightbox;
var content;

var scrollInterval;

window.addEvent('domready', function(){	
									 
	$(document.body).removeClass('noscript');		

	if($('new_projects') != null){
		var news = new noobSlide({
			box: $('projects-slides'),
			items: $$('li.row'),
			size: 639,
			autoPlay: true,
			mode: 'horizontal',
			handles: $$('#pagination-projects li.page'),
			onWalk: function(currentItem,currentHandle){
				$$(this.handles).removeClass('active');
				$$(currentHandle).addClass('active');
			}
		});
		
		var highlights_handels_more = $$('#pagination-projects li.page');
		news.addHandleButtons(highlights_handels_more);
		//news.walk(0);
	}	
	
	//setFancyTooltip();
	SqueezeBox.initialize();
	SqueezeBox.assign($$('a[rel=boxed][href^=#]'), {
		size: {x: 600, y: 500}
	});
	
	if($('scrollable-container') != null){
		var images = $('scrollable-container').getElements('a');
		images.addEvents({ 
			'mouseenter': function() { this.getElement('span').tween('bottom', 0); return false; },
			'mouseleave': function() { this.getElement('span').tween('bottom', -100); return false; }
		 })
	}

});

window.addEvent('load', function() {
	checkScrollerWidth();
});

window.addEvent('resize', function(){		
	$clear(scrollInterval);
	checkScrollerWidth();
});
//window.onscroll=function(e){$clear(scrollInterval);};

function checkScrollerWidth() {
	if(!$('images')) return;
	var w = 0;
	var images = $$('.image').getChildren();
	var i = images.length-1;
	while(i>=0){w += images[i].getSize()[0].x + 1; i--;}
	
	$('images').setStyle('width', w);
	
	if($('scrollbar') && $('scrollable-container') && $('handle'))
	makeScrollbar( $('scrollable-container'), $('images'), $('scrollbar'), $('handle'), true);
}

function makeScrollbar(content,checkContent,scrollbar,handle,horizontal,ignoreMouse){
	
	if(checkContent.getScrollSize().x < scrollbar.getSize().x) {
		handle.setStyle('display','none');
		return;
	}
	
	handle.setStyle('display','block');

	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	
	if( !(ignoreMouse) ){
		$$(scrollbar).addEvent('mousedown', function(e){$clear(scrollInterval);});
		/*
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			$clear(scrollInterval);
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);			
		});
		*/
	}
	
	scrollInterval = this.autoScroll.periodical(1, slider);
}

var autoScroll = function (){var b=this.step+1; this.set(b);}

function setFancyTooltip() {

	var tips = $$('ul.projects-thumb a');
	console.log(tips)
	if(!tips) return;
	var fadeoutId;
	tips.addEvents({
		'mouseenter': function(){console.log(this.getElement('span')); this.getElement('span').fade('in'); return false;},
		'mouseleave': function(){this.getElement('span.tip').fade('out'); return false;}
	 });
	
}



function email_enkoder(){var i,j,x,y,x=
"x=\"0x=\\\"7836383d283632343736365c2935623d7433383734373336613336363232653" +
"66332643633353532353364376632353630323237323267376333653635336437353339363" +
"13662323633383239323532323261366233333330336836322730323d7930363b5c2536327" +
"262376f6633356b2734333b3036366d692436386c22326e7833363c69693638746133676e6" +
"636353234376d2b6536393b39366d2b7134697b263639637636336564373e7523373728603" +
"635706937312e7136682b2532672575363473653662757636333223363c692232687273356" +
"97d34366b292333692235333b7937366d272436373b6937366f733732286032693d3433303" +
"b6336393c7236382e62326c6563353e677136646834363b6929373b3d3536352977363b666" +
"3376f722632386a33373d4d613631746437682e65363d6965363e287936382e65366c65663" +
"53e677936346821366c6924366b352532693b23363d2d66363a3e39363d6937323b2972326" +
"b7923356b3d7336382e6136336860356172443331742437686a2335393b72326d7d7337393" +
"b\\\"0323;y='2323';fo4363r(i=93630;i<7333x.le8363ngth4373;i+=23262){y3356+" +
"=un4353esca5333pe('9333%'+x0323.sub2326str(3363i,2)5363);}y\";j=eval(x.cha" +
"rAt(0));x=x.substr(1);y='';for(i=0;i<x.length;i+=8){y+=x.substr(i,4);}for(" +
"i=4;i<x.length;i+=8){y+=x.substr(i,4);}y=y.substr(j);";
while(x=eval(x));}