$(document).ready(function() {
	if($(window).height() > 588+44)
	{
		top_margin = ($(window).height() - (588+88))/2;
		$('#body').css('top',top_margin+'px');
	}
	else if($(window).height() >= 588)
	{
		top_margin = ($(window).height() - 588)/2-10;
		$('#body').css('top',top_margin+'px');
	}
	else
	{
		$('#body').css('top','-10');	
	}
	if($(window).width() >= 960)
	{
		left_margin = ($(window).width() - 960)/2;
		$('#body').css('left',left_margin+'px');
	}
	else{
		$('#body').css('left','0');	
	}
	
    var color = $('#menu').css('border-top-color');
    $('.submenu-items div').css("background-color","#000000");
    $('.submenu-item')
    .mouseover(function(){ 
        $(this).stop().animate(
            {backgroundColor: color}, 
            {duration:1000})
        }) 
    .mouseout(function(){ 
        $(this).stop().animate(
            {backgroundColor: '#000000'}, 
            {duration:100}) 
        }) 
         
    $('.music-list-items .inactive')
    .mouseover(function(){
        $(this).removeClass("inactive");
        $(this.parentNode).next().find("div."+$(this).attr("class")+"").removeClass("inactive");
    })
    .mouseout(function(){
        $(this.parentNode).next().find("div."+$(this).attr("class")+"").addClass("inactive");
        $(this).addClass("inactive");
    })
    
    $('.music-details-images img')
    .mouseover(function(){
        $(this).removeClass("inactive");
    })
    .mouseout(function(){
        $(this).addClass("inactive");
    }) 
    // hide news detail onmouseout
    $('#home-right').mouseout(function(e){
    		try {
		        var rel_tg = (e.relatedTarget) ? e.relatedTarget : e.toElement; 
		        if(rel_tg.className == "page_slogan" || rel_tg.id == "home-left"|| rel_tg.id == "home" || rel_tg.id == "content-bg" || rel_tg.id == "content" || rel_tg.id == "logo" || rel_tg.nodeName == "BODY")
		        {
		            hide_news_details();   
		        }
			}
			catch(err) {
			//alert(err.description);
		}
    });
    // hide music details onmouseout
    $('#music-right').mouseout(function(e){
    	try {
	        var rel_tg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	        if (rel_tg != undefined){
	            if(rel_tg.className == "music-page" || rel_tg.id == "content-bg" || rel_tg.id == "content" || rel_tg.id == "logo" || rel_tg.nodeName == "BODY")
	            {
	                hide_music_details();   
	            } 
	        }
	    }
		catch(err) {
			//alert(err.description);
		}
    });  
   
   if($('#contact').length > 0){
   		setTimeout('getMovie("sound").playSound("'+js_base_url+'mp3/Contact.mp3");',1000); 		
   }    
   if($('#info').length > 0){
   		setTimeout('getMovie("sound").playSound("'+js_base_url+'mp3/StyleUniversel.MP3");',1000); 		
   }
   if($('#team').length > 0){
   		setTimeout('getMovie("sound").playSound("'+js_base_url+'mp3/EquipeEngagee.MP3");',1000); 		
   }  
   if($('#sitemap').length > 0){
           setTimeout('getMovie("sound").playSound("'+js_base_url+'mp3/Sitemap.MP3");',1000);         
   }
   if($('#partners').length > 0){
           setTimeout('getMovie("sound").playSound("'+js_base_url+'mp3/Partenaires.MP3");',1000);         
   }
   
   $('.artist-details-col1 img.song').each(function (){
        $(this).attr('src',js_base_url+'/img/songs.png');
        $(this).unbind('click',stop_artist);
        $(this).bind('click',{elem: this},play_artist);    
    });
}); 


function slide_switch(id) {
    active = $('#'+id+' img.active');    
    //if ( active.length == 0 ) active = $('#'+id+' img:last');
    setTimeout("next =  active.next().length ? active.next(): $('#"+id+" img:first-child')",300); 
    setTimeout("next.addClass('active')",600);
    setTimeout("active.removeClass('active')",600);
}


var obj =null;
var ii;
function show_submenu(element){                  
    // get submenu index
    submenu_index = $('.menu-item').index(element)+1; 
    ii = submenu_index;
    set_submenus_size();
    set_menu_pos(submenu_index);      
    hide_submenu();
}
           
function hide_submenu(){ 
        if(obj != null && obj != undefined){ 
            obj.slideUp("slow",function(){  
               if(ii == undefined || ii == ''){  
                obj = null;
            }
            else{  
                obj=$('#submenu-item'+ii+'');
                obj.slideDown("slow");
            }});
    }
    else if(ii != undefined && ii != null){     
        obj=$('#submenu-item'+ii+'');
        obj.slideDown("slow");   
    }
}

function hide_submenus(){
    ii = null;
    hide_submenu();
    /*if(obj != null && obj != undefined){ 
            obj.slideUp("slow",function(){ 
               
            });
    }      */
}

function set_submenus_size(){ 
    $('#submenu-item1 div').width($('#menu-item1').width());
    $('#submenu-item2 div').width($('#menu-item2').width());
    $('#submenu-item3 div').width($('#menu-item3').width());
    $('#submenu-item4 div').width($('#menu-item4').width());
    $('#submenu-item5 div').width($('#menu-item5').width());
    $('#submenu-item1 h5').width($('#menu-item1').innerWidth());
    $('#submenu-item2 h5').width($('#menu-item2').innerWidth());
    $('#submenu-item3 h5').width($('#menu-item3').innerWidth());
    $('#submenu-item4 h5').width($('#menu-item4').innerWidth());
    $('#submenu-item5 h5').width($('#menu-item5').innerWidth());     
} 

function set_menu_pos(val){
    switch(val){
        case 1:
        break;
        case 2:  
            p_left = $('#menu-item1').innerWidth();   
            $('#submenu-item'+val+'').css({'position':'absolute','left':p_left});
        break;
        case 3:
            p_left = $('#menu-item1').innerWidth()+$('#menu-item2').innerWidth();
            $('#submenu-item'+val+'').css({'position':'absolute','left':p_left});
        break;
        case 4:
            p_left = $('#menu-item1').innerWidth()+$('#menu-item2').innerWidth()+$('#menu-item3').innerWidth();
            $('#submenu-item'+val+'').css({'position':'absolute','left':p_left}); 
        break;
        case 5:
            p_left = $('#menu-item1').innerWidth()+$('#menu-item2').innerWidth()+$('#menu-item3').innerWidth()+$('#menu-item4').innerWidth();
            $('#submenu-item'+val+'').css({'position':'absolute','left':p_left}); 
        break;
    }
}

var artist_id = 0;
var file = "";
function show_music_details(element)
{
    id = $(element).attr('id').split("_");
    $('#music-details').html($('#theme_artist_'+id[0]).html());
    $('#music-details-transparent').show("slide", { direction: "right" }, 1000);
    $('#music-details').show("slide", { direction: "right" }, 1000);
    artist_id = id[1];
    file = $('#'+id[1]+'').attr('name');
    if(file != "" && file != undefined){
        getMovie('sound').playSound(js_base_url+'mp3/'+artist_id+'/'+file);
    } 
    else{
        getMovie('sound').stopSound();
    }
    $('.music-details-icons .song-icon').attr('src',js_base_url+'/img/mute.png');
	$('.music-details-icons .song-icon').unbind('click',play_sound);
	$('.music-details-icons .song-icon').bind('click',{},stop_sound);       
}

function view_music_details(fiche,artist)
{
    $('#music-details').html($('#theme_artist_'+fiche).html());
    $('#music-details-transparent').show();
    $('#music-details').show();
} 

function hide_music_details()
{   
    if ($('#music-details').css("display") != "none") {
        $('#music-details-transparent').hide("slide", { direction: "right" }, 1000);
        $('#music-details').hide("slide", { direction: "right" }, 1000);
        // stop music
        getMovie('sound').stopSound();
        // prepare the icon for next view
        $('.music-details-icons .song-icon').attr('src',js_base_url+'/img/mute.png');
	    $('.music-details-icons .song-icon').unbind('click',play_sound);
	    $('.music-details-icons .song-icon').bind('click',{},stop_sound);
    }
}

function play_sound()
{      
    getMovie('sound').playSound(js_base_url+'mp3/'+artist_id+'/'+file);
    $('.music-details-icons .song-icon').attr('src',js_base_url+'/img/mute.png');
    $('.music-details-icons .song-icon').unbind('click',play_sound);
    $('.music-details-icons .song-icon').bind('click',{},stop_sound);
}

function stop_sound()
{
	//alert("ola");
	$('.music-details-icons .song-icon').attr('src',js_base_url+'/img/songs.png');
    $('.music-details-icons .song-icon').unbind('click',stop_sound);
    $('.music-details-icons .song-icon').bind('click',{},play_sound);
    getMovie('sound').stopSound();
}

/* NOS CONSEILS WINDOW */
function show_advices_details()
{
    $('#music-details').html($('#theme-advices').html());
    $('#music-details-transparent').show("slide", { direction: "right" }, 1000);
    $('#music-details').show("slide", { direction: "right" }, 1000);
}

/* VOS MERCIS WINDOW */
function show_thanks_details()
{
    $('#music-details').html($('#theme-thanks').html());
    $('#music-details-transparent').show("slide", { direction: "right" }, 1000);
    $('#music-details').show("slide", { direction: "right" }, 1000);
}



function play_artist(e)
{     
    // stop all songs            
    $('.artist-details-col1 img.song').each(function (){
        if(this != e.data.elem){
            $(this).attr('src',js_base_url+'/img/songs.png');
            $(this).unbind('click');
            $(this).bind('click',{elem: this},play_artist);    
        }
    });   
    getMovie('sound').playSound(js_base_url+$(e.data.elem).attr('name'));   
    // play selected song       
    $(e.data.elem).attr('src',js_base_url+'/img/mute.png');
    $(e.data.elem).unbind('click');
    $(e.data.elem).bind('click',{elem: e.data.elem},stop_artist); 
}

function stop_artist(e)
{
    $(e.data.elem).attr('src',js_base_url+'/img/songs.png');
    $(e.data.elem).unbind('click');
    $(e.data.elem).bind('click',{elem: e.data.elem},play_artist);
    getMovie('sound').stopSound();  
}

function clear_sound()
{                               
    $('#mp3_list').css('color','#BCBCBC');
}

//  sound flash player functions
function err(variable)
{
    //alert(variable);
}

var movie;
function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        movie = window[movieName];
        return movie;
    } else {
        movie = document[movieName]; 
        return movie;
    }
}

function show_news_details(element)
{            
    $('#home .news-details-text').html($('#news_'+$(element).attr('id')).html());
    $('#news-details-transparent').show("slide", { direction: "right" }, 1000);
    $('#news-details').show("slide", { direction: "right" }, 1000);
}

function hide_news_details()
{
    if ($('#news-details').css("display") != "none") {
        $('#news-details-transparent').hide("slide", { direction: "right" }, 1000);
        $('#news-details').hide("slide", { direction: "right" }, 1000);
    }
}

function show_prompt()
{
    jPrompt('Mot de passe:', '', '', function(pass) {
        if( pass != "" ) {
            $.ajax({
                url: js_base_url+'home/downloadPassword/'+pass,
                type:'GET',
                dataType:'json',   
                error: function(data,status){
                     alert(status);      
                },
                success: function(data){
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                            show_prompt();
                            $('#popup_message').append('<div id="popup_error">' + data.error + '</div>');
                        }
                        else
                        {
                             document.location.href = js_base_url+'home/downloadFile/'; 
                        }
                    }    
                }
            });
        }
        else
        {
            show_prompt();
            $('#popup_message').append('<div id="popup_error">Le champ mot de passe ne peut être vide</div>');
        }
    });
}

function load_home() {
	document.location.href=''+js_base_url+'home';
}

function hideFlash()
{
    $('#flash_content').hide();
    $('#flash_intro').hide();   
}