﻿/*
	Blankodesign.
	Projet BLC.
	Global js.
	Version 1.0
	Rev. xxx
*/

var oldslide = null;

function videofancybox()
{
	$("a#inline").fancybox(
	{
		'width': '640px',
		'height': '385px',
		'overlayColor' : '#000010',
		'overlayOpacity' : '0.8',		
		'onStart' : videoShowed,
		'onClosed' : videoClosed
	});
}

function onYouTubePlayerReady(playerId) 
{	
	ytplayer = document.getElementById("myytplayer");
	if ( playVideo )
		ytplayer.playVideo();
}

function videoShowed()
{
	$('#data').html('<object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/CD_bdQJFiG8?fs=1&amp;hl=fr_FR&amp;rel=0&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/CD_bdQJFiG8?fs=1&amp;hl=fr_FR&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>');
}

function videoClosed()
{
	$('#data').html('');
}

function menuEffects()
{
	/* Menu */
	$('a.menuwitharrow').hover ( function() {$('img', this).attr('src', 'images/darkarrow.png');}, function() {$('img', this).attr('src', 'images/lightarrow.png');} );			
	$('a.submenuwitharrow').hover ( function() { $(this).css('background-image', "url('images/darkarrow.png')"); }, function() { $(this).css('background-image', "url('images/lightarrow.png')"); } );
	
	$('#nextlink a').hover ( function() {$('img', this).attr('src', 'images/dark2arrow.gif');}, function() {$('img', this).attr('src', 'images/light2arrow.gif');} );			
	
	$('#mainNav').hover(
		function()
		{
			$('span', this).html('<img class="leftarrow" src="images/botarrow.gif" width="10" height="7" alt="" />');
			$('#subnav').stop(true, true).slideDown(600, 'easeOutCirc', function(){});
		},
		function()
		{
			$('span', this).html('<img class="leftarrow" src="images/darkarrow.png" width="7" height="11" alt="" />'); 
			$('#subnav').stop(true, true).slideUp(600, 'easeOutCirc', function(){});				
	});		
}

function avisEffects()
{
	$('#aviscycle a').click( function ()
	{
		$('#aviscycle').cycle('pause');
		$('#aviscyclewrapper').hide();

		avisIdx = parseInt($(this).attr('id').substring(4)) ; // Get the id.
		$('#avispage' + avisIdx).show();
		$('#avispage').show();
		return false;
	});

	$('#avislist').click( function()
	{
		$('#avispage' + avisIdx).hide();
		$('#avispage').hide();
		$('#aviscyclewrapper').show();
		$('#aviscycle').cycle('resume');
		return false;
	});

	$('#avisprev').click( function()
	{
		if ( avisIdx == 0 )
		{
			$('#avispage' + avisIdx).fadeOut('fast', function()
			{
				avisIdx = nbAvis;
				$('#avispage' + avisIdx).fadeIn('fast');
			});
		}
		else
		{
			$('#avispage' + avisIdx).fadeOut('fast', function()
			{
				avisIdx--;
				$('#avispage' + avisIdx).fadeIn('fast');
			});
		}
		return false;
	});

	$('#avisnext').click( function()
	{
		if ( avisIdx == nbAvis )
		{
			$('#avispage' + avisIdx).fadeOut('fast', function()
			{
				avisIdx = 0;
				$('#avispage' + avisIdx).fadeIn('fast');
			});
		}
		else
		{
			$('#avispage' + avisIdx).fadeOut('fast', function()
			{
				avisIdx++;
				$('#avispage' + avisIdx).fadeIn('fast');
			});
		}
		return false;
	});
}

function initFade( items )
{
	delai = 0;
	for ( idx = 0; idx < items.length; idx++ )
	{		
		$('.block' + items[idx]).delay(delai).fadeIn(900);
		delai += 300;
	}
}

function initCycle()
{
	$('#banner').delay(1500).cycle({        
		fx:     'fade',
        speed:  1000,
        timeout: 10000,
		before:  aftercycle,  // transition callback (scope set to element that was shown):  function(currSlideElement, nextSlideElement, options, forwardFlag
        pager:  '#bannernav'        
    });
}

function initCycleAvisPage()
{	
	$('#aviscycle').delay(3000).queue( function ()
	{
		$('#aviscycle').cycle(
		{
			//cleartype: false,
			cleartypeNoBg:true,
			fx:     'turnUp',
			timeout: 12000,
			speed:  1000,        
			pager:  '#avispagenav'
		});
		
		$('#avispagenav a').last().css('border-right', 'none');
	});
}

function aftercycle(currSlideElement, nextSlideElement)
{	
	if ( oldslide != null )
		$('#slide' + oldslide.id).fadeOut('fast');
	
	$('#slide' + nextSlideElement.id).fadeIn('fast');
	oldslide = 	nextSlideElement;
}
