﻿/**
 * @author Oriol Cabau
 */
 
var ampleBrowser = $(window).width();
var tempScrollTop, currentScrollTop = 0;

$(document).ready(function(){
	
	$(window).load(function(){
		//posicio inicial del menu
		posIni = $('.sel').position();
		wIni = $('.sel').width()+30;
		$('#menuSel').animate({left:posIni.left, width:wIni}, 200);
		//.......//
	});
	
	$(window).scroll(function(){

		currentScrollTop = $(window).scrollTop();

		if(tempScrollTop<currentScrollTop){

		}else if(tempScrollTop>currentScrollTop){

		}
		tempScrollTop = currentScrollTop;
		
		varyFondo = -(currentScrollTop/2);
		
		$('#megafondoIndex, #megafondoSeleccio').css("top", varyFondo);
		 
	});
	
	//$('#fondo').click(function(){alert(currentScrollTop);});
	//situa el banner al centre (el de home i el de seleccio
	ampleBanner = $('#bannerCentralHomeesp').width() + $('#bannerCentralHomecat').width() + $('#bannerCentralHomeeng').width();
	marge1 = ((ampleBanner - ampleBrowser)/2)* (-1);
	$('#bannerCentralHomeesp, #bannerCentralHomecat, #bannerCentralHomeeng').css("left", marge1);
	
	ampleBanner = $('#bannerCentralSeleccioesp').width() + $('#bannerCentralSelecciocat').width() + $('#bannerCentralSeleccioeng').width();
	marge1 = ((ampleBanner - ampleBrowser)/2)* (-1);
	$('#bannerCentralSeleccioesp, #bannerCentralSelecciocat, #bannerCentralSeleccioeng').css("left", marge1);
	
	//boto puja
	$('.top').click(function() {
		$('html,body').animate({scrollTop: 0}, 500);
	});
	
	//MENU
	
	$('.elementSubmenu, .elementSubmenu2').mouseover(function(){
		$(this).css("background", "#d4d4d4");	
	});
	
	$('.elementSubmenu, .elementSubmenu2').mouseout(function(){
		$(this).css("background", "#ffffff");	
	});
	
	$('.menu').mouseenter(function(){
		pos = $(this).position();
		w = $(this).width()+30;
		$('#menuSel').stop().animate({left:pos.left, width:w}, 200);
	});
	
	$('#barraSotaMenu, #subMenuPrincipal').mouseleave(function(){
		$('#menuSel').animate({left:posIni.left, width:wIni}, 200);
	});
	
	$('#menuTradicio').mouseenter(function(){
		pos = $('.tradicio').position();
		w = $('.tradicio').width()+30;
		$('#menuSel').stop().animate({left:pos.left, width:w}, 200);
	});
	
	$('#menuEstil').mouseenter(function(){
		pos = $('.estil').position();
		w = $('.estil').width()+30;
		$('#menuSel').stop().animate({left:pos.left, width:w}, 200);
	});
	
	$('#menuSeleccio, #subMenuCavas, #subMenuVins, #subMenuMarc, #subMenuPresentacions').mouseenter(function(){
		pos = $('.seleccio').position();
		w = $('.seleccio').width()+30;
		$('#menuSel').stop().animate({left:pos.left, width:w}, 200);
	});
	
	//SUBMENUUUUUUUUUUUUUUUUUUSSSSSS
	function tradicio(){
		$('#menuEstil, #menuSeleccio, #subMenuCavas, #subMenuVins, #subMenuMarc, #subMenuPresentacions').filter(":visible").slideUp(400);
		$('#menuTradicio').slideDown(400);
	}
	
	function estil(){
		$('#menuTradicio, #menuSeleccio, #subMenuCavas, #subMenuVins, #subMenuMarc, #subMenuPresentacions').filter(":visible").slideUp(400);
		$('#menuEstil').slideDown(400);
	}
	
	function seleccio(){
		$('#menuTradicio, #menuEstil, #subMenuCavas, #subMenuVins, #subMenuMarc, #subMenuPresentacions').filter(":visible").slideUp(400);
		$('#menuSeleccio').slideDown(400);
	}
	
	function desplega(tipus){
		$('#menuSeleccio').slideUp(400);
		switch(tipus){
			case "cavas": $('#subMenuCavas').slideDown(400);
						  break;
			case "vins": $('#subMenuVins').slideDown(400);
						  break;
			case "marc": $('#subMenuMarc').slideDown(400);
						  break;
			case "presentacions": $('#subMenuPresentacions').slideDown(400);
						  break;
		}
	}
	
	$('.tradicio').mouseenter(tradicio);
	
	$('.estil').mouseenter(estil);
	
	$('.seleccio').mouseenter(seleccio);
	
	$('.desplegaCavas').click(function(){
		desplega("cavas");
	});
	
	$('.desplegaVins').click(function(){
		desplega("vins");
	});
	
	$('.desplegaMarc').click(function(){
		desplega("marc");
	});
	
	$('.desplegaPresentacions').click(function(){
		desplega("presentacions");
	});
	
	$('#aDalt').mouseleave(function(){
		$('#menuTradicio, #menuEstil, #menuSeleccio, #subMenuCavas, #subMenuVins, #subMenuMarc, #subMenuPresentacions').slideUp(400);
	});
	
	$('.m1').mouseenter(function(){
		$('#menuTradicio, #menuEstil, #menuSeleccio, #subMenuCavas, #subMenuVins, #subMenuMarc, #subMenuPresentacions').slideUp(400);
	});
	
	//.--------------.//
	
	//submenus seccions index i fletxes galeries - funcio moure fins subseccions//
	
	function mouSeccio(num){
		switch(num){
			case 1: sc = 900;
					$('.c2').slideUp(400, function(){
						$('.c1').slideDown(400);
					});
					break;
			case 2: sc = 900;
					$('.c1').slideUp(400, function(){
						$('.c2').slideDown(400);
					});
					break;
			case 3: sc = 1580;
					$('.c4').slideUp(400, function(){
						$('.c3').slideDown(400);
					});
					break;
			case 4: sc = 1580;
					$('.c3').slideUp(400, function(){
						$('.c4').slideDown(400);
					});
					break;
			case 5: sc = 680;
					break;
			case 6: sc = 1381;
					break;
			case 7: sc = 2081;
					break;
			case 8: sc = 2791;
					break;
			case 9: sc = 2791;
					$('.p2, .p3, .p4, .p5, .p6').filter(":visible").slideUp(400, function(){
						$('.p1').slideDown(400);
					});
					break;	
			case 10: sc = 2791;
					$('.p1, .p3, .p4, .p5, .p6').filter(":visible").slideUp(400, function(){
						$('.p2').slideDown(400);
					});
					break;	
			case 11: sc = 2791;
					$('.p1, .p2, .p4, .p5, .p6').filter(":visible").slideUp(400, function(){
						$('.p3').slideDown(400);
					});
					break;	
			case 12: sc = 2791;
					$('.p1, .p2, .p3, .p5, .p6').filter(":visible").slideUp(400, function(){
						$('.p4').slideDown(400);
					});
					break;	
			case 13: sc = 2791;
					$('.p1, .p2, .p3, .p4, .p6').filter(":visible").slideUp(400, function(){
						$('.p5').slideDown(400);
					});
					break;	
			case 14: sc = 2791;
					$('.p1, .p2, .p3, .p4, .p5').filter(":visible").slideUp(400, function(){
						$('.p6').slideDown(400);
					});
					break;
		}
		$('html, body').animate({scrollTop: sc}, 500);
	}
	
	$('.linkInt').click(function(){
		sec = parseInt($(this).attr("sec"));
		mouSeccio(sec);
		if(sec >= 9 && sec <= 14){
			$('.estSub').each(function(){
				$(this).css("background", "#CCC");
			});
			$(this).css("background", "#917b4c");
		}
	});
	
	//............//
	
	
	var fotoIni1 = fotoIni2 = fotoIni3 = fotoIni4 = 1;
	
	var fotoIni5 = parseInt($('.contGaleria5').attr("init"));
	var fotoIni6 = parseInt($('.contGaleria6').attr("init"));
	var fotoIni7 = parseInt($('.contGaleria7').attr("init"));
	var fotoIni8 = parseInt($('.contGaleria8').attr("init"));
	var fotoIni9 = parseInt($('.contGaleria9').attr("init"));
	var fotoIni10 = parseInt($('.contGaleria10').attr("init"));
	var fotoIni11 = parseInt($('.contGaleria11').attr("init"));
	var fotoIni12 = parseInt($('.contGaleria12').attr("init"));
	var fotoIni13 = parseInt($('.contGaleria13').attr("init"));
	
	mouGaleria(9);
	mouGaleria(11);
	//mouGaleria(13);
	mouGaleria(15);
	mouGaleria(17);
	mouGaleria(19);
	//mouGaleria(21);
	mouGaleria(23);
	mouGaleria(25);
	
	var numImg1 = $('.contGaleria1 img').length;
	var limit1 = -(((numImg1) - 1) * 495);
	var esq1 = 0;
	
	var numImg2 = $('.contGaleria2 img').length;
	var limit2 = -(((numImg2) - 1) * 495);
	var esq2 = 0;
	
	var numImg3 = $('.contGaleria3 img').length;
	var limit3 = -(((numImg3) - 1) * 495);
	var esq3 = 0;
	
	var numImg4 = $('.contGaleria4 img').length;
	var limit4 = -(((numImg4) - 1) * 495);
	var esq4 = 0;
	
	function mouGaleria(num){
		switch(num){
			case 1: 
					$('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png");
					if(esq1 > limit1){
						fotoIni1++;
						esq1 -= 495;
						if(esq1 == limit1){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
						$('.contGaleria1').stop().animate({left: esq1}, 400);
						txt = $('.fotoHistoria'+fotoIni1).attr("text");
						$('.textHistoria').html(txt);
						$('.boletaHistoria'+fotoIni1).attr("src", "img/bolaPlena.png");
						$('.boletaHistoria'+(fotoIni1-1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 2: 
					$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
					if(esq1 < 0){
						fotoIni1--;
						esq1 += 495;
						if(esq1 == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
						$('.contGaleria1').stop().animate({left: esq1}, 400);
						txt = $('.fotoHistoria'+fotoIni1).attr("text");
						$('.textHistoria').html(txt);
						$('.boletaHistoria'+fotoIni1).attr("src", "img/bolaPlena.png");
						$('.boletaHistoria'+(fotoIni1+1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 3: 
					$('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png");
					if(esq2 > limit2){
						fotoIni2++;
						esq2 = -((fotoIni2-1)*495);
						if(esq2 == limit2){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
						$('.contGaleria2').stop().animate({left: esq2}, 400);
						txt = $('.fotoFinca'+fotoIni2).attr("text");
						$('.textFinca').html(txt);
						$('.boletaFinca'+fotoIni2).attr("src", "img/bolaPlena.png");
						$('.boletaFinca'+(fotoIni2-1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 4: 
					$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
					if(esq2 < 0){
						fotoIni2--;
						esq2 = -((fotoIni2-1)*495);
						if(esq2 == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
						$('.contGaleria2').stop().animate({left: esq2}, 400);
						txt = $('.fotoFinca'+fotoIni2).attr("text");
						$('.textFinca').html(txt);
						$('.boletaFinca'+fotoIni2).attr("src", "img/bolaPlena.png");
						$('.boletaFinca'+(fotoIni2+1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 5: 
					$('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png");
					if(esq3 > limit3){
						fotoIni3++;
						esq3 = -((fotoIni3-1)*495);
						if(esq3 == limit3){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
						$('.contGaleria3').stop().animate({left: esq3}, 400);
						txt = $('.fotoVendimia'+fotoIni3).attr("text");
						$('.textVendimia').html(txt);
						$('.boletaVendimia'+fotoIni3).attr("src", "img/bolaPlena.png");
						$('.boletaVendimia'+(fotoIni3-1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 6: 
					$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
					if(esq3 < 0){
						fotoIni3--;
						esq3 = -((fotoIni3-1)*495);
						if(esq3 == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
						$('.contGaleria3').stop().animate({left: esq3}, 400);
						txt = $('.fotoVendimia'+fotoIni3).attr("text");
						$('.textVendimia').html(txt);
						$('.boletaVendimia'+fotoIni3).attr("src", "img/bolaPlena.png");
						$('.boletaVendimia'+(fotoIni3+1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 7: 
					$('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png");
					if(esq4 > limit4){
						fotoIni4++;
						esq4 = -((fotoIni4-1)*495);
						if(esq4 == limit4){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
						$('.contGaleria4').stop().animate({left: esq4}, 400);
						txt = $('.fotoBodega'+fotoIni4).attr("text");
						$('.textBodega').html(txt);
						$('.boletaBodega'+fotoIni4).attr("src", "img/bolaPlena.png");
						$('.boletaBodega'+(fotoIni4-1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 8: 
					$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
					if(esq4 < 0){
						fotoIni4--;
						esq4 = -((fotoIni4-1)*495);
						if(esq4 == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
						$('.contGaleria4').stop().animate({left: esq4}, 400);
						txt = $('.fotoBodega'+fotoIni4).attr("text");
						$('.textBodega').html(txt);
						$('.boletaBodega'+fotoIni4).attr("src", "img/bolaPlena.png");
						$('.boletaBodega'+(fotoIni4+1)).attr("src", "img/bolaBuida.png");
					}
					break;
			case 9: 
					numImg = $('.contGaleria5 img').length;
					if(numImg != 1){
						if(fotoIni5>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria5').css("left")) > limit){
							fotoIni5++;
							esq = -((fotoIni5-1)*495);
							if(esq < limit){ esq = limit; fotoIni5 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria5').stop().animate({left: esq}, 400);
								txt = $('.fotoCavas'+fotoIni5).attr("text");
								$('.textCavas').html(txt);
								$('.boletaCavas'+fotoIni5).attr("src", "img/bolaPlena.png");
								$('.boletaCavas'+(fotoIni5-1)).attr("src", "img/bolaBuida.png");
								$('.magradacavas').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dcavas%26item%3D'+(fotoIni5 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 10:
					numImg = $('.contGaleria5 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria5').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni5--;
							esq = -((fotoIni5-1)*495);
							if(esq > 0){ esq = 0; fotoIni5 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria5').stop().animate({left: esq}, 400);
								txt = $('.fotoCavas'+fotoIni5).attr("text");
								$('.textCavas').html(txt);
								$('.boletaCavas'+fotoIni5).attr("src", "img/bolaPlena.png");
								$('.boletaCavas'+(fotoIni5+1)).attr("src", "img/bolaBuida.png");
								$('.magradacavas').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dcavas%26item%3D'+(fotoIni5 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 11: 
					numImg = $('.contGaleria6 img').length;
					if(numImg != 1){
						if(fotoIni6>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria6').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni6++;
							esq = -((fotoIni6-1)*495);
							if(esq < limit){ esq = limit; fotoIni6 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria6').stop().animate({left: esq}, 400);
								txt = $('.fotoVins'+fotoIni6).attr("text");
								$('.textVins').html(txt);
								$('.boletaVins'+fotoIni6).attr("src", "img/bolaPlena.png");
								$('.boletaVins'+(fotoIni6-1)).attr("src", "img/bolaBuida.png");
								$('.magradavins').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dvins%26item%3D'+(fotoIni6 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 12: 
					numImg = $('.contGaleria6 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria6').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni6--;
							esq = -((fotoIni6-1)*495);
							if(esq > 0){ esq = 0; fotoIni6 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria6').stop().animate({left: esq}, 400);
								txt = $('.fotoVins'+fotoIni6).attr("text");
								$('.textVins').html(txt);
								$('.boletaVins'+fotoIni6).attr("src", "img/bolaPlena.png");
								$('.boletaVins'+(fotoIni6+1)).attr("src", "img/bolaBuida.png");
								$('.magradavins').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dvins%26item%3D'+(fotoIni6 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 13: 
					numImg = $('.contGaleria7 img').length;
					if(numImg != 1){
						if(fotoIni7>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria7').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni7++;
							esq = -((fotoIni7-1)*495);
							if(esq < limit){ esq = limit; fotoIni7 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria7').stop().animate({left: esq}, 400);
								txt = $('.fotoMarc'+fotoIni7).attr("text");
								$('.textMarc').html(txt);
								$('.boletaMarc'+fotoIni7).attr("src", "img/bolaPlena.png");
								$('.boletaMarc'+(fotoIni7-1)).attr("src", "img/bolaBuida.png");
								$('.magradamarc').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dmarc%26item%3D'+(fotoIni7 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 14: 
					numImg = $('.contGaleria7 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria7').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni7--;
							esq = -((fotoIni7-1)*495);
							if(esq > 0){ esq = 0; fotoIni7 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria7').stop().animate({left: esq}, 400);
								txt = $('.fotoMarc'+fotoIni7).attr("text");
								$('.textMarc').html(txt);
								$('.boletaMarc'+fotoIni7).attr("src", "img/bolaPlena.png");
								$('.boletaMarc'+(fotoIni7+1)).attr("src", "img/bolaBuida.png");
								$('.magradamarc').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dmarc%26item%3D'+(fotoIni7 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 15: 
					numImg = $('.contGaleria8 img').length;
					if(numImg != 1){
						if(fotoIni8>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria8').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni8++;
							esq = -((fotoIni8-1)*495);
							if(esq < limit){ esq = limit; fotoIni8 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria8').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsEstoigs'+fotoIni8).attr("text");
								$('.textPresentacionsEstoigs').html(txt);
								$('.boletaPresentacionsEstoigs'+fotoIni8).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsEstoigs'+(fotoIni8-1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions1').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions1%26item%3D'+(fotoIni8 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 16: 
					numImg = $('.contGaleria8 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria8').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni8--;
							esq = -((fotoIni8-1)*495);
							if(esq > 0){ esq = 0; fotoIni8 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria8').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsEstoigs'+fotoIni8).attr("text");
								$('.textPresentacionsEstoigs').html(txt);
								$('.boletaPresentacionsEstoigs'+fotoIni8).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsEstoigs'+(fotoIni8+1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions1').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions1%26item%3D'+(fotoIni8 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 17: 
					numImg = $('.contGaleria9 img').length;
					if(numImg != 1){
						if(fotoIni9>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria9').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni9++;
							esq = -((fotoIni9-1)*495);
							if(esq < limit){ esq = limit; fotoIni9 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria9').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsFestival'+fotoIni9).attr("text");
								$('.textPresentacionsFestival').html(txt);
								$('.boletaPresentacionsFestival'+fotoIni9).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsFestival'+(fotoIni9-1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions2').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions2%26item%3D'+(fotoIni9 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 18: 
					numImg = $('.contGaleria9 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria9').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni9--;
							esq = -((fotoIni9-1)*495);
							if(esq > 0){ esq = 0; fotoIni9 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria9').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsFestival'+fotoIni8).attr("text");
								$('.textPresentacionsFestival').html(txt);
								$('.boletaPresentacionsFestival'+fotoIni9).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsFestival'+(fotoIni9+1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions2').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions2%26item%3D'+(fotoIni9 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 19: 
					numImg = $('.contGaleria10 img').length;
					if(numImg != 1){
						if(fotoIni10>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria10').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni10++;
							esq = -((fotoIni10-1)*495);
							if(esq < limit){ esq = limit; fotoIni10 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria10').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsDuos'+fotoIni10).attr("text");
								$('.textPresentacionsDuos').html(txt);
								$('.boletaPresentacionsDuos'+fotoIni10).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsDuos'+(fotoIni10-1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions3').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions3%26item%3D'+(fotoIni10 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 20: 
					numImg = $('.contGaleria10 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria10').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni10--;
							esq = -((fotoIni10-1)*495);
							if(esq > 0){ esq = 0; fotoIni10 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria10').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsDuos'+fotoIni10).attr("text");
								$('.textPresentacionsDuos').html(txt);
								$('.boletaPresentacionsDuos'+fotoIni10).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsDuos'+(fotoIni10+1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions3').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions3%26item%3D'+(fotoIni10 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 21: 
					numImg = $('.contGaleria11 img').length;
					if(numImg != 1){
						if(fotoIni11>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria11').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni11++;
							esq = -((fotoIni11-1)*495);
							if(esq < limit){ esq = limit; fotoIni11 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria11').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsTrios'+fotoIni11).attr("text");
								$('.textPresentacionsTrios').html(txt);
								$('.boletaPresentacionsTrios'+fotoIni11).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsTrios'+(fotoIni11-1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions4').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions4%26item%3D'+(fotoIni11 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 22: 
					numImg = $('.contGaleria11 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria11').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni11--;
							esq = -((fotoIni11-1)*495);
							if(esq > 0){ esq = 0; fotoIni11 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria11').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsTrios'+fotoIni11).attr("text");
								$('.textPresentacionsTrios').html(txt);
								$('.boletaPresentacionsTrios'+fotoIni11).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsTrios'+(fotoIni11+1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions4').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions4%26item%3D'+(fotoIni11 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 23: 
					numImg = $('.contGaleria12 img').length;
					if(numImg != 1){
						if(fotoIni12>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria12').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni12++;
							esq = -((fotoIni12-1)*495);
							if(esq < limit){ esq = limit; fotoIni12 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria12').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsTorello'+fotoIni12).attr("text");
								$('.textPresentacionsTorello').html(txt);
								$('.boletaPresentacionsTorello'+fotoIni12).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsTorello'+(fotoIni12-1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions5').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions5%26item%3D'+(fotoIni12 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 24: 
					numImg = $('.contGaleria12 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria12').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni12--;
							esq = -((fotoIni12-1)*495);
							if(esq > 0){ esq = 0; fotoIni12 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria12').stop().animate({left: '+=495'}, 400);
								txt = $('.fotoPresentacionsTorello'+fotoIni12).attr("text");
								$('.textPresentacionsTorello').html(txt);
								$('.boletaPresentacionsTorello'+fotoIni12).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsTorello'+(fotoIni12+1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions5').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions5%26item%3D'+(fotoIni12 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 25: 
					numImg = $('.contGaleria13 img').length;
					if(numImg != 1){
						if(fotoIni13>=1){ $('.fletxa[num="'+(num+1)+'"]').attr("src", "img/izquierdaon.png"); }
						limit = -(((numImg) - 1) * 495);
						if(parseInt($('.contGaleria13').css("left")) > -(((numImg) - 1) * 495)){
							fotoIni13++;
							esq = -((fotoIni13-1)*495);
							if(esq < limit){ esq = limit; fotoIni13 = numImg; }else{
								if(esq == limit){ $('.fletxa[num="'+num+'"]').attr("src", "img/derechaoff.png"); }
								$('.contGaleria13').stop().animate({left: esq}, 400);
								txt = $('.fotoPresentacionsCaixes'+fotoIni13).attr("text");
								$('.textPresentacionsCaixes').html(txt);
								$('.boletaPresentacionsCaixes'+fotoIni13).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsCaixes'+(fotoIni13-1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions6').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions6%26item%3D'+(fotoIni13 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
			case 26: 
					numImg = $('.contGaleria13 img').length;
					if(numImg != 1){
						if(parseInt($('.contGaleria13').css("left")) < 0){
							$('.fletxa[num="'+(num-1)+'"]').attr("src", "img/derechaon.png");
							fotoIni13--;
							esq = -((fotoIni13-1)*495);
							if(esq > 0){ esq = 0; fotoIni13 = 1; }else{
								if(esq == 0){ $('.fletxa[num="'+num+'"]').attr("src", "img/izquierdaoff.png"); }
								$('.contGaleria13').stop().animate({left: '+=495'}, 400);
								txt = $('.fotoPresentacionsCaixes'+fotoIni13).attr("text");
								$('.textPresentacionsCaixes').html(txt);
								$('.boletaPresentacionsCaixes'+fotoIni13).attr("src", "img/bolaPlena.png");
								$('.boletaPresentacionsCaixes'+(fotoIni13+1)).attr("src", "img/bolaBuida.png");
								$('.magradapresentacions6').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.torello.com%2Fseleccio.php%3Fsec%3Dpresentacions6%26item%3D'+(fotoIni13 - 1)+'&amp;send=false&amp;layout=standard&amp;width=370&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:370px; height:30px;" allowTransparency="true"></iframe>');
							}
						}
					}
					break;
		}
	}
	
	$('.fletxa').click(function(){
		num = parseInt($(this).attr("num"));
		mouGaleria(num);
	});
	
	//ACTUALITAT
	
	var itemsActualitat = ($('.noti2').length)+3;
	var numPages = Math.ceil(itemsActualitat/6);
	var leftMaxActualidad = -((numPages-1)*960);
	var leftActualitat = 0;
	var pagActual = 1;
	var widthActual = numPages*960;
	
	$('#intWrapper').css("width", widthActual);
	$('#textoPaginacionActualidad').html('&nbsp;&nbsp;&nbsp;P&aacute;gina '+pagActual+' de '+numPages+'&nbsp;&nbsp;&nbsp;');
	
	
	function mouActualitat(caso){
		switch(caso){
			case "derecha":	if(leftActualitat > leftMaxActualidad){ 
								leftActualitat = leftActualitat - 960;
								pagActual++;
								$('#textoPaginacionActualidad').html('&nbsp;&nbsp;&nbsp;P&aacute;gina '+pagActual+' de '+numPages+'&nbsp;&nbsp;&nbsp;');
								$('.izq').attr("src", "img/izquierdaon.jpg");
								if(leftActualitat == leftMaxActualidad){
									$('.der').attr("src", "img/derechaoff.jpg");
								}
								$('#intWrapper').stop().animate({left: leftActualitat}, 600);
							}
							break;
			case "izquierda":if(leftActualitat < 0){ 
								leftActualitat = leftActualitat + 960;
								pagActual--;
								$('#textoPaginacionActualidad').html('&nbsp;&nbsp;&nbsp;P&aacute;gina '+pagActual+' de '+numPages+'&nbsp;&nbsp;&nbsp;');
								$('.der').attr("src", "img/derechaon.jpg");
								if(leftActualitat == 0){
									$('.izq').attr("src", "img/izquierdaoff.jpg");
								}
								$('#intWrapper').stop().animate({left: leftActualitat}, 600);
							}
							break;
		}
	}
	
	$('.der').click(function(){
		mouActualitat("derecha");
	});
	
	$('.izq').click(function(){
		mouActualitat("izquierda");
	});
	
	//DISTRIBUIDORS
	
	var numPagesDis = $('.pagDistri').length;
	var leftMaxDis = -((numPagesDis-1)*960);
	var leftDis = 0;
	var pagActualDis = 1;
	
	if(numPagesDis==1){
		$('#textoPaginacionDistri').html('&nbsp;&nbsp;&nbsp;P&aacute;gina 1 de 1&nbsp;&nbsp;&nbsp;');
		$('.derDis').attr("src", "img/derechaoff.jpg");
	}else{
		$('#textoPaginacionDistri').html('&nbsp;&nbsp;&nbsp;P&aacute;gina '+pagActualDis+' de '+numPagesDis+'&nbsp;&nbsp;&nbsp;');
		$('.derDis').click(function(){
			mouDis("derecha");
		});
		
		$('.izqDis').click(function(){
			mouDis("izquierda");
		});
	}
	
	
	function mouDis(caso){
		switch(caso){
			case "derecha":	if(leftDis > leftMaxDis){ 
								leftDis -=  960;
								pagActualDis++;
								$('#textoPaginacionDistri').html('&nbsp;&nbsp;&nbsp;P&aacute;gina '+pagActualDis+' de '+numPagesDis+'&nbsp;&nbsp;&nbsp;');
								$('.izqDis').attr("src", "img/izquierdaon.jpg");
								if(leftDis == leftMaxDis){
									$('.derDis').attr("src", "img/derechaoff.jpg");
								}
								$('#intWrapperDistribuidores').stop().animate({left: leftDis}, 600);
							}
							break;
			case "izquierda":if(leftDis < 0){ 
								leftDis +=  960;
								pagActualDis--;
								$('#textoPaginacionDistri').html('&nbsp;&nbsp;&nbsp;P&aacute;gina '+pagActualDis+' de '+numPagesDis+'&nbsp;&nbsp;&nbsp;');
								$('.derDis').attr("src", "img/derechaon.jpg");
								if(leftDis == 0){
									$('.izqDis').attr("src", "img/izquierdaoff.jpg");
								}
								$('#intWrapperDistribuidores').stop().animate({left: leftDis}, 600);
							}
							break;
		}
	}
	
});
