$(document).ready(function(){


    $("img[@src$=png], div.dropShadow-tbn, div.dropShadow").pngfix();

	
	
	// rollOver function
	$(".rollover").hover(
	function(){
		if($(this).attr("src").indexOf("-active") == -1) {
			var newSrc = $(this).attr("src").replace(".png","-active.png#hover");
			$(this).attr("src",newSrc);
		}
	},
	function(){
		if($(this).attr("src").indexOf("-active.png#hover") != -1) {
			var oldSrc = $(this).attr("src").replace("-active.png#hover",".png");
			$(this).attr("src",oldSrc);
		}
	}
	);
	
	// HORIZONTAL SCROLL
	$.easing.easeOutQuart = function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		};
		
	$.easing.elasout = function(x, t, b, c, d) {
					var s=1.70158;var p=0;var a=c;
					if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
					if (a < Math.abs(c)) { a=c; var s=p/4; }
					else var s = p/(2*Math.PI) * Math.asin (c/a);
					return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		};
	
	$('#scroll').serialScroll(
		{
				items:'li',
				prev:'#left_scroll',
				next:'#right_scroll',
				axis:'x',
				offset:-5, //when scrolling to photo, stop 230 before reaching it (from the left)
				start:0, //as we are centering it, start at the 2nd
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
		}
	);
	$('#scroll_extras').serialScroll(
		{
				items:'ul',
				prev:'#left_scroll',
				next:'#right_scroll',
				axis:'x',
				offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
				start:0, //as we are centering it, start at the 2nd
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
		}
	);
	$('#scroll_opd').serialScroll(
		{
				items:'ul',
				prev:'#left_scroll',
				next:'#right_scroll',
				axis:'x',
				offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
				start:0, //as we are centering it, start at the 2nd
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
		}
	);
	
	///// VERTICAL SCROLL //////
	$('#media_scroll_comm').serialScroll(
		{
				items:'p',
				prev:'.top_scroll',
				next:'.bottom_scroll',
				axis:'y',
				offset:-10, //when scrolling to photo, stop 230 before reaching it (from the left)
				start:0, //as we are centering it, start at the 2nd
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
		}
	);

	
	///// FLASH EMBEDDING //////
	
	$('.audioPlayer').flash(
        { src: "http://monicafreire.com/medias/flash/audioplayer.swf", height: 16, width: 40 },
        { version: 7 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.extrait = $this.attr('id');
            htmlOptions.flashvars.fade = $this.attr('fade');
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('mp3player').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
    
    $('#radiogram').flash(
        { src: "http://monicafreire.com/medias/flash/radiogram.swf", height: 30, width: 175 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.home_artiste_id = $this.attr('rel');
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('radiogram').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
    
    $('.videoPlayer').flash(
        { src: "http://monicafreire.com/medias/flash/video-overview.swf", height: 315, width: 400 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.le_id = $this.attr('id');
            htmlOptions.flashvars.le_type = $this.attr('rel');
            htmlOptions.flashvars.a_run = $this.attr('a_run');
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('flashVideo').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
    
    $('.photoGallery').flash(
        { src: "http://monicafreire.com/medias/flash/image_gallery.swf", height: 550, width: 782 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.xmlFile = 'http://monicafreire.com/inc/php/photo_gallery.php?id_gallery='+$this.attr('id');
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('flashGallery').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
	
	$('.embedBabillard').flash(
        { src: "http://monicafreire.com/medias/flash/monicaBabillard.swf", height: 700, width: 825 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('flashBB').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
    
    $('#anim-envois').flash(
        { src: "http://audiogram.com/envois/anim-envois-audiogram.swf", width: 300, height: 215 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.wmode = 'transparent';
            htmlOptions.flashvars.artistName = 'MONICA FREIRE';
            this.innerHTML = '';
            $(this).addClass('anim-envois').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
    
        $('#logo_audiogram').flash(
        { src: "http://audiogram.com/envois/logo-audiogram.swf", width: 135, height: 28 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('logo_audiogram').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );


	
	// sIFR text replacement    
    $('.ChollaSansBold').flash(
        { 
            src: 'http://monicafreire.com/medias/flash/ChollaSansBold.swf', 
            flashvars: { 
                css: [
                    '* { color: #FFFFF5; }',
                    'a { color: #A41E26; text-decoration: none; }',
                    'a:hover { color: #000000; text-decoration: underline; }'
                ].join(' ')
            }
        },
        { version: 8 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            htmlOptions.wmode = 'transparent';
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	
	$('.ChollaSansRed').flash(
        { 
            src: 'http://monicafreire.com/medias/flash/ChollaSans.swf', 
            flashvars: { 
                css: [
                    '* { color: #A41E26; }',
                    'a { color: #A41E26; text-decoration: none; }',
                    'a:hover { color: #000000; text-decoration: underline; }'
                ].join(' ')
            }
        },
        { version: 8 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = '42px';
            htmlOptions.width = $alt.width();
            htmlOptions.wmode = 'transparent';
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
	
    
    $('.ChollaSans').flash(
        { 
            src: 'http://monicafreire.com/medias/flash/ChollaSans.swf', 
            flashvars: { 
                css: [
                    '* { color: #000000; }',
                    'a { color: #000000; text-decoration: none; }',
                    'a:hover { color: #A41E26; text-decoration: none; }'
                ].join(' ')
            }
        },
        { version: 8 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            htmlOptions.wmode = 'transparent';
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
    
    // SHOW LYRICS
    $('.showLyrics').click(function() {
    	$('.lyrics').hide("fast");
    	var Song = $(this).attr("rel");
    	$.scrollTo('#boxLyrics', 400, { easing:'easeOutQuart' });
    	$('#'+Song).show("slow");
    	return false;
   	});
   	
	// SHOW MEDIA
    $('.showMedias').click(function() {
    	$('.medias').hide("fast");
    	var mediaObject = $(this).attr("rel");
    	$('#password_'+mediaObject).show("slow");
    	$('#media_scroll_'+mediaObject).trigger( 'goto', [ 0 ] );
    	return false;
   	});
   	
   	
   	/// AJAX FUNCTIONS ////////////////////////////////////////////////////////////////
   	
   	// MEDIA LOGIN
	$("#login_dossiers").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#problem_dossiers").html('').addClass('loading').show("fast");
		//check the password
		$.post("http://monicafreire.com/inc/php/queryPassword.php",{ password:$('#pwdLogin_dossiers').val(), artiste:$('#artiste_dossiers').val() } ,function(data)
        {
		  if(data == 'no' || data == '') {
		  	$("#problem_dossiers").fadeTo(200,0.1,function() { 
			  $(this).html('<br>Mot de passe invalide!').addClass('error').removeClass('loading').fadeTo(700,1);
			});		
		  }
		  else {
		  	$("#password_dossiers").remove();
		  	$("#password_fichiers").remove();
		  	$("#password_comm").after(data);
		  	$("#password_dossiers").show("slow");
		  	//$("img[@src$=png]").pngfix();
		  	$('#media_scroll_dossiers, #media_scroll_fichiers').serialScroll(
				{
				items:'p',
				prev:'.top_scroll',
				next:'.bottom_scroll',
				axis:'y',
				offset:-10, //when scrolling to photo, stop 230 before reaching it (from the left)
				start:0, //as we are centering it, start at the 2nd
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
				}
			);
          }
				
        });
 		return false; 
	});
	
	$("#login_fichiers").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#problem_fichiers").html('').addClass('loading').show("fast");
		//check the password
		$.post("http://monicafreire.com/inc/php/queryPassword.php",{ password:$('#pwdLogin_fichiers').val(), artiste:$('#artiste_fichiers').val() } ,function(data)
        {
		  if(data == 'no' || data == '') {
		  	$("#problem_fichiers").fadeTo(200,0.1,function() { 
			  $(this).html('<br>Mot de passe invalide!').addClass('error').removeClass('loading').fadeTo(700,1);
			});		
		  }
		  else {
		  	$("#password_dossiers").remove();
		  	$("#password_fichiers").remove();
		  	$("#password_comm").after(data);
		  	$("#password_fichiers").show("slow");
		  	$('#media_scroll_dossiers, #media_scroll_fichiers').serialScroll(
				{
				items:'p',
				prev:'.top_scroll',
				next:'.bottom_scroll',
				axis:'y',
				offset:-10, //when scrolling to photo, stop 230 before reaching it (from the left)
				start:0, //as we are centering it, start at the 2nd
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
				}
			);

          }
				
        });
 		return false; 
	});
	
	// abonnement ˆ la liste d'envoi
	$("#subscribe").submit(function() {
		var $a = $('#adresse').val();
		//loading...
		$("#adresse").val('un instant...');
			
		//subscribe the user
		$.post("http://monicafreire.com/inc/php/inscription_artiste.php", { adresse:$a, artiste:$('#artiste').val()}, function(data) {
		  if (data == 'erreur' || data == '') {
			$("#adresse").val('erreur');	
		  } else {
			$("#adresse").val(data);
          }
        });
        
 		return false; 
	});
	
	$("#adresse").focus(function() {
		$("#adresse").val('');
	});

    
});