$('document').ready(function(){
    $("#bigThumb").load(function(){
        bigThumbPlacement();
    });
    zoom($("#bigThumb").attr('src'));
});

function zoom(element){
    $("#bigThumb").css('visibility', 'hidden');
    currentViewGotoPictures();
    $("#bigThumb").attr('src',element.replace(/\"/gi, ''));
}

function bigThumbPlacement(){
    var thumbHeight = '';
    var thumbWidth = '';
    $('#bigThumb').css('height',thumbHeight);
    $('#bigThumb').css('width',thumbWidth);
    if( $('#bigThumb').height() > $('#zoom').height() ){
        thumbHeight = $('#zoom').height()+'px';
    }
    $('#bigThumb').css('height',thumbHeight);
    if( $('#bigThumb').width() > $('#zoom').width() ){
        thumbHeight = '';
        thumbWidth = $('#zoom').width()+'px';
    }
    $('#bigThumb').css('height',thumbHeight);
    $('#bigThumb').css('width',thumbWidth);
    
    var diff = Math.max($('#zoom').height()-$('#bigThumb').height(),0);
    $('#bigThumb').css('margin-top',diff/2);
    $("#bigThumb").css('visibility', 'visible');
}

var startTeaserDisplay = 'block';
var startZoomDisplay = 'block';
function currentViewGotoVideos(){
    var teasers = $('.profile_teasers');
    currentViewGoto(teasers[0]);
    $('#teaser').css('display',startTeaserDisplay);
}
function currentViewGotoPictures(){
    var pictures = $('.profile_pictures');
    currentViewGoto(pictures[0]);
    $('#zoom').css('display',startZoomDisplay);
}
function currentViewGoto( element ){
    if($('#zoom').css('display') != 'none') startZoomDisplay = $('#zoom').css('display');
    if($('#teaser').css('display') != 'none') startTeaserDisplay = $('#teaser').css('display');
    $('#zoom').css('display','none');
    $('#teaser').css('display','none');
    if( element && element.id != "currentView" ){        
        var tabsDiv = window.document.getElementById('profile_tabs');
        var tabs = tabsDiv.getElementsByTagName('a');
        for( var tabIndex in tabs ){
            tabs[tabIndex].id = "";
        }
        element.id = "currentView";
    }
}

// affichage de la video
function showTeaser( url, livePicture, addConfig ){
    var show = false;
    if( url != '' ){
        show = true;
        currentViewGotoVideos();
        startStreaming(url, 'teaser', livePicture, addConfig);
    }
    return show;
}
