﻿$(document).ready(function() {
    //jQuery("#s4-workspace").height(jQuery(window).height() - jQuery("#s4-ribbonrow").innerHeight(true));
	$("#s4-workspace").height(jQuery(window).height() - 1);

});


// SPLASH IMAGES ================================================================ //
// document ready
$(document).ready(function(){
	medazioSplash();
});

// splash carousel
var medazioSplashEnabled = false;
var medazioSplashImageWidth = 636;
var medazioSplashImageHeight = 284;
var medazioSplashTimer = null;
var medazioSplashTimerDelay = 8000;
function medazioSplash(){
	if($('.medazio-splash').size() > 1){
		$('.medazio-splash:eq(0)').closest('ul').addClass('medazio-splash-slider');
		$('.medazio-splash-slider').wrap('<div class="medazio-splash-wrapper" />');
		$('.medazio-splash-slider').css('position', 'absolute');
		$('.medazio-splash-slider').css('top', '0px');
		$('.medazio-splash-slider').css('left', '0px');
		$('.medazio-splash-slider').css('height', medazioSplashImageHeight + 'px');
		$('.medazio-splash-slider').css('width', ($('.medazio-splash').size() * medazioSplashImageWidth) + 'px');
		var splashNav = $('<ul class="medazio-splash-nav" dir="ltr" />');
		$('.medazio-splash').each(function(i){
			$(this).closest('li').show();
			$(this).closest('li').css('position', 'absolute');
			$(this).closest('li').css('top', '0px');
			$(this).closest('li').css('left', (i * medazioSplashImageWidth) + 'px');
			$(this).closest('li').css('height', medazioSplashImageHeight + 'px');
			$(this).closest('li').css('width', medazioSplashImageWidth + 'px');
			$(splashNav).append('<li><a href="javascript:medazioSplashNext(' + i + ');">' + i + '</a></li>');
		});
		var splashNext = $('<a class="medazio-splash-next" href="#next">Next</a>');
		$(splashNext).click(function(e){
			e.preventDefault();
			medazioSplashNext();
		});
		$('.medazio-splash-wrapper').append(splashNext);
		$('.medazio-splash-wrapper').append(splashNav);
		$('.medazio-splash-nav li:eq(0) a').addClass('selected');
		medazioSplashEnabled = true;
		medazioSplashTimer = setTimeout('medazioSplashNext();', medazioSplashTimerDelay);
	}
}
function medazioSplashNext(i){
	if(medazioSplashEnabled){
		clearTimeout(medazioSplashTimer);
		if(i == null){
			i = ((parseInt($('.medazio-splash-slider').css('left')) * -1) / medazioSplashImageWidth) + 1;
		}
		if(i >= $('.medazio-splash').size()){
			i = 0;
		}
		$('.medazio-splash-nav a').removeClass('selected');
		$('.medazio-splash-nav li:eq(' + i + ') a').addClass('selected');
		medazioSplashEnabled = false;
		
		if(i != 0){
			 $('.medazio-splash-slider').animate({
			left: ((medazioSplashImageWidth * -1) * i) + 'px'
		}, 1200, 'swing', function(){
			medazioSplashEnabled = true;
			medazioSplashTimer = setTimeout('medazioSplashNext();', medazioSplashTimerDelay);
		});
		}
		else{
			$('.medazio-splash-slider').animate({
			left: ((medazioSplashImageWidth * +1) * i) + 'px'
			}, 1200, 'swing', function(){
			medazioSplashEnabled = true;
			medazioSplashTimer = setTimeout('medazioSplashNext();', medazioSplashTimerDelay);
			});
		}
	}
}



// BASIC FUNCTIONS ================================================================ //

$(function () {		
// Manage TopNavBar and QuickLaunch
	$(".menu-vertical ul.root li ul li.selected").parent().parent().children(":first-child").addClass("HeaderHighlight");  
// Add tags in other specifics class for all WP
	$(".s4-ca #SplashImages .s4-wpcell-plain").wrapInner("<div class='CornerWP'></div>");
// Add a 1 pixel to the left of Webpart header (for IE 8-9)
	var calendar = $.trim($('#AsynchronousViewDefault_CalendarView').html());
	if(!calendar){	
		$("#LeftColumn .s4-wpTopTable tr:first-child td:first-child table:first-child").before("<div class='SimuliBkg'></div>");
		$("#LeftColumn .s4-wpTopTable tr.ms-WPHeader td:last-child").after("<td><div class='SimuliBkgRightCorner'></div></td>");
	}

	

if( $.browser.opera ){
  $(".SimuliBkg").css('display', 'none');
  // $(".ms-WPHeaderTdSelection").css('display', 'block!important');
  $(".ms-wpTdSpace").css('display', 'table-cell!important');
  $(".ms-WPHeader td:last-child").addClass("toto").append("<div class='SimuliBkg2'></div>");

  }

// Add tags in Home page left menu
//	$("#StrategicObjectives, #HomeLinks, #Newsroom").wrapInner("<div class='CornerLeftMenu'></div>");
// Add tags in Home page left menu
//	$("#left").wrapInner("<div class='StandardLeftMenu'></div>");

// Add tags MeetingsEvents
//	$("#MeetingsEvents").wrapInner("<div class='CornerMeetingsEvents'></div>");

// Add corners for meetings events
//	$('.CornerWP').prepend('<div class="tl"></div><div class="tr"></div>');
//	$('.CornerWP').append('<div class="bl"></div><div class="br"></div>');

// Curvy corners
//	$('.CornerLeftMenu .ms-WPBody, #MeetingsEvents .ms-WPBody, .WPZone1 .ms-WPBorderBorderOnly, .WPZone1 .ms-WPBorder, #LeftZoneMenu2 .ms-WPBorderBorderOnly, #LeftZoneMenu2 .ms-WPBorder')
//		.parents('.s4-wpTopTable')
//		.wrap('<div id="myBox" class="Corners" />');
//	curvyCorners.addEvent(window, 'load', initCorners);
//	function initCorners() {
//	    var settings = {
//	      tl: { radius: 12 },
//	      tr: { radius: 12 },
//	      bl: { radius: 12 },
//	      br: { radius: 12 },
//	      antiAlias: true
//	    }
//	    curvyCorners(settings, ".Corners");
//	  }
	  
//$('.StandardLeftMenu').wrap('<div id="myBox" class="Corners" />');
//	curvyCorners.addEvent(window, 'load', initCorners);
//	function initCorners() {
//	    var settings = {
//	      tl: { radius: 12 },
//	      tr: { radius: 12 },
//	      bl: { radius: 12 },
//	      br: { radius: 12 },
//	      antiAlias: true
//	    }
//	    curvyCorners(settings, ".Corners");
//	  }

//$('.Corners:first-child').css('padding-bottom', '32px');

// ipad splash image corner management
//if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
//{
//$('.bl').css({'left': '-3px', 'background': 'url("/Design/img/BL_16x16.png") no-repeat left 2px','width': '16px', 'height': '16px'});
//$('.br').css({'right': '-3px', 'bottom': '-3px', 'background': 'url("/Design/img/BR_16x16.png") no-repeat left 0px', 'width': '16px', 'height': '16px'});
//$('.tl').css({'left': '-3px', 'top': '-3px', 'background': 'url("/Design/img/TL_16x16.png") no-repeat left -1px', 'width': '16px', 'height': '16px'});
//$('.tr').css({'right': '-3px', 'background': 'url("/Design/img/TR_16x16.png") no-repeat left -2px', 'width': '16px', 'height': '16px'});
//}

// Add tags to ICAO NewsRoom HomePage WP
	$('html[lang="en-us"] #Newsroom .cbq-layout-main').append('<div class="SeeMore"><a href="/Newsroom">See more ...</a></div>');
	$('html[lang="fr-fr"] #Newsroom .cbq-layout-main').append('<div class="SeeMore"><a href="/Newsroom">En savoir plus ...</a></div>');
		$("#Newsroom .dfwp-item:last-child").children().addClass('noBottomBorder');

// Add tags to ICAO Meetings and Events HomePage WP
	$('html[lang="en-us"] #MeetingsEvents .cbq-layout-main').append('<div class="SeeMore"><a href="/meetings">See more ...</a></div>');
	$('html[lang="fr-fr"] #MeetingsEvents .cbq-layout-main').append('<div class="SeeMore"><a href="/meetings">En savoir plus ...</a></div>');
		$("#MeetingsEvents .dfwp-item:last-child").children().addClass('noBottomBorder');

// Manage last item border for News template
	$(".WPZone1 .dfwp-item:last-child").children().addClass('noBottomBorder');
	
// Add a second link next to Environment on the top Nav bar for Sustainability - See controlesSharepoint.css for the design
	$('html[lang="en-us"] .menu-horizontal ul.dynamic li.dynamic:last-child').append('<span class="SpecTopNavSpan">&nbsp; &<br/></span> <a class="inline SpecTopNav" href="/sustainability">SUSTAINABLE DEVELOPMENT OF AIR TRANSPORT</a>');
	$('html[lang="fr-fr"] .menu-horizontal ul.dynamic li.dynamic:last-child').append('<span class="SpecTopNavSpan">&nbsp; &<br/></span> <a class="inline SpecTopNav" href="/sustainability">DÉVELOPPEMENT DURABLE DU TRANSPORT AÉRIEN</a>');

// "See more..." toogle to show page content field
$('.article-content').hide();
$('.Resume div:last-child').addClass('ResumeDiv');

var contenu = $.trim($('.ResumeDiv').html());
if (contenu == ""){
    $(".ResumeDiv").remove();
    $(".SeeMoreLink").remove();
    $('.article-content').show();
}
if (contenu !== ""){
$('html[lang="en-us"] .ResumeDiv').parent().after('<div class="SeeMoreLink"><a href="javascript: void(0)">See more ...</a></div>');
$('html[lang="fr-fr"] .ResumeDiv').parent().after('<div class="SeeMoreLink"><a href="javascript: void(0)">En savoir plus ...</a></div>');
}

$('.SeeMoreLink').click(function(){		
	$('.ms-formfieldvaluecontainer .SeeMoreLink').hide();
	$('.Resume').hide();
	$('.SeeMoreLink').hide();
	$('.article-content').css('padding', '0 0 10px 0').fadeIn();	
	});

// See more link if we are in edit mode
var contenu2 = $.trim($('.ms-formfieldlabel').html());
if (contenu2 !== ""){
    $(".ResumeDiv").show();
    $(".SeeMoreLink").remove();
    $('.article-content').show().css('padding-bottom', '10px');
}

var contenu3 = $.trim($('.article-content .ms-rtestate-field').html());
if (contenu3 == ""){
    $(".article-content").css('padding-bottom', '0px');
}

// Managment of styles apply to content from old website 	
$('.data').parent().parent().parent().parent().removeAttr('width').removeAttr('border').removeAttr('cellSpacing').removeAttr('cellPadding').removeAttr('bgColor').addClass('OldToNewMain');
$('.OldToNewMain table').removeAttr('width').removeAttr('cellSpacing').removeAttr('cellPadding').addClass('OldToNew');
$('.data table').removeAttr('border').removeAttr('width').removeAttr('cellSpacing').removeAttr('cellPadding').addClass('OldToNew');
$('.ms-rtestate-field table').removeAttr('border').removeAttr('width').removeAttr('cellSpacing').removeAttr('cellPadding').addClass('OldToNew');
$('.ms-rtestate-field hr').removeAttr('color').css({'background-color': '#003D78', 'height': '1px'});
});

// Resize tool for some content pages
function resizeText(multiplier) {
if (mytext.style.fontSize == "") {
mytext.style.fontSize = "0.75em";
}
mytext.style.fontSize = parseFloat(mytext.style.fontSize) + (multiplier * 0.18) + "em";
}

