﻿/*
 * EOGallery 1.0 - Animated slideshow gallery.
 * By fortin - FProd (http://www.fprod.net)
 * Copyright (c) 2006 fortin - FProd
 * EOGallery uses jQuery (http://www.jquery.com).
 */

 slider = new Array();
big = new Array();
big["width"] = 320;
big["height"] = 320;
big["height2"] = big["height"] ;
small = new Array();
small["width"] = 160;
small["height"] = 160;
small["height2"] = small["height"] ;
font = new Array();
font["big"] = 16;
font["small"] = 12;
timer = -1;
function equilibrate() {
	$('#slider ul li').each(function (i) {
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.children('a').children('img');
		var ttl = a.children('.imtitle');
		switch (d) {
		case 0:
			var img_src = new Image();
			img_src.src = img.attr('src');
//alert(img_src.width+"-"+img_src.height);

			if (img_src.width>img_src.height) {
				var big_width = big["width"];
				var big_height = Math.floor((img_src.height*big["width"])/img_src.width);
			} else {
				var big_height = big["height"];
				var big_width = Math.floor((img_src.width*big["height"])/img_src.height);
			}

//alert(big_width+"-"+big_height);

			img.animate({
				width: big_width,
				height: big_height
			});
			a.animate({
				width: big["width"],
				height: big["height2"]
			},
			function () {
				ttl.css({
					'font-size': font["big"] + 'px'
				})
			});
			showtext(a.attr('id').substr(5));
			break;
		case 1:
			ttl.css({
				'font-size':
				font["small"] + 'px'
			});
			if (slider[i] == 1) {
				slider[i] = 0;
				a.css({
					display: 'inline',
					width: '0px',
					height: '0px'
				});
				img.css({
					width: '0px',
					height: '0px'
				});
				ttl.css({
					opacity: '0'
				})
			}
			img.animate({
				width: small["width"],
				height: small["height"]
			},
			function () {
				ttl.fadeTo(500, 1)
			});
			a.animate({
				width: small["width"],
				height: small["height2"]
			});
			break;
		default:
			if (slider[i] != 1) {
				slider[i] = 1;
				a.hide('fast')
			}
			break
		}
	});
	directlink();
	rotate()
}
function actual_change(diff) {
	if (actual + diff > 0 && actual + diff < max) {
		actual = actual + diff;
		return true
	}
	return false
};
function directlink() {
	$('#directlink').attr('href', location.href.replace(location.search, '') + '?show=' + actual)
}
$(document).ready(function () {
	var requete = location.search.substring(1);
	var tab_paires = requete.split("&");
	var tab_elts = new Array();
	for (var i = 0; i < tab_paires.length; i++) {
		temp = tab_paires[i].split("=");
		tab_elts[temp[0]] = unescape(temp[1])
	}
	$('#slider ul').css('overflow', 'hidden');
	$('#slider ul').prepend('<li><a><img src="templates/defaut/front/images/vide.png" alt="" /></a></li>');
	max = $('#slider ul li').size();
	i = (tab_elts["show"]) ? parseInt(tab_elts["show"]) : 0;
	actual = (!isNaN(i) && i > 0 && i < max) ? i: 1;
	$('#slider ul li .text').appendTo("#texts");
	$('#slider ul li').each(function (i) {
		d = Math.abs(actual - i);
		var a = $(this);
		var img = a.children('a').children('img');
		var ttl = a.children('.imtitle');
		switch (d) {
		case 0:
			var img_src = new Image();
			img_src.src = img.attr('src');
//alert(img_src.width+"-"+img_src.height);

			if (img_src.width>img_src.height) {
				var big_width = big["width"];
				var big_height = Math.floor((img_src.height*big["width"])/img_src.width);
			} else {
				var big_height = big["height"];
				var big_width = Math.floor((img_src.width*big["height"])/img_src.height);
			}
//alert(big_width+"-"+big_height);

		ttl.css({
				'font-size':
				font["big"] + 'px'
			});
			img.css({
				width: big_width + 'px',
				height: big_height + 'px'
//				width: big["width"] + 'px',
//				height: big["height"] + 'px'
			});
			a.css({
				height: big["height2"] + 'px'
			});
			showtext(a.attr('id').substr(5));
			break;
		case 1:
			img.css({
				width:
				small["width"] + 'px',
				height: small["height"] + 'px'
			});
			a.css({
				width: small["width"] + 'px',
				height: small["height2"] + 'px'
			});
			break;
		default:
			a.css({
				display:
				'none',
				width: '0px',
				height: '0px'
			});
			break
		}
	});
	$('#butleft').click(function () {
		if (actual_change( - 1)) equilibrate();
		timer_stop();
		return false
	});
	$('#butright').click(function () {
		if (actual_change( + 1)) equilibrate();
		timer_stop();
		return false
	});
	$('#playpause').click(function () {
		var a = $('#playpause').children('img').attr('src');
		var a = a.split("/");
		if (a[a.length - 1] == 'pause.png') {
			timer_stop()
		} else {
			next();
			timer = window.setInterval("next()", 4000);
			$('#playpause').children('img').attr('src', 'templates/defaut/front/images/pause.png')
		}
		return false
	});
	$('#slider ul li a').click(function () {
		timer_stop()
	})
});
function timer_stop() {
	var a = $('#playpause').children('img').attr('src');
	var a = a.split("/");
	if (a[a.length - 1] == 'pause.png') {
		$('#playpause').children('img').attr('src', 'templates/defaut/front/images/play.png');
		window.clearInterval(timer)
	}
}
function next() {
	if (actual_change( + 1)) equilibrate()
}
function rotate() {}
function showtext(id) {
	$('#texts .text').each(function (i) {
		if ($(this).css('display') != 'none') $(this).hide()
	});
	$('#texts #text' + id).slideDown('slow')
}
 

 