 /* This file is part of Desktop!.
 Desktop! created by Mickael.j@gmail.cm,
 Desktop! is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Desktop! is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 */


	window.addEvent('domready', function(){

		image();
	});


function image(){

	var imImage=$$('.dragit img');


	imImage.each(function(element){
		var fadeIt=new Fx.Styles(element, {duration: 450, wait: false, transition: Fx.Transitions.Quart.easeInOut});
	 	new Drag.Move(element, {droppables: $('destkop')});
		element.addEvent('mouseup',function(drop){
		//Save cookies with X/Y pos
			if (element.width<80){
				name=element.title;
				position=element.getStyle('top')+"+"+element.getStyle('left');
				Cookie.set(name,position);
			}
		});
		//
		// Pulse effect on mouse on event
		//
 		element.addEvent('mouseenter',function(){
			width=element.getStyle('width').split("px");
			width=width[0];
	 		if (width<80){
				fx = new Fx.Style(element, 'opacity',{duration: 600, wait: false, transition: Fx.Transitions.Quart.easeInOut});
				fx.start('1','.5');
				fx.start('.5','1');
			}
		});

		//
		// Z-Index adjust
 		//
		element.addEvent('click', function(){
			$$('img').setStyle('z-index',0);
			element.setStyle('z-index',10);
			if (element.width>80){
				element.addEvent(function(event){

				});
			}
		});

		element.addEvent('dblclick',function(){ // Redim image (fixed for IE and Opera)
			width=element.getStyle('width').split("px");
			width=width[0];
			if (width<80){

				// recuperation de la taille originale.
				var tmp_img = new Image();
				tmp_img.src=element.src;

				real_width = tmp_img.width;
				real_height = tmp_img.height;

				// on ajuste le positionnement a gauche.
				if (navigator.appName == "Microsoft Internet Explorer") {
					var left=((document.body.clientWidth)/2)-((real_width)/2);
				}else{
					left=((document.width)/2)-((real_width)/2);
				}


				// thumbails
				$$('img').setStyle('z-index','0');
				//
				// Fondu
				//
				fx = new Fx.Style(element, 'opacity',{duration: 600, wait: false, transition: Fx.Transitions.Quart.easeInOut});
				fx.start('.3','1');

				fadeIt.start({	//
					'width':(real_width)
				}).chain(function(){
					this.start({
						'padding-left':'10px',
						'padding-right':'10px',
						'padding-top':'10px',
						'padding-bottom':'10px',
						'background-color':'#eee',
						'left':left,
						'z-index':'10',
						'top':35	// Image top

					});
				});

			}else{	// image -> thumbail
				$$('img').setStyle('opacity','1');

				position=Cookie.get(name); // Get X/Y position by cookies.
				pos=position.split('+')
				//alert ('X :'+pos[0]+" Y :"+pos[1]);
				fadeIt.start({
					'width':'75px',
					'padding':'1px',
					'background-color':'#fff',
					'top': pos[0],
					'left': pos[1]

				});
			}
			$$('img').setStyle('z-index',0); // defaults z-index
			element.setStyle('z-index',10);
		});

		//
		// Zoom/Unzom event.
		//

		element.addEvent('mousewheel', function(event) {
			event = new Event(event);
			var zoomIt=new Fx.Styles(element, {duration: 750, wait: false, transition: Fx.Transitions.Quart.easeInOut});
			width=element.getStyle('width').split("px");
			width=width[0];
			if (width>80){
				if (event.wheel > 0) { // zoom.
					zoomIt.start({'width':(element.width + 20)});
				}
				if (event.wheel < 0) {	// ezoom .
					zoomIt.start({'width':(element.width - 20)});
				}
			}
		});
	});


}

