var m__flashPayerVersion;

/* --- INIT --- */
$(document).ready(function()
{
	//Cufon
	Cufon.set('fontFamily', 'Trade-Gothic');

	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');

	//Event
	$('.button_site').mouseenter(function()
	{
		$(this).animate({"background-color": '#3d3d3d'}, 300);
	})

	$('.button_site').mouseleave(function()
	{
		$(this).animate({"background-color": '#2D2D2D'}, 300);
	})

	$('.container_slideshow .overlay').mouseenter(function()
	{
		$(this).animate({"opacity": '0.8'}, 300);
	})

	$('.container_slideshow .overlay').mouseleave(function()
	{
		$(this).animate({"opacity": '0.7'}, 300);
	})

	//Slides
    $('#espace_trocadero #slides').slides(
    {
        preload: true,
        preloadImage: 'images/loader.gif',
        generatePagination: false
    });

    $('#zsuzsanna #slides').slides(
    {
        preload: true,
        preloadImage: 'images/loader.gif',
        generatePagination: false
    });

	$('#uncharted_3 #slides').slides(
	{
		preload: true,
		preloadImage: 'images/loader.gif',
		generatePagination: false
	});

	$('#victoires #slides').slides(
	{
		preload: true,
		preloadImage: 'images/loader.gif',
		generatePagination: false
	});

	$('#savoy #slides').slides(
	{
		preload: true,
		preloadImage: 'images/loader.gif',
		generatePagination: false
	});

	$('#slides .prev').mouseenter(function()
	{
		$(this).animate({"opacity": '1'}, 200);
	});

	$('#slides .prev').mouseout(function()
	{
		$(this).animate({"opacity": '0'}, 200);
	});

	$('#slides .next').mouseenter(function()
	{
		$(this).animate({"opacity": '1'}, 200);
	});

	$('#slides .next').mouseout(function()
	{
		$(this).animate({"opacity": '0'}, 200);
	});

	//Parallax
    $.scrollingParallax('images/background/img8.jpg', {
        name : 'item_1',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 900,
        bgWidth: '562px',
        bgHeight: '414px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img9.jpg', {
        name : 'item_1',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 2200,
        bgWidth: '566px',
        bgHeight: '440px',
        disableIE6 : true
    });

	$.scrollingParallax('images/background/img1.jpg', {
		name : 'item_1',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 3800,
        bgWidth: '561px',
        bgHeight: '317px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img2.jpg', {
    	name : 'item_2',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 5000,
        bgWidth: '561px',
        bgHeight: '575px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img3.jpg', {
    	name : 'item_3',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 6500,
        bgWidth: '561px',
        bgHeight: '698px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img4.jpg', {
    	name : 'item_4',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 7800,
        bgWidth: '561px',
        bgHeight: '569px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img5.jpg', {
    	name : 'item_5',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 9500,
        bgWidth: '561px',
        bgHeight: '456px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img6.jpg', {
    	name : 'item_6',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 11100,
        bgWidth: '561px',
        bgHeight: '262px',
        disableIE6 : true
    });

    $.scrollingParallax('images/background/img7.jpg', {
    	name : 'item_7',
        staticSpeed : 1.7,
        loopIt : false,
        staticScrollLimit : false,
        bgTop : 12800,
        bgWidth: '561px',
        bgHeight: '252px',
        disableIE6 : true
    });

    //VideoPlayer & Fancybox
    var m__flashPayerVersion = getFlashVersion().split(',').shift();

    $('#bt_movie_bretagne').click(function()
    {
        var thumb = m__rootURL + 'videos/thumb-bretagne.png';
        var flash_path = m__rootURL + 'videos/bretagne.f4v';
        var hm_path = m__rootURL + 'videos/bretagne.m4v';
		//var path = m__rootURL + 'images/video/annedebretagne.mov';

        loadVideoPlayer(thumb, flash_path, hm_path);

        return false;
    });

    $('#bt_movie_fiat').click(function()
    {
        var thumb = m__rootURL + 'videos/thumb-fiat.png';
        var flash_path = m__rootURL + 'videos/fiat.f4v';
        var hm_path = m__rootURL + 'videos/fiat.m4v';

        loadVideoPlayer(thumb, flash_path, hm_path);

        return false;
    });
});

function removeOverlay(i__target)
{
	$(i__target).fadeOut(300);
}

function loadVideoPlayer(thumb, flash_path, hm_path)
{
    $.fancybox(
        '<div id="player" class="video-js-box"><video class="video-js" width="670" height="376" controls preload poster="' + thumb + '"><source src="' + hm_path + '" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' /></video></div>',
        {
            'autoDimensions'    : false,
            'width'             : 670,
            'height'            : 'auto',
            'speedIn'           : 600, 
            'speedOut'          : 200
        }
    );

    var flashvars = {
        path: flash_path,
        defaut_image: thumb
    };
    var params = {
        menu: "false",
        scale: "noScale",
        allowFullscreen: "true",
        allowScriptAccess: "always",
        bgcolor: "#00FF00",
        wmode: "transparent"
    };
    var attributes = {
        id:"flash-content"
    };
    
    swfobject.embedSWF("swf/videoPlayer.swf", "player", "670", "376", "10.0.0", "swf/expressInstall.swf", flashvars, params, attributes);

    //If no flash activate HTML5 Player
    if(m__flashPayerVersion == '0')
    {
        VideoJS.setupAllWhenReady();
    }
}

function getFlashVersion()
{
  // ie
  try {
    try {
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
      try { axo.AllowScriptAccess = 'always'; }
      catch(e) { return '6,0,0'; }
    } catch(e) {}
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  // other browsers
  } catch(e) {
    try {
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
      }
    } catch(e) {}
  }
  return '0,0,0';
}
