/***********************************************************
*	Fichier		=	fonction.js
*	Auteur		=	Varoujan PAPAZIAN (varoujhay@free.fr)
*	Réalisé pour	=	Alan Portfolio
*	Site			=	http://www.alanrenault.com/
*	Date			=	23/09/08
*	Modifé		=	14/03/08
*	Version		=	1.0
***********************************************************/

var elements = null;
var cacher = null;
var afficher = null;
var termine = true;

$(document).ready(function(){

	/* ------------------------------------------------------------------------
		Initialisation des infobulles
	------------------------------------------------------------------------- */
	$('#logos a').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 750 
	});
	$('#portfolio div').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 750 
	});
	$('#twitter a').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 750 
	});
	
	/* ------------------------------------------------------------------------
		Initialisation du bloc des catégories en fondu
	------------------------------------------------------------------------- */

	$("body").append("<div id=\"masque\"></div>");
	var masque		=	$('#masque'); // Le masque de fond
	if(document.getElementById('voir_cat')) {
		$('#voir_cat').click(function () {
			//masque.css({ display:"block", opacity:"0",top:"0" });
			//$('#masque').fadeIn("slow", function() {
			var arrayPageSize = $.fn.lightbox.getPageSize();
			masque.hide().css({width: '100%', height: arrayPageSize[1]+'px', opacity : "0.9"}).fadeIn(function(){

				$('#contenant').css({ top:10})
				$('#contenant').fadeIn("slow");
				//$('#contenant').hide().css({width: '100%', height: arrayPageSize[1]+'px', opacity : "0.9"}).fadeIn();
				}
			);
			masque.css({ cursor:"pointer"});

			$('#masque').click(function () {
				$('#contenant').fadeOut("normal", function() {
					masque.fadeOut("normal");
				});
				return false;
			});
			$('#retour').click(function () {
				$('#contenant').fadeOut("normal", function() {
					masque.fadeOut("normal");
				});
				return false;
			});
			return false;
		});
	}
	
	/* ------------------------------------------------------------------------
		Initialisation de l'effet slide des news et du portfolio
	------------------------------------------------------------------------- */
	$('#news').slide_infos();
	$('#portfolio').slide_infos();
	
	$('#descendre').click(function () {
		if((elements.length > 2 || (afficher + 2) != elements.length) && termine==true && elements.length != 1) {
			if(!afficher){
				afficher = 0;
				cacher = 0;
			}
			if((afficher + 2) < elements.length)
			{
				afficher = afficher +2;
				cacher = afficher -2;
			}
			$.slide_infos.next(elements, afficher, cacher);
		}
		return false;
	});
	
	$('#remonter').click(function () {
		if(afficher !=0 && afficher != null && termine==true)
		{
			afficher = afficher - 2;
			cacher = afficher + 2;
			$.slide_infos.next(elements, afficher, cacher);
		}
		return false;
	});
	
	/* ------------------------------------------------------------------------
		Initialisation de l'effet lightbox
	------------------------------------------------------------------------- */
	$('#portfolio a').lightbox();
	
	/* ------------------------------------------------------------------------
		Initialisation de l'effet infobulle pour l'administration
	------------------------------------------------------------------------- */
	imagePreview();
			
});


;(function($) {

	$.fn.slide_infos = function(options) {
		return this.each(function() {   
			$.slide_infos(this, options);
		});
    };
	
	$.slide_infos = function(container) {
		elements = $(container).children();
    };
	
	$.slide_infos.next = function(elements, current, last) {
	termine=false;
		$(elements[last+1]).slideUp(); // slideUp //fadeOut
		$(elements[last]).slideUp(function() {
			$(elements[current+1]).slideDown();
			$(elements[current]).slideDown(function() {
				termine = true;
			});
		});
	};
})(jQuery);



/* ------------------------------------------------------------------------
	Fonction infobulle (administration)
	Via : http://www.webinventif.fr/comment-faire-des-info-bulles-avec-preview-dimage-via-jquery/
	http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
------------------------------------------------------------------------- */

this.screenshotPreview = function(){   
        /* CONFIG */
               
                xOffset = 10;
                yOffset = 30;
               
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
               
        /* END CONFIG */
        $("a.screenshot").hover(function(e){
                this.t = this.title;
                this.title = "";       
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");                                                                
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                               
    },
        function(){
                this.title = this.t;   
                $("#screenshot").remove();
    }); 
        $("a.screenshot").mousemove(function(e){
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};
this.imagePreview = function(){ 
        /* CONFIG */
               
                xOffset = 10;
                yOffset = 30;
               
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
               
        /* END CONFIG */
        $("td.preview").hover(function(e){
                this.t = this.firstChild.title;
                this.title = "";       
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='preview'><img src='"+ this.firstChild.href +"' alt='Image' />"+ c +"</p>");                                                                
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                               
    },
        function(){
                this.title = this.t;   
                $("#preview").remove();
    }); 
        $("td.preview").mousemove(function(e){
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};

this.tooltip = function(){
        /* CONFIG */           
                xOffset = 10;
                yOffset = 20;          
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result            
        /* END CONFIG */               
        $("a.tooltip").hover(function(e){                                                                                        
                this.t = this.title;
                this.title = "";                                                                         
                $("body").append("<p id='tooltip'>"+ this.t +"</p>");
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");               
    },
        function(){
                this.title = this.t;           
                $("#tooltip").remove();
    }); 
        $("a.tooltip").mousemove(function(e){
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};