/*
 * Description :
 * Author : Samuel RODIER
 * Created : 20111007
 */



// Patch HTML5 pour Internet Explorer
if( navigator.appName == 'Microsoft Internet Explorer' )
{
    document.createElement("header");
    document.createElement("footer");
    document.createElement("section");
    document.createElement("aside");
    document.createElement("nav");
    document.createElement("article");
    document.createElement("figure");
    document.createElement("figcaption");
    document.createElement("hgroup");
    document.createElement("time");
}


// Ouvre un popup pour impression d'un attrait
function htmlPrintJob( iAttractionId )
{
    $('div.ui-dialog').remove();
    var sPrintUrl = '/attraction.php?id=' + iAttractionId;
    /*var sConfig = 'resizable=no, location=no, width=600, height=700, menubar=no, status=no, scrollbars=yes, menubar=no';
    window.open( sPrintUrl, '', sConfig );*/
    var eDivContainer = $( '<div></div>' );
    eDivContainer.attr( 'id', 'PrintJob' );
    eDivContainer.css( 'width', '100%' );
    var eFrame = $( '<iframe></iframe>' );
    eFrame.attr( 'id', 'PrintFrame' );
    eFrame.css( 'width', '99.5%' );
    eFrame.css( 'height', '98%' );
    eFrame.attr( 'src', sPrintUrl );
    eDivContainer.append( eFrame );
    $('body').append( eDivContainer );
    $( '#PrintJob' ).dialog({
        title: 'Imprimer l\'attrait',
        autoOpen: true,
        modal: true,
        width: 800,
        height: 700,
        buttons: {
            //Imprimer: function() { var eIFrame = document.getElementById('PrintFrame');eIFrame.focus();eIFrame.print(); },
            Fermer: function() {$(this).dialog( 'close' );}
        }
    });
    
}


// Ouvre un popup permettant de s'enregistrer comme visiteur
function RegisterVisitor()
{
    var sFormUrl = '/registervisitor.php';
    window.location = sFormUrl;
}

// Ouvre un popup permettant de réinitialiser un mot de passe
function RetrievePassword()
{
    var sFormUrl = '/resetpasswd.php';
    window.location = sFormUrl;
}


// Fournit les éléments nécessaires au flash pour loger l'utilisateur
function AutoLogin( mail, password )
{
    var app = document.getElementById( 'myAlternativeContent' );
    app.autoLoginUser( mail, password );
}


// RS : 2011/11/21
// Mise en place des liens sociaux...
$( document ).ready(function(){
    // En cas de click sur un des boutons sociaux
    $( '#followUs ul>li>a.Button' ).click(function(event){
        event.preventDefault();
        var sDivReference = $(this).attr( 'href' );
        $( '#followUs div.Feeds' ).hide();
        $( sDivReference ).show();
        $( '#followUs ul>li>a.Button' ).removeClass( 'Selected' );
        $(this).addClass( 'Selected' );
    });
});


// RS : 2011/11/28
// Mise en place des liens externes
$( document ).ready(function(){
    $( 'a.External' ).click(function(){
        $(this).attr( 'target', '_blank' );
    });
});


// RS : 2011/12/02
// Mise en place des sous menus
var iFadeDelay = 250;
$( document ).ready(function(){
    $( '#primary li' ).hover(function(){
        $(this).children( 'ul' ).fadeIn( iFadeDelay );
        $( this ).mouseleave(function(){
            $(this).children( 'ul' ).fadeOut( iFadeDelay );
        });
    });
    
});


// RS : 2011/12/12
// Recherche via Google
$( document ).ready(function(){
    // Lancement d'une recherche
    $( '#frmSearch' ).submit(function(event){
        event.preventDefault();
        var sSearch = $( 'input[name=Search]' ).val();
        var sSite = $( 'input[name=Site]' ).val();
        sSearch += '+site:' + sSite;
        location = 'http://www.google.com/search?q=' + sSearch;
    });
    // Réinitialisation du champ de recherche
    $('#srch_clear').click(function(){
        $( 'input[name=Search]' ).val('');
    });
});
