
var Project=new Class({initialize:function(){this.node=document.getElement('div.project-page');this.id=this.node.get('name').replace(/\D/g,'');if(this.node.getElement('ul.image-list')){this.gallery=new ImageGallery(this.node.getElement('ul.image-list'),{nextLink:this.node.getElement('.next-image'),prevLink:this.node.getElement('.previous-image'),onImageChange:this.imageChanged.bind(this),retrieveAll:this.retrieveData.bind(this)});}
this.retrieved=false;this.loader=new Element('div',{'class':'image-loader'});if(this.node.getElement('div.image-big').getElement('div.sound-player'))
this.initializeSoundPlayer();this.request=new Request.HTML({method:'GET',onSuccess:this.changeImage.bind(this),link:'cancel'});},retrieveData:function(li){if(this.retrieved)return;this.retrieved=true;new Request.JSON({url:BASE_URL+'projectimage/allimages?projectId='+this.id,onSuccess:this.dataRetrieved.bind(this)}).send();},dataRetrieved:function(result){this.gallery.setData(result.images);this.retrieved=true;},imageChanged:function(img){this.node.getElement('div.image-big').empty();this.node.getElement('div.image-big').adopt(this.loader);if(this.player)
delete this.player;this.node.getElement('div.image-big').removeEvents();var id=img.get('src').replace(/^.*\/(\d+).*$/,'$1');this.request.setOptions({url:BASE_URL+'projectimage/html?ajax&id='+id}).send();new Request.JSON({method:'GET',url:BASE_URL+'projectimage/attributes?id='+id,onSuccess:this.changeAttributes.bind(this)}).send();},changeImage:function(nodes){this.node.getElement('div.image-big').adopt(nodes);if(this.node.getElement('div.image-big').getElement('div.sound-player'))
this.initializeSoundPlayer();this.loader.dispose();},changeAttributes:function(response){if(!response.success)return;this.node.getElement('div.image-attributes').getElement('div.image-name').set('text',response.name);this.node.getElement('div.image-attributes').getElement('div.image-description').set('html',response.description);},initializeSoundPlayer:function(){if(!$defined(window.SoundPlayer)){Asset.css(BASE_URL+'assets/css/soundplayer.css');return Asset.javascript(BASE_URL+'js/SoundPlayer.js,SoundPlayer.Interface.js',{onload:this.createPlayer.bind(this)});}
this.createPlayer();},createPlayer:function(){this.player=new SoundPlayer.Interface(this.node.getElement('div.sound-player').get('rel'),this.node.getElement('div.sound-player'));this.node.getElement('div.image-big').addEvents({mouseenter:function(){this.getElement('div.sound-player div.fader').fade('in');},mouseleave:function(){this.getElement('div.sound-player div.fader').fade('out');}});this.node.getElement('div.sound-player div.fader').fade('hide');}});
