function toggleDiv(divid) {
    varon = divid + 'full';
    varoff = divid + 'light';

    var el1 = document.getElementById(varon);
    var el2 = document.getElementById(varoff);
    if (el1 != null && el2 != null && el1.style != null && el2.style != null){
        if (el1.style.display == 'inline') {
            el1.style.display = 'none';
            el2.style.display = 'inline';
        } else {
            el2.style.display = 'none';
            el1.style.display = 'inline'
        }
    }
}
/*
TODO: add a mini browser interface
(function(a, b) {
    if (/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile|o2|opera m(ob|in)i|palm( os)?|p(ixi|re)\/|plucker|pocket|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))window.location = b
})(navigator.userAgent || navigator.vendor || window.opera, 'http://www.neomultimedia.ch/clients/unine/test_templates/index_mobile.html');
 */

$(document).ready(function() {
    jQuery("#rightCol .boxitem:first-child").addClass("firstitem");

    $(".fadelogo").hover(function() {
        $(this).attr("src", "/templates/unine_core/images/logo_unine_hover.png");
    }, function() {
        $(this).attr("src", "/templates/unine_core/images/logo_unine.png");
    });
    $(".fadelogofoot").hover(function() {
        $(this).attr("src", "/templates/unine_core/images/logo_unine_footer-hover.png");
    }, function() {
        $(this).attr("src", "/templates/unine_core/images/logo_unine_footer.png");
    });
    $("#portals1 ul li, #portals2 ul li").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });
    $("#portals1 ul li a,#portals2 ul li a").hover(
        function() {
            var imageOut = $(this).css("background-image");
            var imageHover = $(this).attr('rel');
            if (imageHover != null && imageHover != "") {
                $(this).css("background-image",imageHover);
                $(this).attr('rel',imageOut);
            }
        }, function() {
            var imageHover = $(this).css("background-image");
            var imageOut= $(this).attr('rel');
            if (imageHover != null && imageHover != "") {
                $(this).css("background-image",imageOut);
                $(this).attr('rel',imageHover);
            }
        });


    $("#formation,#admission,#recherche,#campus,#facultes").height($("#lists_bloc").height());
    /*$('#middleCol a,#rightCol a').filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    }).append(' <span class="icon_newwin"></span>');*/
    $('#wrapper a').filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    }).attr("target", "_blank");
    $("a[href^='/repository'],a[href^='/files']").addClass("file").attr("target", "_blank");
    $("a[href*='.png'], a[href*='.jpg'], a[href*='.gif']").addClass("img").attr("target", "_blank");
    $("a[href*='.ppt'], a[href*='.pptx']").addClass("ppt").attr("target", "_blank");
    $("a[href*='.xls'], a[href*='.xlsx']").addClass("xls").attr("target", "_blank");
    $("a[href*='.pdf']").addClass("pdf").attr("target", "_blank");
    $("a[href*='.doc'], a[href*='.docx'], a[href*='.txt'], a[href*='.rft']").addClass("txt").attr("target", "_blank");
    $("a[href*='.zip'], a[href*='.rar']").addClass("zip").attr("target", "_blank");
    $("a[href*='mailto:']").addClass("email");
    $(".mediagallery a.file,a.more,.imageBox a").removeClass("file img ppt xls txt zip");
    $("a.file img").parent().removeClass("file pdf xls ppt txt zip email img");
    $(".vignette a img").parent().removeClass("file pdf xls ppt txt zip email img");
    $('#content a').filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    }).addClass("external");
    $(".freeText a.external img").parent().removeClass("external");
    $('a.predefinedImage, .imageBox a.external, .vignettesBox a.external, #subbrowser a.external').removeClass("external");
    $('.banner_big.captionfull').hover(function() {
        $(".cover", this).stop().animate({
            top: '100px'
        }, {
            queue: false,
            duration: 160
        });
    }, function() {
        $(".cover", this).stop().animate({
            top: '150px'
        }, {
            queue: false,
            duration: 160
        });
    });
    $('.banner.caption').hover(function() {
        $(".cover", this).stop().animate({
            top: '140px'
        }, {
            queue: false,
            duration: 160
        });
    }, function() {
        $(".cover", this).stop().animate({
            top: '160px'
        }, {
            queue: false,
            duration: 160
        });
    });
    $("#rightCol .freeText ul,#leftCol .freeText ul").each(function(){
        if (! $(this).hasClass("standard_list") && ! $(this).hasClass("list_events") && ! $(this).hasClass("standard_arrow_list")){
            $(this).addClass("standard_list");
        }
    });
    $("#middleCol .freeText ul").each(function(){
        if (! $(this).hasClass("standard_arrow_list") && ! $(this).hasClass("list_events") && ! $(this).hasClass("standard_list")){
            $(this).addClass("standard_arrow_list");
        }
    });

    /**/
    $('#middleCol ul.accordion').accordion();

    /**/
    $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_square'});
    /**/

    var themeColor;
    jQuery('.fadeThis').hover(
            function () {
                themeColor = jQuery(this).css("color");
                jQuery(this).animate({backgroundColor:'#666666', color:'#ffffff'}, {queue:false,duration:500});
            },
            function () {
                jQuery(this).animate({backgroundColor:'#ffffff', color:''+themeColor}, {queue:false,duration:500});
            });
     $.featureList(
            $("#tabs li a,.tabs li a"),
            $("#output.animatedOutput li"), {
                start_item    :    0
            });


    /*

     // Alternative


     $('#tabs li a,.tabs li a').featureList({
     output			:	'#output li',
     start_item		:	1
     });

     */
    /**/
    //Set opacity on each span to 0%
    $(".rollover").css({'opacity':'0'});

    $('.img_list a').hover(
            function() {
                $(this).find('.rollover').stop().fadeTo(500, 1);
            },
            function() {
                $(this).find('.rollover').stop().fadeTo(500, 0);
            }
            )
    $("#languages").each(
      function() {
        var elem = $(this);
        if (elem.children().length == 0) {
          elem.remove();
            jQuery("#navigation").css("width","960px");
        }
      }
    );

    if ($("#breadcrumbs").children().size() == 0 && $("#bachelors-masters").children().size() == 0) {
        $("#top").remove();
    }

    jQuery(".vignettes li .spacer").hover(function() {
        jQuery(this).css("cursor","pointer");
    });
    jQuery(".vignettes li .spacer").click(function() {
        var rel = jQuery(this).attr('rel');
        if (rel != null) {
            window.location = rel;
        }
    });
    /*
    jQuery('table.style1 tr,#subbrowser li ul li').hover(
            function() {
                jQuery(this).addClass("hover");
            },
            function() {
                jQuery(this).removeClass("hover");
            });
    */
    jQuery('table.style2 tbody tr:odd,table.style3 tbody tr:odd').addClass('odd');
    jQuery('table.style2 tbody tr:even,table.style3 tbody tr:even').addClass('even');
    jQuery('table.style3 td:first-child').addClass("first");
    jQuery('table.style2 td:last-child,table.style3 td:last-child,table.style3 th:last-child').addClass("last");
    jQuery('#middleCol .halfSizeRubricBox:odd').addClass('odd');

    /*
    jQuery("#‡menu").hover(
            function() {
                jQuery("#mega").show();
            });
    jQuery("#mega").mouseleave (
            function() {
                jQuery(this).hide();
            });
     */
    jQuery(".facs > span").hover(
            function() {
                jQuery(".facs > span").removeClass("hover");
                jQuery(this).addClass("hover");
            });
    jQuery("a.fac").hover(function() {
        //jQuery("a.fac").removeClass("hover");
        //jQuery(this).addClass("hover");
        var rel = jQuery(this).attr('rel');
        if (rel != null) {
            jQuery(".unite").hide();
            jQuery("#"+rel).show();
        }
    });

    jQuery("#lists_bloc .foot .spacer").equalHeights(100);
    jQuery("#lists_bloc .foot:nth-child(7)").before("<div class='footseparator'></div>");
    jQuery("#lists_bloc .foot:nth-child(6),#lists_bloc .foot:last-child").addClass("last");
    jQuery('img[align]').each(function(){ jQuery(this).addClass(jQuery(this).attr('align')); });
    jQuery('td[valign]').each(function(){ jQuery(this).addClass(jQuery(this).attr('valign')); });
    jQuery('table[cellpadding]').each(function(){
        if (jQuery(this).attr('cellpadding') > 0) {
            jQuery(this).addClass("p5");
        }
    });

    var vignetteWidth = jQuery(".vignettes").attr("rel");
    if (vignetteWidth != null) {
        if (vignetteWidth < 500) {
            jQuery(".vignettes li:nth-child(3)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(5)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(7)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(9)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(11)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(13)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(15)").addClass("clearleft");
        } else {
            jQuery(".vignettes li:nth-child(4)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(7)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(10)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(13)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(16)").addClass("clearleft");
            jQuery(".vignettes li:nth-child(19)").addClass("clearleft");
        }
    }
    jQuery(".rubricBoxFull li:nth-child(4)").addClass("clearleft");
    jQuery(".rubricBoxFull li:nth-child(7)").addClass("clearleft");
    jQuery(".rubricBoxFull li:nth-child(10)").addClass("clearleft");
    jQuery(".rubricBoxFull li:nth-child(13)").addClass("clearleft");
    jQuery(".rubricBoxFull li:nth-child(16)").addClass("clearleft");
    jQuery(".rubricBoxFull li:nth-child(19)").addClass("clearleft");

    jQuery(".halfSizeRubricBox:odd").append("<div class='clear'></div>");
    $(".dropdownBox select").filter(function(){
        $(this).uniform();
    });
    //$("form.uniform input:checkbox, form.uniform input:radio").uniform();
    $(".new").addClass($("html").attr("lang"));
    if($.trim($("#footer_navigation").text()) == "") {
      $("#footer_navigation").remove();
    }
});


$(function() {
    swapValues = [];
    $(".swap_value").each(function(i) {
        swapValues[i] = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function() {
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });
});

/*
$(function() {
    $(".markedForDelete").remove();
});
 */

$(function() {
    $('#tabs,.tabs').tabs();
});

$(function(){
    //jQuery("ul li:last-child").addClass("last");

    jQuery(".selectionList li:first-child a.item,.subSelectionList li:first-child a.subitem").each(function() {
        jQuery(this).addClass("on");
        jQuery(this.hash).show();
    });

    jQuery(".selectionList a.item").click(function(e) {
        jQuery(".selectionList a.item").removeClass("on");
        jQuery(this).addClass("on");
        jQuery("div.bloc").hide();
        jQuery(this.hash).show();
        e.preventDefault();
    });

    jQuery(".subSelectionList a.subitem").click(function(e) {
        jQuery(".subSelectionList a.subitem").removeClass("on");
        jQuery(this).addClass("on");
        jQuery("div.subbloc").hide();
        jQuery(this.hash).show();
        e.preventDefault();
    });
});

$(function() {
    jQuery("#open").click(function() {
        jQuery.cookie("viewDiapo","true",{ path: '/', expires: 7 });
        //alert("set cookie to " + jQuery.cookie("viewDiapo"));
        toggleDiv("subheader_");
        jQuery("#s1").height(150);
        jQuery("#s1").css("position","relative");
        jQuery("#s1").width(960);
    });
    jQuery("#close").click(function() {
        jQuery.cookie("viewDiapo","false",{ path: '/', expires: 7 });
        //alert("set cookie to " + jQuery.cookie("viewDiapo"));
        toggleDiv("subheader_");
    });
    var viewDiapo = jQuery.cookie("viewDiapo");
    //alert(viewDiapo);
    if (viewDiapo == "false") {
        toggleDiv("subheader_");
    }
});


$(function() {
    $('.freeText2Col').columnize({ columns : 2 })
});

$(function() {
    jQuery('.freeText3Col').columnize({ columns : 3})
});

function formatText(index, panel) {
    return index + "";
}

/*
$(function () {

    $('.anythingSlider').anythingSlider({
        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 3000,                    // How long between slide transitions in AutoPlay mode
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        animationTime: 600,             // How long the slide transition takes
        hashTags: true,                 // Should links change the hashtag in the URL?
        buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
        pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        startText: "Diaporama",             // Start text
        stopText: "Stop",               // Stop text
        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
    });

    $("#slide-jump").click(function() {
        $('.anythingSlider').anythingSlider(6);
    });

});
 */

// wrap as a jQuery plugin and pass jQuery in to our anoymous function
(function ($) {
    $.fn.cross = function (options) {
        return this.each(function (i) {
            // cache the copy of jQuery(this) - the start image
            var $$ = $(this);

            // get the target from the backgroundImage + regexp
            var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

            // nice long chain: wrap img element in span
            $$.wrap('<span style="position: relative;"></span>')
                // change selector to parent - i.e. newly created span
                    .parent()
                // prepend a new image inside the span
                    .prepend('<img>')
                // change the selector to the newly created image
                    .find(':first-child')
                // set the image to the target
                    .attr('src', target);

            // the CSS styling of the start image needs to be handled
            // differently for different browsers
            if ($.browser.msie || $.browser.mozilla) {
                $$.css({
                    'position' : 'absolute',
                    'left' : 0,
                    'background' : '',
                    'top' : this.offsetTop
                });
            } else if ($.browser.opera && $.browser.version < 9.5) {
                // Browser sniffing is bad - however opera < 9.5 has a render bug
                // so this is required to get around it we can't apply the 'top' : 0
                // separately because Mozilla strips the style set originally somehow...
                $$.css({
                    'position' : 'absolute',
                    'left' : 0,
                    'background' : '',
                    'top' : "0"
                });
            } else { // Safari
                $$.css({
                    'position' : 'absolute',
                    'left' : 0,
                    'background' : ''
                });
            }

            // similar effect as single image technique, except using .animate
            // which will handle the fading up from the right opacity for us
            $$.hover(function () {
                $$.stop().animate({
                    opacity: 0
                }, 250);
            }, function () {
                $$.stop().animate({
                    opacity: 1
                }, 250);
            });
        });
    };

})(jQuery);

// note that this uses the .bind('load') on the window object, rather than $(document).ready()
// because .ready() fires before the images have loaded, but we need to fire *after* because
// our code relies on the dimensions of the images already in place.
$(window).bind('load', function () {
    //$('img.fade').cross();
});

//-->





 $(function() {
     $('#subheaderDiaporama #s1').cycle();
     $('#subheaderDiaporama #pauseButton').click(function() {
     $('#subheaderDiaporama #s1').cycle('pause');});
     $('#subheaderDiaporama #resumeButton').click(function() {
     $('#subheaderDiaporama #s1').cycle('resume', true);});
 });

$(function() {
    $('*').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250
    });
});

$(function() {
    $('.rubricBoxHalf + .rubricBoxHalf').addClass("rubricBoxHalfRight");
    var boxes = $('.rubricBoxHalfRight').toArray();
    for (var i=0; i < boxes.length; i++) {
        var box = boxes[i];
        var boxID = "#".concat(box.getAttribute("id"));
        if ($(boxID).prev().hasClass("rubricBoxHalfRight")) {
            $(boxID).removeClass("rubricBoxHalfRight");
        }
    }
});

$.fn.removeCol = function(col){
    // Make sure col has value
    if(!col){ col = 1; }
    $('tr td:nth-child('+col+'), tr th:nth-child('+col+')', this).remove();
    return this;
};

$(function() {
    $('#content .specialBox table').each(function() {
        var nbRemovedCols = 0;
        for(var i=1;i<9;i++) {
            var col = i-nbRemovedCols;
            var empty = true;
            $('tr td:nth-child('+col+'), tr th:nth-child('+col+')', this).each(
                function() {
                    var htmlStr = $(this).html();
                    htmlStr = $.trim(htmlStr);
                    if (htmlStr.length > 0) {
                        empty = false;
                    }
            });
            if (empty) {
                $(this).removeCol(col);
                nbRemovedCols++;
            }
        }
        });
});


