if (typeof window.wesc != 'object') window.wesc = {};
wesc.slideshow = {};

wesc.slideshow.init = function(){
	

	// Big Slideshow Navigation
	if($('.bigslidenav').length) {
			
		$('.bigslidenav .bsn a').click(function(){

			i = $('.bigslidenav .bsn a').index(this);
			
			$('.bigslidenav .active, .bigslides .bigslide').removeClass('active');
			$(this).parents('li').addClass('active');
			$('.bigslides .bigslide').eq(i).addClass('active'); //.animate({opacity:1},{duration:800,easing:'easeOutExpo'});
			wesc.enableImagesInside('.bigslide.active .item-preview > a,.bigslide.active .bs-content');
			
			// pageTracker._trackPageview('clicked-other-bigslideshow/'+i);
			_gaq.push(['_trackEvent', 'Slideshow', 'next slideshow', $(this).text()]);
			
			$('.slide.intro .formatted-text').each(function(i,e){
				e =$(e);
				eh = 200 - e.height()/2;
				e.css({top:eh+'px'});
			})
			return false;
		});
		
		$('#bigsprev').click(function(){
			//previous big slideshow
			bno = $('.bigslidenav li.bsn');
			i = bno.index($('.bigslidenav li.active'));
			ni = i-1;
			if(ni == -1){
				ni = bno.length -1;
			} 
			$('.bigslidenav li.bsn a').eq(ni).trigger('click');
			return false;
		});
		
		$('#bigsnext').click(function(){
			//next big slideshow
			bno = $('.bigslidenav li.bsn');
			i = bno.index($('.bigslidenav li.active'));
			ni = i+1;
			if(ni == bno.length){
				ni = 0;
			} 
			$('.bigslidenav li.bsn a').eq(ni).trigger('click');
			return false;
		});
		
	}
	
	wesc.disableImagesInside('.bigslide:not(.active)');
	
	
	//small slideshow
	$('.slideshowwrap').each(function(i,e){
		
		s = $('.slideshow',e);
		
		//special case slideshow with 1 element
		if(s.is('.s1')) {
			$('a.bigprev,a.bignext,.navigation',e).hide();
			$('.items',s).css({width:'960px',margin:'0 auto'});
			return;
		}
		
		var scrollOptions = {
			size: 1, 
			loop: false,
			speed:600,
			keyboard:true,
			items:'li.slide',
			// api:true,
			easing:'easeInOutSine',
			onBeforeSeek:function(e){
				// console.log(e);
				// return false;
				ss = e.target;
				if(!ss.first) {
					wesc.enableImagesInside('.bigslide.active .item-preview > a,.bigslide.active .bs-content');
					ss.first = true;
				}

				_gaq.push(['_trackEvent', 'Slideshow', 'next image in slideshow']);
				
			}
		}
		
		$('li.slide .item-preview > a',e).click(function(){
			console.log('click slide');
			api = $(this).parents('.slideshow').data('scrollable');
			api.move(1);
			return false;
		})
		
		if($('body#stores').length) {
			
			//slideshow with navigator and autoscroll for stores
			scrollOptions.loop = true;
			/*autoscroll({
										autopause:true,
										autoplay:true,
										interval:3000,
									})*/
			api = s.scrollable(scrollOptions).navigator({
				navi: "ul.navigation",
				navitem: "li",
				activeClass: "selected",
			});
			
		} else {
			
			api = s.scrollable(scrollOptions);
			
		}
		
		$('.item-preview > a',e).click(function(ev){
			ev.preventDefault();
		});

	});
	
	
	
	//smooth rollovers
	$('.slide .btm').css({opacity:0,bottom:'-100px'});
	$('.slide').hover(function(argument) {
		wesc.enableImagesInside(this);
		$('.btm',this).stop().animate({opacity:1,bottom:0},{duration:400,easing:'easeOutExpo'});
	},function(argument) {
		$('.btm',this).stop().animate({opacity:0,bottom:'-100px'},{duration:200,easing:'easeInExpo'});
	})
	
	
	//activists slider country page
	if($('#activistslider').length) {
		$('#activistslider').scrollable({
			size: 1, 
			clickable: false, 
			speed:400,
			easing:'easeInOutExpo',
			items:'ul',
		});
	}
	
	//notes slider fullscreen view
	if($('body.fullscreen .fulltagslist').length) {
		$('.fulltagslist').scrollable({
			size: 2, 
			loop:false,
			clickable: false, 
			// speed:100,
			// easing:'easeInOutExpo',
			items:'.taglist',
		}).mousewheel();
	}
	
	
	$('.slide.intro .formatted-text').each(function(i,e){
		e = $(e);
		eh = 200 - e.height()/2;
		e.css({top:eh+'px'});
	})
	
	//enable tag zoom
	wesc.slideshow.tagzoom();
}


//Tag Rollover Effect
wesc.slideshow.tagzoom = function(){
	elements = $('.slideshow .notes a,.bs-content .notes a');
	if(!elements.length)return;
	
	note = $('<div/>',{
		id:'notepopup',
		css: {
			position: "absolute",
			display:"none",
		}
	});
	
	note.append($('<div/>').addClass('arrUp'));
	note.append($('<h5/>'));
	note.append($('<img/>'));
	note.append($('<div/>').addClass('arrDown'));
	note.prependTo('body');
	
	elements.hover(function(){
		//over
		src = $('img',this).attr('src');
		
		pos = $(this).offset();
		t = pos.top-260;
		l = pos.left-80;
		if(t < 250) {
			t = pos.top + 50;
			$('#notepopup .arrUp').show();
			$('#notepopup .arrDown').hide();
		} else {
			$('#notepopup .arrUp').hide();
			$('#notepopup .arrDown').show();
		}
		$('#notepopup').css({
			top:t+'px',
			left:l+'px'
		});
		t = $(this).attr('title');
		$('#notepopup img').attr('src',wesc.adjustImageSize(src,'bigsquare','default'));
		$('#notepopup .price').remove();
		if($('.price',this).length) {
			$('#notepopup').prepend($('<span class="price">'+$('.price',this).html()+'</span>'))
		} 
		
		$('#notepopup h5').html(t);
		$('#notepopup').show();
		
	},function(){
		//ou
		$('#notepopup h5').text('');
		$('#notepopup img').removeAttr('src');
		$('#notepopup').hide();
	});
}


$(wesc.slideshow.init);
