
//var webroot = <?php echo WEBROOT; ?>;

var webroot = 'http://anastasiafriedman.com';

$(document).ready(function(){


    $("img[@src$=png], div.dropShadow, #footer").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;
		};
	$('#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, #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
		}
	);
	
	$('#bio').serialScroll(
		{
				items:'p',
				prev:'#top_scroll_bio',
				next:'#bottom_scroll_bio',
				axis:'y',
				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
		}
	);
	
	$('#spectacles_content').serialScroll(
		{
				items:'div',
				prev:'#top_scroll',
				next:'#bottom_scroll',
				axis:'y',
				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
		}
	);



	
	///// FLASH EMBEDDING //////
	
	$('.audioPlayer').flash(
        { src: webroot+"/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;
        }
    );
	
	$('.audioExtras').flash(
        { src: webroot+"/medias/flash/player.swf", width: 290, height: 30},
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.soundFile = "http://www.audiogram.com/doc/pc_audio/"+$this.attr('rel');
			 htmlOptions.flashvars.width = "290";
            htmlOptions.flashvars.transparentpagebg = "yes";
			htmlOptions.flashvars.autostart = "yes";
			htmlOptions.flashvars.leftbg = "cccccc";
			htmlOptions.flashvars.lefticon = "666666";
			htmlOptions.flashvars.rightbg = "999999";
			htmlOptions.flashvars.righticon = "666666";
			htmlOptions.flashvars.voltrack = "eeeeee";
			htmlOptions.flashvars.bg = "eeeeee";
			htmlOptions.flashvars.track = "eeeeee";
			htmlOptions.flashvars.text = "666666";
			htmlOptions.flashvars.skip = "777777";
			htmlOptions.flashvars.loader = "666666";
			htmlOptions.flashvars.tracker = "cccccc";
			htmlOptions.flashvars.border = "aaaaaa";
			htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('mp3player').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );
    
    
    $('.videoPlayer').flash(
        { src: webroot+"/medias/flash/video-overview.swf", height: 252, width: 320 },
        { 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.flashvars.clr = $this.attr('clr');
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('flashVideo').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );

    
    $('.photoGallery').flash(
        { src: webroot+"/medias/flash/image_gallery.swf", height: 550, width: 782 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.xmlFile = '/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: webroot+"/medias/flash/babillard.swf", height: 450, width: 700 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.webroot = webroot;
            htmlOptions.wmode = 'transparent';
            this.innerHTML = '';
            $(this).addClass('flashBB').prepend($.fn.flash.transform(htmlOptions));
            return false;
        }
    );	
	
	// 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("/inc/php/queryPassword.php",{ password:$('#pwdLogin_dossiers').val(), artiste:$('#artiste_dossiers').val(), lang:$('#lang').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("/inc/php/queryPassword.php",{ password:$('#pwdLogin_fichiers').val(), artiste:$('#artiste_fichiers').val(), lang:$('#lang').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();
		
		var $lang = $('#lang').val();
		if ($lang == 'fr') { var $wait = 'un instant...'; }
		else { var $wait = 'one moment please...'; }
		
		//loading...
		$("#adresse").val($wait);
			
		//subscribe the user
		$.post(webroot+"/inc/php/inscription_artiste.php", { adresse:$a, artiste:$('#artiste').val(), lang:$lang }, function(data) {
		  if (data == 'erreur' || data == '') {
			$("#adresse").val('erreur');	
		  } else {
			$("#adresse").val(data);
          }
        });
        
 		return false; 
	});
	
	$("#adresse").focus(function() {
		$("#adresse").val('');
	});

    
});
