var YUI3_config = { modules: {} };
YUI( YUI3_config ).add('io-ez', function( Y )
{
var _rootUrl = '/graphic_designer/', _serverUrl = _rootUrl + 'ezjscore/', _seperator = '@SEPERATOR$', _configBak;
function _ez( callArgs, c )
{
callArgs = callArgs.join !== undefined ? callArgs.join( _seperator ) : callArgs;
var url = _serverUrl + 'call/';
if ( c === undefined )
c = {on:{}, data: '', headers: {}, method: 'POST'};
else
c = Y.merge( {on:{}, data: '', headers: {}, method: 'POST'}, c );
var _token = '', _tokenNode = document.getElementById('ezxform_token_js');
if ( _tokenNode ) _token = '&ezxform_token=' + _tokenNode.getAttribute('title');
if ( c.method === 'POST' )
c.data += ( c.data ? '&' : '' ) + 'ezjscServer_function_arguments=' + callArgs + _token;
else
url += encodeURIComponent( callArgs );
c.headers.Accept = 'application/json,text/javascript,*/*';
if ( c.on.success !== undefined )
c.on.successCallback = c.on.success;
c.on.success = _ioezSuccess;
_configBak = c;
return Y.io( url, c );
}
function _ioezSuccess( id, o )
{
if ( o.responseJSON === undefined )
{
var returnObject = {'responseJSON': Y.JSON.parse( o.responseText ),
'readyState': o.readyState,
'responseText': o.responseText,
'responseXML': o.responseXML,
'status': o.status,
'statusText': o.statusText
};
}
else
{
var returnObject = o;
}
var c = _configBak;
if ( c.on.successCallback !== undefined )
{
if ( c.arguments !== undefined )
c.on.successCallback( id, returnObject, c.arguments );
else
c.on.successCallback( id, returnObject, null );
}
else if ( window.console !== undefined )
{
if ( returnObject.responseJSON.error_text )
window.console.error( 'Y.ez(): ' + returnObject.responseJSON.error_text );
else
window.console.log( 'Y.ez(): ' + returnObject.responseJSON.content );
}
}
_ez.url = _serverUrl;
_ez.root_url = _rootUrl;
_ez.seperator = _seperator;
Y.io.ez = _ez;
}, '3.0.0' ,{requires:['io-base', 'json-parse']});
if (window.location.hash != null && window.location.hash != ""){
var splitted = window.location.hash.split('=');
if (splitted.length == 2 && splitted[0]=='#img'){
window.location=document.URL.substring(0,document.URL.lastIndexOf('/'))+'/'+splitted[1];
}
}
YUI( YUI3_config ).add( 'anim-blur', function (Y) {
Y.Anim.behaviors.blur = {
set: function(anim, att, from, to, elapsed, duration, fn) {
var v = fn(elapsed, Number(from),  Number(to) - Number(from), duration);
var str = "progid:DXImageTransform.Microsoft.Blur(PixelRadius='6', MakeShadow='true', ShadowOpacity='"+v+"')";
anim._node.setStyle( 'filter', str );
anim._node.setStyle( 'ms-filter', str );
}
};
}, '0.0.1', { requires: ['anim'] });
YUI(YUI3_config).use('node','anim','anim-blur','node-event-simulate','async-queue','history','io-ez', function(Y) {
var isIE = (Y.UA.ie > 0 && Y.UA.ie < 9);
var history = new Y.HistoryHash();
Y.on( "load", function( e ){
if (null != Y.one('#mozaic')){
var ajaxDisplayAllDatas=function (e){
var nid=e.currentTarget.one('a').getAttribute('nid');
Y.one('#ajaxload').setStyle('visibility', 'visible');
Y.all('.photo,.video').each(function (node){
node.setStyle('backgroundColor','transparent');
});
Y.io.ez( 'ezjsimage::get', {
data: 'arg1='+nid,
on: {success: function( id,r ){
if ( r.responseJSON.error_text ){
console.error(r.responseJSON.error_text);
}else {
var photoBack=Y.one('#photo-top').cloneNode(false);
photoBack.setContent(r.responseJSON.content['content']);
photoBack.setAttribute("id", 'photo-back');
if (isIE){
if (photoBack.one('.video')){
photoBack.all('.video').setStyle('visibility','hidden');
}else{
photoBack.all('.photo img').setStyle('opacity',0);
}
photoBack.one('.ombreimg').setStyle('filter',"progid:DXImageTransform.Microsoft.Blur(PixelRadius='6', MakeShadow='true', ShadowOpacity='0.00')");
photoBack.one('.ombreimg').setStyle('ms-filter',"progid:DXImageTransform.Microsoft.Blur(PixelRadius='6', MakeShadow='true', ShadowOpacity='0.00')");
}else{
photoBack.all('.photo').setStyle('opacity',0);
}
if (photoBack.one('.video'))
photoBack.all('.video').setStyle('visibility','hidden');
photoBack.all('.photo,.video').setStyle('backgroundColor','transparent');
Y.one('#gallery').append(photoBack);
var captionBack=Y.one('#photo-caption').cloneNode(true);
captionBack.setAttribute("id", 'photo-caption-back');
captionBack.setStyle('opacity',0);
captionBack.one('.photo-caption-spacer').setContent(r.responseJSON.content['caption']);
Y.one('#photo-caption').get('parentNode').append(captionBack);
Y.one('#ajaxload').setStyle('visibility', 'hidden');
processAnimations(e);
}
}
}
});
};
var preloadingImg=new Array();
var getImageObject = function (imgSrc){
var newImg = new Image();
newImg.src = imgSrc;
return newImg;
}
Y.all('#mozaic img').each(function (node){
preloadingImg[node.getAttribute('src')]=getImageObject(node.getAttribute('src').replace('_smaller.jpg', '_larger.jpg'));
});
Y.on('history:change', function (e) {
if (e.src === Y.HistoryHash.SRC_HASH) {
if (e.changed.img) {
Y.one("#mozaic td#"+e.changed.img.newVal).simulate("click");
} else if (e.removed.img) {
Y.one("#mozaic td#"+document.URL.split('/').reverse()[0]).simulate("click");
}
}
});
var processAnimations= function(e){
var topCaptionAnim = new Y.Anim({
node: 		'#photo-caption',
to: 		{opacity: 0},
duration:	1,
easing:		Y.Easing.easeOut
});
var backCaptionAnim = new Y.Anim({
node: 		'#photo-caption-back',
to: 		{opacity: 1},
duration:	1,
easing:		Y.Easing.easeOut
});
backCaptionAnim.on('end', function() {//cleaning
Y.one('#photo-caption').remove();
Y.one('#photo-caption-back').setAttribute('id','photo-caption');
});
var topAnim ;
var topOmbre;
if (isIE){
if (Y.one("#photo-top .video") == null){
topAnim = new Y.Anim({
node: 		'#photo-top .photo img',
to: 		{opacity: 0},
duration:	1,
easing:	Y.Easing.easeOut
});
}
topOmbre = new Y.Anim({
node: 		'#photo-top .ombreimg',
from: 		{ 'blur' : '0.60' },
to 	: 		{ 'blur' : '0.0' },
duration:	1,
easing:		Y.Easing.easeOut
});
}else{
if (Y.one("#photo-top .video") == null){
topAnim = new Y.Anim({
node: 		'#photo-top .photo',
to: 		{opacity: 0},
duration:	1,
easing:		Y.Easing.easeOut
});
}
}
var topColor = new Y.Anim({
node: 		'#mozaic td.selected',
from: 		{backgroundColor:Y.one('#mozaic td.selected').getStyle('backgroundColor')},
to: 		{backgroundColor: '#E5E5E5'},
duration:	1,
easing:		Y.Easing.easeOut
});
topColor.on('end', function() {
var tmpNode = Y.one('#mozaic td.selected');
tmpNode.removeClass('selected');
tmpNode.setStyle('backgroundColor','');
});
var backAnim;
var backOmbre;
if (isIE){
if (Y.one("#photo-back .video") == null){
backAnim = new Y.Anim({
node: 		'#photo-back .photo img',
to: 		{opacity: 1},
duration:	1,
easing:		Y.Easing.easeOut
});
}
backOmbre = new Y.Anim({
node: 		'#photo-back .ombreimg',
from: 		{ 'blur' : '0.0' },
to 	: 		{ 'blur' : '0.60' },
duration:	0.6,
easing:		Y.Easing.easeOut
});
}else{
if (Y.one("#photo-back .video") == null){
backAnim = new Y.Anim({
node: 		'#photo-back .photo',
to: 		{opacity: 1},
duration:	1,
easing:		Y.Easing.easeOut
});
}
}
var backColor = new Y.Anim({
node: 		e.currentTarget,
from: 		{backgroundColor: e.currentTarget.getStyle('backgroundColor')},
to: 		{backgroundColor: Y.one('#mozaic td.selected').getStyle('backgroundColor')},
duration:	1,
easing:		Y.Easing.easeOut
});
backColor.on('end', function() {
e.currentTarget.addClass('selected');
Y.one('#photo-top').remove();
var backN = Y.one("#photo-back");
if (!isIE && backN.one('.video') != null)
backN.one('.video').setStyle('visibility', 'visible');
backN.setAttribute('id','photo-top');
history.addValue('img', e.currentTarget.getAttribute('id') || null);
var hr = Y.one('#translation').getAttribute('href')
Y.one('#translation').setAttribute('href',hr.substring(0,hr.lastIndexOf('/'))+'/'+e.currentTarget.one('a').getAttribute('nid'));
_gaq.push(	['_trackPageview', document.URL.split('/').pop()+"/"+e.currentTarget.getAttribute('id')],
['_trackEvent', 'Mozaic', 'Click', e.currentTarget.getAttribute('id')]);
processing=false;
});
var q = new Y.AsyncQueue();
if (isIE){
q.add({
fn: function(){
topOmbre.run();
},
timeout : 0
});
}
q.add({
fn: function(){
topCaptionAnim.run();
topColor.run();
if (topAnim==null){
Y.one('#photo-top .video').setStyle('visibility', 'hidden');
}else{
topAnim.run();
}
},
timeout : 200
});
q.add({
fn: function(){
backCaptionAnim.run();
backColor.run();
if(backAnim!=null){
backAnim.run();
}
},
timeout : 400
});
if (isIE ) {
q.add({
fn: function(){
backOmbre.run();
if (Y.one('#photo-back .video') != null)
Y.one('#photo-back .video').setStyle('visibility', 'visible');
},
timeout : 400
});
}
q.run();
}
var processing=false;
var onClick = function(e) {
e.halt(); //stop propagation
if (processing){
return;
}else{
processing=true;
}
var srcUrl = e.currentTarget.one('img').getAttribute('src');
ajaxDisplayAllDatas(e);//make ajax call
};
Y.one('#mozaic').delegate('click', onClick, 'td');
}
});
Y.delegate('click', function(e) {
var siteA = window.location.pathname.replace(/^\//,'').split('/').shift();
if ('graphic_designer' == siteA){
_gaq.push(['_trackEvent', 'Download', 'Resume','english']);
}else if ('graphiste_illustratrice' == siteA){
_gaq.push(['_trackEvent', 'Download', 'Resume','french']);
}else{
_gaq.push(['_trackEvent', 'Download', 'Resume','unknow_'+siteA]);
}
}, '#header-cv','a');
});

