﻿// OnLoad
$(function(){
	initCycles();
	initLightBox();
	initExternalLinks();
	//initAccordion();
});

/*********************************************************************************/
function initCycles()
{
	// Bandeau
	if ($('#frontphoto').length)
	{
		$('#frontphoto').cycle({
			fx: 'fade', // choose the fade transition type
			random : 1,
			timeout: 6000 // X second delay between fade in and fade out
		});
	}
	
	
	
	// Page des réalisations
	if ($('#ScrollEmp').length)
	{
		$('#ScrollEmp').cycle({
			fx: 'fade', // choose the fade transition type
			random : 1,
			timeout: 6000 // X second delay between fade in and fade out
		});
		
		$('#BtnScrollPrec').bind('click', function(){
								$('#ScrollEmp').cycle('prev');
								return false;
							});
		$('#BtnScrollPause').bind('click',  function(){
								$('#ScrollEmp').cycle('pause');
								$("#BtnScrollPause").css('visibility','hidden');
								$("#BtnScrollPlay").css('visibility','visible');
								return false;
							});
		$('#BtnScrollPlay').bind('click',  function(){
								$('#ScrollEmp').cycle('resume');
								$("#BtnScrollPlay").css('visibility','hidden');
								$("#BtnScrollPause").css('visibility','visible');
								return false;
							});
		$('#BtnScrollSuiv').bind('click',  function(){
								$('#ScrollEmp').cycle('next');
								return false;
							});
	}
}


function initAccordion()
{
	// Default state
	$('div.accordion> div').each(function() {
		$(this).hide();
		$(this).addClass('content');
	});
	
	$('div.accordion> h3').each(function() {
		$(this).addClass('default');
	});
	
	// Triggers
	$('div.accordion> h3').click(function() {
		if( $(this).next().is(':hidden') ) 
		{ 
			$('div.accordion> h3').removeClass('active').next().slideUp(); 
			$(this).toggleClass('active').next().slideDown(); 
		}
		else
		{
			$('div.accordion> h3').removeClass('active').next().slideUp(); 
		}
		return false;
	});
}


function initLightBox()
{
	$('#RealisationsScreens a').lightBox();
	
	// Download image/fichier
	$("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.gif'],a[href$='.png']").click(function() {
		_gaq.push(['_trackEvent', 'download', 'Images' ,"'" + this.href + "'"]);
	});
	
	$("a[href$='.zip'],a[href$='.exe']").click(function() {
		_gaq.push(['_trackEvent', 'download', 'Fichiers' ,"'" + this.href + "'"]);
	});
}

function initExternalLinks()
{
	$("a[href^=http]").not('a[href*="andyharvey.ca"]').click(function() {
		_gaq.push(['_trackEvent', 'outgoing', 'Links' ,"'" + this.href + "'"]);
	});
	
	/*$("a[rel*='ext']").click(function(){
		pageTracker._trackPageview('/outgoing/'+ $(this).attr('href'));
	});*/
}

