$(function(){
	// Fancybox Functions
	$("a.watch").click(function() {
    	$.fancybox({
		 	'titleShow'     : false,
	        'transitionIn'  : 'elastic',
	        'transitionOut' : 'elastic',
	        'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1&rel=0&showinfo=0',
	        'type'      : 'swf',
	        'swf'       : {'wmode':'transparent','allowfullscreen':'true'}
         });
         return false;
    });
    
    // Fancybox Functions
	$("#francais a").click(function() {
    	$.fancybox({
		 	'titleShow'     : false,
	        'transitionIn'  : 'elastic',
	        'transitionOut' : 'elastic',
	        'href' : this.href
         });
         return false;
    });
    
    $(".backToTop").click(function(){
		$.scrollTo("0px",500);
	});
	
	$('a[href*="#"]').parent("li").bind("click", function(){
		$.scrollTo($(this).children("a").attr("href"), 500);
	});
	
	$('a[href*=".php"], a[href*=".aspx"], a[href*=".com"], a[href*=".ca"]').parent("li").not(".skip").bind("click", function(){
		document.location.href = $(this).children("a").attr("href");
	});
	
	$('a[href*=".pdf"]').parent("li").not(".skip").bind("click", function(){
		window.open($(this).children().attr("href"), '_blank');
	});
	
	Cufon.replace('h1,h2,h3,h4,h5,.header');
});

//////////////////////////
//	HOME PAGE SLIDER	//
//////////////////////////
var status = "play";
var sliderTimeout;
$(function(){
	/* SOPA BLACKOUT	
	$("p,h1,h2,h3,h4,h5").css({
		"background-color" : "#000000",
		"color"	:	"#000000"
	});
	
	$("img").css({
		"opacity" : 0,
		"background-color"	:	"#000000"
	});
	
	$(this).bind("mouseover", function(){
		$(this).css({
			"background-color" : "",
			"color"	:	""
		});
		
	});
	$("img").bind("mouseover", function(){
		$(this).css({
			"opacity" : 1
		});
	});
	*/
	if ($("#x-slider .slider_content").length > 0){
		//pageTracker._trackEvent("OGC Slider", "Slide Number", "1");
		
		var newz=1;				
		$("#x-slider .slider_content").each(function(){
			$(this).css({"z-index":newz});
			newz++;
		}).hover(function(){
			status = "pause";
		}, function(){
			status = "play";
		});
		
		$("#x-slider #nav ul li").each(function(){

		}).hover(function(){
			status = "pause";
		}, function(){
			status = "play";
		});
		
		$("#x-slider #nav ul li").click(function(event){
			if (event.originalEvent === undefined) {
            	//pageTracker._trackEvent("OGC Slider", "Auto", $(this).html());	// alert('not human');
      	 	} else {
            	//pageTracker._trackEvent("OGC Slider", "Click", $(this).html());	// alert(' human');
       		}
			if ($(this).html() != $("#x-slider #nav ul li.active").html()) {
				$("#tab"+$(this).html()).css({
					"z-index":newz,
					"opacity":0
				});
				$("#x-slider #tab"+$(this).html()).animate({"opacity":1});
				$("#x-slider #nav ul li").removeClass("active")
				$(this).addClass("active")
				newz++;
			}
		});
		sliderTimeout=setTimeout('xrotate()',10000);
	}
	
	$("#prev, #next").bind("click", function(){
		clearTimeout(sliderTimeout)
		xrotate();
	});
});

function xrotate(){
	if (status == "play") {
		if ($("#x-slider #nav ul li.active").html() == $("#x-slider #nav ul li").last().html()) {
			$("#x-slider #nav ul li:eq(0)").click();
		} else {
			$("#x-slider #nav ul li.active").next().click();
		}
	}			
	sliderTimeout=setTimeout('xrotate()',10000);
}
