﻿/**
* hovering over a picture in IE displays the alt attribute
* while FF displays the title attribute. SharePoint and EPiServer
* have a alt field but no title field. The code below create a title
* attribute for all images in the page and fill it out with the content
* of the alt attribute.
**/
$(document).ready(function(){
    $('img[alt]').each(function(i, item){
        $(item).attr("title",item.alt);
    });
});


/* popup function. Applies on any link having class="popup".
* cliking the link will open the link in a pop up windows    
* you can possibly put options in the a tag "title" attribute.
* for instance <a href="page.htm" title="width=600, height=800">open popup</a>
*/
$(document).ready(function() {

    $('.popup').click(function(event) {
        event.preventDefault();
        var link = $(this).attr('href');
        var options = $(this).attr('title');
        window.open(link, 'popup', options);
    });

});



/** 
* ligth Pictures library. Applies to any img wrap within 
* a div element with css class epi_gallery. Hide all photos 
* except the first one. requires ligthBox plugin.
*
* example :
* <div class="epi_gallery">
*	<img src="images/one.png" width="128" height="149" />
*	<img src="images/two.png" width="128" height="149" />
* </div>
*/
$(document).ready(function() {

    // remove the instruction used to create the gallery
    $('.delimiter').hide();

    // removes the brackets located before the first picture
    // and after the last one.
    var photos = $(".epi_gallery").html();
    if (photos != null || photos != undefined){
	    var cleaned = photos.substr(1,photos.length-2);
	    $(".epi_gallery").html(cleaned);
    }
    
    // wrap the img tag with <a /> tag to fulfill 
    // lightBox plugin requirements
    $('.epi_gallery img').each(function() {
        var a = $(document.createElement('a'));
        a.attr('href', $(this).attr('src'));
        $(this).wrap(a);
    });

    // show only the first pictures 
    $('.epi_gallery img').hide();
    $('.epi_gallery img:first').show();
    $('.epi_gallery img:first').css('border', 'solid 1px black');


    // set caption text
    var num = $(document.createElement('div'));
    num.css({ 'font-size': 'small' });
    num.text('click to view the ' + $('.epi_gallery img').length + ' pictures');
    $('.epi_gallery').append(num);

    // start ligthBox plugin
    $('.epi_gallery a').lightBox();
});

