$(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');
    $('.ddsmoothmenu ul li a').css("background-color","#000000");
    $('.ddsmoothmenu ul li a')
    .mouseover(function(){ 
        $(this).stop().animate(
            {backgroundColor: color}, 
            {duration:1000})
        }) 
    .mouseout(function(){ 
        $(this).stop().animate(
            {backgroundColor: '#000000'}, 
            {duration:100}) 
        }) 
    
    $('.ddsmoothmenu ul li ul li a').css("background-color","#000000");
    $('.ddsmoothmenu ul li ul li a')
    .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");
    }) 
    $('.news-details-over').bind('mouseleave', function(e) {
			hide_news_details();
	});
    // hide news detail onmouseout
   /* $('.news-details-over').mouseout(function(e){
    		try {
		        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) {
	var $active = $('#slideshow_'+id+' IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow_'+id+' IMG:last');

   var $next =  $active.next().length ? $active.next()
        : $('#slideshow_'+id+' IMG:first-child');     
    //var $next =  active.next().length ? active.next(): $('#slideshow_'+id+' img:first-child'); 
        
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

}


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(300,function(){  
               if(ii == undefined || ii == ''){  
                obj = null;
            }
            else{  
                obj=$('#submenu-item'+ii+'');
                obj.slideDown(1000);
            }});
    }
    else if(ii != undefined && ii != null){     
        obj=$('#submenu-item'+ii+'');
        obj.slideDown(1000);   
    }
}

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("_");
	save_link_clicked(id[0]);
	
    $('#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);   
	
	// image slideshow

	setInterval("slide_switch("+id[0]+")", 3000 );
}

function view_music_details(fiche,artist)
{
    $('#music-details').html($('#theme_artist_'+fiche).html());
    $('#music-details-transparent').show();
    $('#music-details').show();
    setInterval("slide_switch("+fiche+")", 3000 );
} 

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);    
    //$('.news-details-over').show();
}

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); 
        //$('.news-details-over').hide();         
    }
}

function save_link_clicked(id) {
	$.ajax({
        url: js_base_url+'home/save_link_clicked/'+id,
        type:'GET',
        dataType:'json',   
        error: function(data,status){
            // alert(status);      
        },
        success: function(data){
            
        }
    });	
}

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();   
}
