slider = new Array();
big = new Array();
big["width"] = 320;
big["height"] = 250;
big["height2"] = 250;
small = new Array();
small["width"] = 200;
small["height"] = 150;
small["height2"] = 150;
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 img_b = a.children('a').children('img.b');
		var img_a = a.children('a').children('img.a');
		var ttl = a.children('.imtitle');
		
		var imgId		=		document.getElementById(a.attr('id')).id
		
		
		if(document.getElementById(imgId + "_videoCont") != null)
		{
					
			video			=		document.getElementById(imgId + "_videoCont");
			
			videoParent		=		document.getElementById(imgId + '_div');
			
			videoParent.removeChild(video);
								
		}
		
		document.getElementById(imgId + '_img').style.display		=		"inline";
		
		switch(d) {
			case 0:
				var imgContainer		=		document.getElementById(a.attr('id'));
				imgContainer.style.paddingTop = "0px";
				//img.animate({width: big["width"], height: big["height"]});
				
				img_a.animate({width: 307+'px', height: 184+'px', skewY : 0});
				
				img_b.animate({width: 320+'px', height: 250+'px', skewY : 0});
				
				
				if(actual < 1){
					a.animate({
						width: big["width"]
						,height: big["height2"]
						,marginLeft : 200
					}, function () { 
						ttl.css({'font-size': font["big"]+'px'}); 
					});
				} else {
					a.animate({
						width: big["width"]
						,height: big["height2"]
						,marginLeft : 0
					}, function () { 
						ttl.css({'font-size': font["big"]+'px'}); 
					});
				}
			break;
			case 1:
				var imgContainer		=		document.getElementById(a.attr('id'));
				imgContainer.style.display		=		"";
				imgContainer.style.paddingTop = "50px";

				//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); });
				
				img_a.animate({width: '192px', height: '111px'}, function () { ttl.fadeTo(500, 1); });
				
				img_b.animate({width: '200px', height: '150px'}, function () { ttl.fadeTo(500, 1); });
				
				a.animate({width: small["width"], height: small["height2"],marginLeft : 0});
			break;
			default:
				if (slider[i] != 1) {
					slider[i] = 1;
					a.hide('fast');
				}
			break;
		}
	});
	directlink();
	rotate();
}
function actual_change(diff) {
	
	
	if (actual + diff > -1 && 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();
	
	var video_ele, video_html;
	
	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="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.b');
		var img_a = a.children('a').children('img.a');
		var ttl = a.children('.imtitle');
		switch(d) {
			case 0:
				var imgContainer		=		document.getElementById(a.attr('id'));
				img_a.css({width: 307+'px', height: 184+'px'});
				img.css({width: 320+'px', height: 250+'px'});
				a.css({height: big["height2"]+'px'});

			break;
			case 1:
		
				img.css({width: 200+'px', height: small["height"]+'px'});
				img_a.css({width: 192+'px', height: 111+'px'});
				a.css({width: 200+'px', height: small["height2"]+'px'});
				var imgContainer		=		document.getElementById(a.attr('id'));
				imgContainer.style.paddingTop = "50px";
			break;
			default:
				a.css({display: 'none', width: 0 + 'px', height: 0 + 'px'});

		}
	});
	$('#butleft').click( function () {
		$(video_ele).html(video_html);
		if (actual_change(-1)){
			$('#html_vdo').remove();
			loading_video = false;
			equilibrate();
		}
		return false;
	});
	$('#butright').click( function () {
		$(video_ele).html(video_html);
		if (actual_change(+1)){
			$('#html_vdo').remove();
			loading_video = false;
			equilibrate();
		}
		return false;
	});
	
	$('.view_video').click(function(){
		if($(this).width() == '320' && $(this).attr('video') != '1'){
			video_ele = this;
			video_html = $(this).html();
			
			$(this).attr('video','1');
			var html_video = 	'<div class="video-js-box">'+
								'<video id="example_video_1" class="video-js" width="320" height="250" controls="controls" preload="auto" poster="http://video-js.zencoder.com/oceans-clip.png">'+
								'<source src="http://video-js.zencoder.com/oceans-clip.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' />'+
								'<source src="http://video-js.zencoder.com/oceans-clip.webm" type=\'video/webm; codecs="vp8, vorbis"\' />'+
								'<source src="http://video-js.zencoder.com/oceans-clip.ogv" type=\'video/ogg; codecs="theora, vorbis"\' />'+
								'<object id="flash_fallback_1" class="vjs-flash-fallback" width="320" height="250" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">'+
								'<param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />'+
								'<param name="allowfullscreen" value="true" />'+
								'<param name="flashvars" value=\'config={"playlist":["http://video-js.zencoder.com/oceans-clip.png", {"url": "http://vulcanfireworks.a.ysdhk.com/file/product/f4d92ffc9ec8f5.mp4","autoPlay":false,"autoBuffering":true}]}\' />'+
								'<img src="http://video-js.zencoder.com/oceans-clip.png" alt="Poster Image" title="No video playback capabilities." /></object></video></div>';
			$(this).html(html_video);
			
			VideoJS.setupAllWhenReady();

		}
	})
});
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', 'images/playred.png'); /* ou play.png */
		window.clearInterval(timer);
	}
}
function next() {
	if (actual_change(+1))
		equilibrate();
}
function rotate() {
	//alert(max + ' ' + actual + ' ' + (max - actual));
/*
	if (actual < (max / 2)) {
		var a = $('#slider ul li').eq(max-1).remove();
		$('#slider ul').prepend(a);
		actual = actual + 1;
	}
*/
/*
		if (diff < 0) {
			var a = $('#slider ul li:last').remove();
			$('#slider ul').prepend(a);
		}
		else {
			var a = $('#slider ul li:first').remove();
			$('#slider ul').append(a);
		}
*/
}

function showtext(id) {
	/*$('#texts .text').each( function (i) {
		if ($(this).css('display') != 'none')
			//$(this).fadeOut('fast');
			$(this).hide();
	});
	$('#texts #text'+id).slideDown('slow');*/
}
