﻿// JavaScript Document
jQuery.noConflict();

jQuery(document).ready(function () {

    //Detect if user surf with an iphone|ipod|ipad
//    var deviceAgent = navigator.userAgent.toLowerCase();
//    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
//    if (agentID) {
//        if (confirm("Click OK to download our application")) { document.location = "http://itunes.apple.com/fr/app/angry-birds/id343200656?mt=8"; }
//    }
jQuery('#nav_main ul li').mouseover(function(){
if(jQuery(this).children('ul').hasClass('relative') && (!(jQuery.browser.msie)|| (jQuery.browser.version > 7.9999))){ jQuery(this).children().css('margin-left', -jQuery(this).width())
       }
})





    // Main navigation
    jQuery('#nav_main li').hoverIntent({
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 100,   // number = milliseconds of polling interval (we don't need this as it is initiated on click rather than hover)
        over: level2show,  // function = onMouseOver callback (required)
        timeout: 200,   // number = milliseconds delay before onMouseOut function call
        out: level2hide    // function = onMouseOut callback (required)
    })
    jQuery('#nav_main li ul li').hoverIntent({
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 100,   // number = milliseconds of polling interval (we don't need this as it is initiated on click rather than hover)
        over: level3slideDown,  // function = onMouseOver callback (required)
        timeout: 200,   // number = milliseconds delay before onMouseOut function call
        out: level3slideUp    // function = onMouseOut callback (required)
    })

    jQuery(".nav_main-level2 > li:last-child").css({ "border-right": "0" })
    jQuery(".nav_main-level3 > li:last-child").css({ "border-bottom": "0" })

    // Top Slideshow // Slides : http://www.slidesjs.com/ 
    jQuery('#slides').slides({
        preload: true,
        generateNextPrev: false,
        play: 7500,
        hoverPause: true
    });


    /* Constructor for dropdown perso | set the classes .bghover-grey or .bghover-dark, .autoWidth and .scrollbar if needed */
    /* grey dropdown perso for the homepage ONLY (padding-top is for debugging in IE7) */
    jQuery('select.dropdown_ecco_home').multiselect({
        header: false,
        multiple: false,
        height: "auto",
        minWidth: "auto",
        selectedList: 1, // 0-based index
        noneSelectedText: "All News",
        classes: "bghover-grey autoWidth padding-top"
    });


    /* grey dropdown perso for other page*/
    jQuery('select.dropdown_ecco').multiselect({
        header: false,
        multiple: false,
        height: "auto",
        minWidth: "auto",
        selectedList: 1, // 0-based index
        noneSelectedText: "All News",
        classes: "bghover-grey autoWidth"
    });
    /* dark dropdown perso for footer*/
    jQuery('select.dropdown_footer').multiselect({
        header: false,
        multiple: false,
        position: {
            my: 'left bottom',
            at: 'left top'
        },
        height: "auto",
        minWidth: "auto",
        selectedList: 1, // 0-based index
        noneSelectedText: "",
        classes: "bghover-dark"
    });
    /* Constructor for dropdown perso MULTIPLE (width checkboxes) in search results */
    jQuery(".dropdown_section").multiselect({
        multiple: true,
        selectedList: 1, // 0-based index
        minWidth: "auto",
        height: "auto",
        selectedText: "Section (#)",
        noneSelectedText: "Section",
        checkAllText: "All",
        uncheckAllText: "None",
        classes: "bghover-dark scrollbar"
    });
    jQuery(".dropdown_type").multiselect({
        multiple: true,
        selectedList: 1, // 0-based index
        minWidth: "auto",
        height: "auto",
        selectedText: "Type of content (#)",
        noneSelectedText: "Type of content",
        checkAllText: "All",
        uncheckAllText: "None",
        classes: "bghover-dark autoWidth"
    });
    /* Constructor for dropdown perso MULTIPLE (width checkboxes) in ecco tv search webcast */
     jQuery(".dropdown_bycongress").multiselect({
        multiple: true,
        selectedList: 1, // 0-based index
        minWidth: "auto",
        height: "auto",
        selectedText: "Tracks (#)",
        noneSelectedText: "Tracks",
        checkAllText: "All",
        uncheckAllText: "None",
        /*use these open/close callbacks ONLY if we call autoWidth AND scrollbar classes*/
        open: addScrollBarWidth,
        close: removeScrollBarWidth,
        classes: "bghover-dark autoWidth scrollbar"
    });
    jQuery(".dropdown_byspeciality").multiselect({
        multiple: true,
        selectedList: 1, // 0-based index
        minWidth: "auto",
        height: "auto",
        selectedText: "Sessiontypes (#)",
        noneSelectedText: "Sessiontypes",
        checkAllText: "All",
        uncheckAllText: "None",
        classes: "bghover-dark autoWidth scrollbar"
    });
    jQuery(".dropdown_sessiontype").multiselect({
        multiple: true,
        selectedList: 1, // 0-based index
        minWidth: "auto",
        height: "auto",
        selectedText: "Types (#)",
        noneSelectedText: "Types",
        checkAllText: "All",
        uncheckAllText: "None",
        classes: "bghover-dark"
    });




    // Horizontal members // Jcarousel : http://sorgalla.com/jcarousel/ 
    jQuery('#mycarousel_members,.mycarousel_tv').jcarousel({
        scroll: 1
    });
    // Vertical Events calendar
    jQuery('#mycarousel_calendar').jcarousel({
        vertical: true,
        scroll: 1
    });
    // Horizontal gallery
    jQuery('#mycarousel_details_gallery').jcarousel({
        scroll: 1
    });
    // Horizontal date filter
    jQuery('#mycarousel_datefilter').jcarousel({
        scroll: 1
    });

    // Popin Google map // Fancybox : http://fancybox.net/
    jQuery('#popin_map').fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'autoScale': 'true',
        'type': 'iframe'
    });
	    jQuery('.popin_photo').fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'autoScale': 'false',
        'type': 'iframe',
        'height': 629,
        'width': 960
    });
    // Popin Roundtable TV
    jQuery('#popin_tv').fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'autoScale': 'false',
        'type': 'iframe',
        'height': 629,
        'width': 830
    });
	
    jQuery('#popin_tv1').fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'autoScale': 'false',
        'type': 'iframe',
        'height': 629,
        'width': 830
    });
    jQuery('.view_webcast').fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'autoScale': 'false',
        'type': 'iframe',
        'height': 629,
        'width': 830
    });

    // Alerts ticker // http://www.codeunit.co.za/2010/01/18/a-jquery-horizontal-scrolling-news-ticker/ 
    jQuery('ul#alerts').liScroll();

    // Emulates the placeholder attribute for web browsers that do not natively support it
    jQuery('input').placeholder();

    // Login box
    jQuery('#btn_login').click(function () {
        jQuery('#plannerbox').hide();
        jQuery('#loginbox').fadeIn(500);
        jQuery('#loginbox .close').click(function () {
            jQuery('#loginbox').fadeOut(500);
        })
    })

    // Congress planner box
    jQuery('#btn_planner').click(function () {
        jQuery('#loginbox').hide();
        jQuery('#plannerbox').fadeIn(500);
        jQuery('#plannerbox .close').click(function () {
            jQuery('#plannerbox').fadeOut(500);
        })
    })

    // Congress planner box - Hide (Collapse) the toggle containers on load
    //jQuery(".toggle_container").hide();
    jQuery("#plannerbox .trigger").removeClass("trigger").addClass("active");
    // Congress planner box - Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
    jQuery("h5.trigger").live('click', function () {
        jQuery(".toggle_container").hide();
        jQuery("#plannerbox .active").removeClass("active").addClass("trigger");
        jQuery(this).removeClass("trigger").addClass("active").next().slideToggle("slow");
        //return false; //Prevent the browser jump to the link anchor
    })
    jQuery("h5.active").live('click', function () {
       jQuery(".toggle_container").hide();
      jQuery(this).removeClass("active").addClass("trigger");
        return false; //Prevent the browser jump to the link anchor
   })

    // Congress planner box > Agenda // Jcarousel 
    jQuery('#mycarousel_plannerbox1').jcarousel({
        vertical: true,
        scroll: 5,
        animation: "slow"
    });
    // Congress planner box > Abstracts // Jcarousel 
    jQuery('#mycarousel_plannerbox2').jcarousel({
        vertical: true,
        scroll: 5,
        animation: "slow"
    });
    // Congress planner box > Exhibitors // Jcarousel 
    jQuery('#mycarousel_plannerbox3').jcarousel({
        vertical: true,
        scroll: 5,
        animation: "slow"
    });

    // Validation Spry for Login box
    //var spryEmail = new Spry.Widget.ValidationTextField("tfv_login", "custom", { validateOn: ["blur"] });
   // var spryPassword = new Spry.Widget.ValidationPassword("tfv_password", { validateOn: ["blur"] });

 
    //Full size background for IE8/IE7 compatibility

    if (jQuery('body#home').length > 0) {
        jQuery('body#home').bgStretcher({ images: ['/img/ml/bg_home.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub1').length > 0) {
        jQuery('body#rub1').bgStretcher({ images: ['/img/ml/bg_rub1.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub2').length > 0) {
        jQuery('body#rub2').bgStretcher({ images: ['/img/ml/bg_rub2.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub3').length > 0) {
        jQuery('body#rub3').bgStretcher({ images: ['/img/ml/bg_rub3.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub4').length > 0) {
        jQuery('body#rub4').bgStretcher({ images: ['/img/ml/bg_rub4.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub5').length > 0) {
        jQuery('body#rub5').bgStretcher({ images: ['/img/ml/bg_rub5.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub6').length > 0) {
        jQuery('body#rub6').bgStretcher({ images: ['/img/ml/bg_rub6.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub7').length > 0) {
        jQuery('body#rub7').bgStretcher({ images: ['/img/ml/bg_rub7.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#rub8').length > 0) {
        jQuery('body#rub8').bgStretcher({ images: ['/img/ml/bg_rub8.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#ecco16_home').length > 0) {
        jQuery('body#ecco16_home').bgStretcher({ images: ['/img/ml/bg_rub8.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
    if (jQuery('body#ecco16').length > 0) {
        jQuery('body#ecco16').bgStretcher({ images: ['/img/ml/bg_rub8.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
	if (jQuery('body#ebcc8').length > 0) {
        jQuery('body#ebcc8').bgStretcher({ images: ['/img/ml/bg_EBCC8.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
	if (jQuery('body#ecco17').length > 0) {
        jQuery('body#ecco17').bgStretcher({ images: ['/img/ml/bg_ECCO17.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
	if (jQuery('body#ecco17_home').length > 0) {
        jQuery('body#ecco17_home').bgStretcher({ images: ['/img/ml/bg_ECCO17.jpg'], imageWidth: 1680, imageHeight: 1142 });
    }
	
	
});
// Equalize section heights when the page is fully loaded (including graphics)
jQuery(window).load(function () {
	var tallest = 0;
	//set layout heights
	//jQuery('#content_detail_narrow, #content_center, #content_sub, #content_main, #content_detail').each(function(){
	jQuery('#content_detail_narrow, #content_center, #content_sub, #content_main, #content_detail').each(function(){
	    var thisHeight = jQuery(this).outerHeight();
	    if (thisHeight > tallest) tallest = thisHeight;
	}).css({
	    'overflow': 'hidden',
	    'height': tallest
	});
	//set restricted area boxes heights
	var tallestBox = 0;
	jQuery('#restricted_area_detail nav ul').children('.box').children('div').each(function(){
	    var thisHeight = jQuery(this).outerHeight();
	    if (thisHeight > tallestBox) tallestBox = thisHeight;
	}).css({
	    'overflow': 'hidden',
	    'height': tallestBox
	});


	
});

//METHOD FOR DROPDOWN PERSO :
//add 18px to the width of dropdown perso that contains checkboxes to display the vertical scrollbar
function addScrollBarWidth(){
	var w = jQuery(".scrollbar .ui-multiselect-checkboxes").width()
	jQuery(".scrollbar .ui-multiselect-checkboxes").css('width',w+18)
}
//remove 18px to the width of dropdown perso that contains checkboxes to hide the vertical scrollbar
function removeScrollBarWidth(){
	var w = jQuery(".scrollbar .ui-multiselect-checkboxes").width()
	jQuery(".scrollbar .ui-multiselect-checkboxes").css('width',w-18)
}

//METHOD FOR MAIN NAVIGATION :
function level2hide() {
	jQuery(this).find('.nav_main-level2').hide(0);
	jQuery(this).find('.nav_main-level3').slideUp('fast');
	jQuery(this).children('a').removeClass('highlight');
}
function level2show() {
	jQuery(this).children('a').addClass('highlight');
	jQuery(this).find('.nav_main-level2').show(150);
}
function level3slideUp() {
	jQuery(this).find('.nav_main-level3').slideUp('fast');
	jQuery(this).children('a').removeClass('highlight');
}
function level3slideDown() {
	jQuery(this).children('a').addClass('highlight');
	jQuery(this).find('.nav_main-level3').slideDown(200);
}

//Print page in new browserwindow and close the window
function PrintWindow(link) {
    var WinPrint;
    WinPrint = window.open(link, '', 'left=0,top=0,width=500,height=400, toolbar=0,scrollbars=1,status=0');
    return false;
}

//whatever was declared in jQuery(document).ready(...) is gone after partial pageload
function pageLoad(sender, args) {
    if (args.get_isPartialLoad()) {
	 		
    // Login box
    jQuery('#btn_login').click(function () {
        jQuery('#plannerbox').hide();
        jQuery('#loginbox').fadeIn(500);
        jQuery('#loginbox .close').click(function () {
            jQuery('#loginbox').fadeOut(500);
        })
    })

    // Congress planner box
    jQuery('#btn_planner').click(function () {
        jQuery('#loginbox').hide();
        jQuery('#plannerbox').fadeIn(500);
        jQuery('#plannerbox .close').click(function () {
            jQuery('#plannerbox').fadeOut(500);
        })
    })

    // Congress planner box - Hide (Collapse) the toggle containers on load
    jQuery(".toggle_container").hide();

    // Congress planner box > Agenda // Jcarousel 
    jQuery('#mycarousel_plannerbox1').jcarousel({
        vertical: true,
        scroll: 5,
        animation: "slow"
    });
    // Congress planner box > Abstracts // Jcarousel 
    jQuery('#mycarousel_plannerbox2').jcarousel({
        vertical: true,
        scroll: 5,
        animation: "slow"
    });
    // Congress planner box > Exhibitors // Jcarousel 
    jQuery('#mycarousel_plannerbox3').jcarousel({
        vertical: true,
        scroll: 5,
        animation: "slow"
    });
	
    }
}
