/*	Copywright Bruno Torrinha Nov 2008	www.torrinha.com	*/
var site = {

	start: function(sLang){

		//-----------------
		//	Setup Portfolio
		//-----------------
		var p = $('photosBoxWrap').set('tween', {
			duration: 1000,
			link:'cancel',
			transition: 'sine:in:out'
		});
		var fotosWrap = $('photosBoxWrap');

		['web', 'code', 'design', 'foto'].each(function(el, index){
//		['web', 'foto', 'code', 'design'].each(function(el, index){
			if (index == 0) {
				this.setupBtns(p.getElement('ul'));
			} else {
				var req = new Request.JSON({
					url:'/postPortf.asp', 
					onComplete: function(myJson) {
						var boxFoto = new Element('div', {'class': 'photosBox'});
						var ulPhotos = new Element('ul');
						myJson.each(function(project, i){
							var xli = new Element('li').inject(ulPhotos);
							var xA = new Element ('a', {'href': '/images/portfolio/' + project.fotoHigh, 'rel': 'milkbox:' + el, 'title': project.title});
							var xImg = new Element('img', {'src': '/images/portfolio/' + project.fotoMini, 'id': 'thumb' + el + i});
							xA.adopt(xImg);
							xli.adopt(xA);
						}, this);
						boxFoto.adopt(ulPhotos).inject(fotosWrap);
						this.setupBtns(ulPhotos);
					}.bind(this)
				}, this).get({'nlg': sLang, 'portfolio': el});
			};
		}, this);
		
		var doMilkbox = function(){new Milkbox();};
		doMilkbox.delay(500);

		var portLinks = [];
		var portLinkOn = 0;

		//---------------
		//	Setup buttons
		//---------------
		$('menuTopRg').getElements('a').each(function(el, index){
			el.set('href', '#portfolio');
			portLinks.push(el);
			el.addEvent('click', function(e){
				e.stop();
				if (portLinkOn != index) {
					portLinks[portLinkOn].removeClass('lnkOn');
					portLinks[index].addClass('lnkOn');
					portLinkOn = index;
					p.tween('left', index * '-545');
				}
			}, this);
		}, this);

		//----------------------------
		//	Setup anchor scroll effect
		//----------------------------
		var mySmoothScroll = new SmoothScroll({duration: 700, wheelStops: false}, window);
	},


	//---------------------------------------------------------------
	//	Setup thumb's opacity of portfolio photos MouseHover MouseOut
	//---------------------------------------------------------------
	setupBtns: function(ul) {
		ul.getElements('li').each(function(el){
			if (Browser.Engine.webkit) el.setStyle('margin-right', '18px');
			el.set('tween', {duration:300, link:'cancel'}).set('opacity', 0.5).addEvents({
				mouseenter: function(){ el.tween('opacity', 1) },
				mouseleave: function(){ el.tween('opacity', 0.5) }
			});
		});
	}
};