//core.js -- © 2010 Marc-Emmanuel Ramage & NVN STUDIOS
//navigator section
var versiondev = 11;
var isIE = jCalix_checkNav('msie');
var isIE6 = jCalix_checkNav('msie 6');
var isIE7 = jCalix_checkNav('msie 7');
var isIE8 = jCalix_checkNav('msie 8');
var isChrome = jCalix_checkNav('chrome');
var isSafari = jCalix_checkNav('safari') && !jCalix_checkNav('chrome') ;
var isIphone = jCalix_checkNav('iphone');
var isIpad = jCalix_checkNav('ipad');
var isChromeMac = function() {
    var mac = jCalix_checkNav('macintosh');
    var chrome = jCalix_checkNav('chrome');
    if (mac != 0 && chrome != 0)
    return true;
    else
    return false;
}

// end navigator section
// var section
var line1;
var line2;
var lis;
var loadindex = 0;
var slideindex = 0;
var slidepx = 0;
var imgindex = 0;
var enableclick = true;
var imgsloaded = false;
var slidewidth = 720;
var sliding = false;
var changeslide = false;
var reseting = false;
var sortednav;
var prevslide;
var prevz;
var objects;
var animatestop = false;
var activeplayer = null;
var loaded = false;
var pane = null;

//end var section
// jQuery section
function fadeinObject(obj, time) {
    var t = 500;
    if (time != null)
    t = time;
    jQuery(obj).animate({
        opacity: 1
    },
    t);
}


function fadeoutObject(obj, time) {
    var op = 0;
    if (isIE)
    op = 1;
    var t = 200;
    if (time != null)
    t = time;
    jQuery(obj).animate({
        opacity: op
    },
    t);
}


function fadefilomeno() {

    if (_$('#filomeno').getObject()) {
        _$('#loaded').Load(
        jQuery(".container").animate({
            opacity: 1
        },
        1000),jQuery(".pagination").animate({
            opacity: 1
        },
        1000),jQuery(".space img").animate({
            opacity: 1
        },
        1000));    

    }
}

// end jQuery section
// callbacks section

function afterload() {	 
    var bodyclass = _$('#bodyclass').html();
    if (_$('#ajaxcontainer').getObject())
    _$('#ajaxcontainer').Display('block');
        var bigimg = _$('#bigimg').getObject();
        if (bigimg)
        fadeinObject(bigimg, 200);    
    pane = initscroll();
}



function devalert() {
    var version = _$('#version').html();
    if (parseInt(version) != parseInt(versiondev))
    _$('#devalert').Display('block');
}


/*
function centermenu() {
	var menunumbers = jQuery('#menu ol').size();
	if (!isIE6) {
	var cookie = jCalix.getCookie('centermenumargin');
	if (cookie == null){
		var menu = _$('#menu', {index1: 0});
		if (menu.getObject() == null) return false;
		var menuwidth = menu.getPosition().x + menu.getWidth();
		var menuimgs = _$(':ol', {node: menu.getObject()});
		var rightimg = menuimgs.get(menuimgs.Length() - 1);
		var leftimg = menuimgs.get(menuimgs.Length() - 2);
		var innerleft = leftimg.getPosition().x + leftimg.getWidth();
		var innerright = rightimg.getPosition().x;
		var innercenter = innerright + 2 - innerleft;
		var marginright = innercenter / (menunumbers-1);
		for (var i = 0; i < menuimgs.Length() - 2; i++) {
			menuimgs.get(i).Style().marginRight = marginright + 'px';
		}
		jCalix.setCookie('centermenumargin',marginright,30);
    }
    
    }
}
*/


function fixcss() {	
	if(navigator.appVersion.indexOf('Win') == -1)
	return false;
    var l = document.createElement('link');
    l.setAttribute('rel', 'stylesheet');
    l.setAttribute('href', '/css/windows.css');
    l.setAttribute('type', 'text/css');
    document.getElementsByTagName('html')[0].appendChild(l);
}


function fixiphone() {
    if (isIphone) {
        var l = document.createElement('link');
        l.setAttribute('rel', 'stylesheet');
        l.setAttribute('href', 'http://www.mfilomeno.com/css/iphone.css');
        l.setAttribute('type', 'text/css');
        document.getElementsByTagName('html')[0].appendChild(l);
        var space = jQuery('.space');
		var spaceWidth = space.find('img').width();
		jQuery('.space img').height(300)
    }
}

function fixipad() {
    if (isIpad) {
        var l = document.createElement('link');
        l.setAttribute('rel', 'stylesheet');
        l.setAttribute('href', 'http://www.mfilomeno.com/css/ipad.css');
        l.setAttribute('type', 'text/css');
        document.getElementsByTagName('html')[0].appendChild(l);
    }
}


jCalix.onLoad();

if (!isIE6) {
    jCalix.addOnLoad(fixiphone);
    jCalix.addOnLoad(fixipad);
    jCalix.addOnLoad(fixcss);
  //  jCalix.addOnLoad(jCalix.initAjax);
 //   jCalix.addOnLoad(function(){ if(!isIE6)jCalix.ajaxSetLinks({callback_in: ajaxResponse});});
 //   jCalix.addOnLoad(checkreload);
}
jCalix.addOnLoad(onLoad);
if (!isIE6) {
/*     jCalix.addOnLoad(centermenu); */
   // jCalix.addOnLoad(jCalix.initAjaxHistory);
   // jCalix.addOnLoad(jCalix.addHistoryEntry);
}


function onLoad() {

if(document.location.href.indexOf('blog/') != -1)
	return false;
    devalert();
    fadefilomeno();
    afterload();
}


// end callbacks section


// add vincent



function bioSlider() {
	var container = jQuery('.space');
	var ul = jQuery('div', container);
	var difference = ul.innerHeight()-450;
	var proportion = 450/ul.innerHeight();
	var handleHeight = 450*proportion;//set the proportional height - round it to make sure everything adds up correctly later on


	if(difference > 0 && !isIphone && !isIpad){
	
		jQuery(".bioslider").slider({
			orientation: "vertical",
			range: "max",
			min: 0,
			max: 100,
			value: 100,
			slide: function(event, ui) {
				var topValue = -((100-ui.value)*difference/100);
				jQuery(".space").css({top:topValue});
			}
		});

		//set the handle height
		jQuery(".ui-slider-handle").css({height:handleHeight});

		//now amend the height of the slider so that the handle doesn't stick out of the bottom...
		var origSliderHeight = jQuery("#slider-vertical").height();//read the original slider height
		var sliderHeight = origSliderHeight - handleHeight +10;//height needs to be the original height - handle height +10px already accounted for
		var sliderPaddingBottom = origSliderHeight - sliderHeight +15;//need to increase the padding-bottom of the slider to compensate for the reduced height, add the original 15px back on
		jQuery("#slider-vertical").css({height:sliderHeight,'padding-bottom':sliderPaddingBottom});//set the slider height and padding-bottom
	}else{
		jQuery(".sliderContainerV").hide()
	}
}


function Avancer() {
/*
var container = jQuery('.space');
var ul = jQuery('ul', container);

var itemsWidth = ul.innerWidth()-910;
var elValue = jQuery('.slider').slider('option', 'value');
  
       if(elValue < itemsWidth) {
          elValue +=  itemsWidth/1000; 
          if(elValue > itemsWidth) {
         elValue = itemsWidth;
      }


      jQuery(".slider").slider('value', elValue); 
      //jQuery(".space").animate({'left' : elValue * -1}, 15,function(){if(!animatestop)Avancer();});      
      _$('.space').Animate({effect:{name:'translation',left:(elValue*-1)},speed:'10',after:function(){if(!animatestop)Avancer();}});
      
       }
*/

jQuery('.jspArrowRight').mousedown();
}

function Reculer() {
/*
var container = jQuery('.space');
var ul = jQuery('ul', container);

var itemsWidth = ul.innerWidth()-910;
var elValue = jQuery('.slider').slider('option', 'value');

       if(elValue > 0) {
          elValue -= itemsWidth/1000;
          if(elValue < 0) {
         elValue = 0;
      }

      
     jQuery(".slider").slider('value', elValue);
     //jQuery(".space").animate({'left' : elValue * -1}, 15,function(){if(!animatestop)Reculer();});
     _$('.space').Animate({effect:{name:'translation',left:(elValue*-1)},speed:'10',after:function(){if(!animatestop)Reculer();}});
       }
*/

jQuery('.jspArrowLeft').mousedown();

}



function imgVideo(obj) {
	
	obj.currentTime=0;
	if(!isIE){
		jQuery(obj).hide();
		obj.pause();
		if(!isff && !isIphone && !isIpad)
			obj.load();
		jQuery(".videodiv").prev().fadeIn(300);
	}else{
		jQuery(".player").hide();
		jQuery(".img-video").fadeIn(300);
	}
}

if(document.location.href.indexOf('blog/') == -1)
jQuery(inits);

function inits() {
		 
 //Flèche gauche grisée au départ 
var space = jQuery('body');
var spaceWidth = space.find('.heavy').width();


if(isIphone || isIpad){
	jQuery('.biography').jScrollTouch()
	jQuery('.text-container').jScrollTouch()
}

var cmenu = false;

function restorecontent(){

		cmenu = false;
		jQuery('.container').stop().clearQueue();
		jQuery('.container').animate({opacity: 1}, 200,function(){cmenu = false;});
		if(isIE){
		jQuery('img').animate({opacity: 1}, 200);
		jQuery('.pagination').animate({opacity: 1}, 200);
/* 		jQuery('.album').animate({opacity: 1}, 200); */
		}
		
		if(document.location.href.indexOf('blog/') != -1){		
		jQuery('.post').animate({opacity: 1}, 200);
		jQuery('.page-title').animate({opacity: 1}, 200);
		jQuery('.widget-area').animate({opacity: 1}, 200);
		}
}

function hidecontent(){

		if(cmenu == false)
			return false;

		jQuery('.container').stop().clearQueue();
		jQuery('.container').animate({opacity: 0.2}, 200,function(){cmenu = false;});		
		if(isIE){
		jQuery('img').animate({opacity: 0.2}, 200);
		jQuery('.pagination').animate({opacity: 0.2}, 200);
/* 		jQuery('.album').animate({opacity: 0.2}, 200); */
		}
			
		if(document.location.href.indexOf('blog/') != -1){	
		jQuery('.post').animate({opacity: 0.2}, 200);
		jQuery('.page-title').animate({opacity: 0.2}, 200);
		jQuery('.widget-area').animate({opacity: 0.2}, 200);
		}
}

if(!isIpad && !isIphone){

jQuery('.menu-wrapper ol').mouseenter(
	function() {
		if(cmenu == true)return false;
		cmenu = true;
		hidecontent();


	}).mouseleave(
	function() {
		restorecontent();
		
	});
	
	
jQuery('#ajax').mouseenter(
	function() {
		restorecontent();
			
	});	
	
	
jQuery('.container').mouseenter(
	function() {
		restorecontent();
			
	});	
	
	
	
jQuery('.title').mouseenter(
	function() {
		restorecontent();
			
	
	});		
	
jQuery('#main').mouseenter(
	function() {
		restorecontent();
	
	});		
	
}	
	
jQuery('.menu-wrapper ol li').mouseenter(
	function() {
		jQuery(this).addClass('over');
		jQuery('.container').fadeTo(100,0.1);
		
	}).mouseleave(
	function() {
		jQuery(this).removeClass('over');
	
	});

jQuery('#album').click(function(){jQuery('.container').fadeTo(100,1);});
	
//if(isIpad || isIphone)
//jQuery('.level0').click(function(){jQuery(this).addClass('over');jQuery('#album').fadeOut();});	

	
jQuery('.gallery li a').mouseenter(
	function() {
	//	jQuery(this).children('.layer').fadeIn();
	jQuery('.container').fadeTo(100,1);
	jQuery(this).children().show();	
	//jQuery(this).children('.name').show();
	jQuery(this).children('.layer').animate({
            opacity: 0.7
        },
        500);
        
	}).mouseleave(
	function() {
	//	jQuery(this).children('.layer').fadeOut();
	jQuery(this).children().hide();
		jQuery(this).children('.layer').animate({
            opacity: 0
        },
        500);
	});


jQuery('.img-video').click(
	function() {
		if(!isIpad && !isIphone){
			var left = _$('.menu-container').getPosition().x;
			var thisx = _$(this).getPosition().x; 
			var api = pane.data('jsp');
			api.scrollBy(parseInt(thisx-left));
		}
		if(activeplayer){
			activeplayer.pause();
			jQuery(activeplayer).hide();
			}			
		
		jQuery(".videodiv").prev().show();		
		jQuery(this).toggle();
		

		if(isIphone || isIpad){
			if(!isIphone){
			activeplayer = _$(':video',{node:this.parentNode}).getObject();
			activeplayer.style.display = 'block';		
			activeplayer.play();
			
			}else{			
				
				var tmp = jQuery(this).next(".videodiv").html();
				jQuery(this).next().children(":first-child").remove();	
				jQuery(this).next(".videodiv").html(tmp);				
				jQuery(this).next().children(":first-child").show();
				jQuery(this).next().children(":first-child").trigger('play');	
				activeplayer = _$(':video',{node:this.parentNode}).getObject();
	
			}		
		}else{

			var clip1 = { url: jQuery('#src'+jQuery(this).attr('id')).html(),autoPlay:false,autoBuffering: true,scaling:'orig',onfinish: function() {this.unload();imgVideo();}};
		
			jQuery(".player").hide();					
			jQuery('#player'+jQuery(this).attr('id')).toggle();
			if($f('player'+jQuery(this).attr('id')) == null)
			$f('player'+jQuery(this).attr('id'), "/js/flowplayer/flowplayer.commercial-3.2.5.swf",{key: '#$9d60f0c9eb54a5c1bdc',canvas: {backgroundGradient: 'none',backgroundColor:'#000'},clip:clip1});			
			$f('player'+jQuery(this).attr('id')).play();

		}

		
});


jQuery("video").click(
	function () {
		if(!jQuery(this).attr("paused")){
			jQuery(this).trigger("pause");
		}else{
			jQuery(this).trigger("play");				
		}
	}
);





  // Déplacement du slideshow
/*
  jQuery('a#goLeft').mouseout(
    function (e) {
      jQuery('.space').stop();
    }).hover(
    function (e) {
      var sz = jQuery('.space');
      sz.animate({ left : 0 }, 10000, 'linear');
	});
  jQuery('a#goRight').mouseout(
  	function (e) {
      jQuery('.space').stop();
    }).hover(
    function (e) {
      var sz = jQuery('.space');
      var margin = -sz.find('ul').width() + 910;
      sz.animate({ left : margin }, 10000, 'linear');
    });
*/



//Evénement sur le clic flèche droite + partie droite de l'image




//Evénement sur le clic flèche gauche + partie gauche de l'image 			   			

jQuery('a#goLeft').mouseenter(function(){
//	animatestop = false;
	Reculer();
});


jQuery('a#goLeft').mouseout(function(){
  //setTimeout('animatestop = true;',10);
  jQuery('.jspArrowLeft').mouseup();
});


jQuery('a#goRight').mouseenter(function(){
 // animatestop = false;	
  Avancer();

});

jQuery('a#goRight').mouseout(function(){
//  setTimeout('animatestop = true;',10);
jQuery('.jspArrowRight').mouseup();

});  


//Evénement sur les mouvements iPhone/iPad 			

if(isIpad || isIphone){
   			
jQuery("#pages").touchwipe({
 		wipeLeft: function() {
 	 		jQuery("#pages").cycle("next");
 		},
 		wipeRight: function() {
 	 		jQuery("#pages").cycle("prev");
 		}
	});
	
	}
	
/*
jQuery("#album").touchwipe({
 		wipeLeft: function() {
 	 		Avancer();
 		},
 		wipeRight: function() {
			Reculer();
 		}
	});
*/

//Evénement clavier
jQuery(window).keydown(function(e){ 
        switch (e.keyCode) { 
            case 37: // flèche gauche 
                jQuery("#pages").cycle("prev");
                Reculer();
                break; 
            case 39: // flèche droite 
				jQuery("#pages").cycle("next");
				Avancer();
                break;  
        } 
    });

	   
/*
var widthHD = 0; 	
jQuery('.hd-album img').each(function() {
    widthHD += jQuery(this).outerWidth( true );
    jQuery('.hd-album').css('width', widthHD+1);
});
*/

jQuery('#title').delay(5000).animate({
	"top": "-76px"
},2000);

jQuery('#titleContainer').mouseenter(function(){jQuery('#title').clearQueue()})

jQuery('#titleContainer').mouseenter(
		function() {
		jQuery('#title').animate({"top": "0px"},1000);
	}).mouseleave(
	function() {
		jQuery('#title').animate({"top": "-76px"},1000);
	});
 	
/*
*/


}//);


function initscroll(){
	if(!isIpad && !isIphone){	
		if(isSafari)
			return $('#album').jScrollPane({onlyHRZ:true, showArrows: true, arrowButtonSpeed: 1, arrowRepeatFreq: 7, mouseWheelSpeed:0.2});
		else	
			return $('#album').jScrollPane({onlyHRZ:true, showArrows: true, arrowButtonSpeed: 1, arrowRepeatFreq: 7, mouseWheelSpeed:10});

	}
}



