jQuery(document).ready(function() {

// lightbox
jQuery('.lightbox').lightbox({
	fitToScreen: true,
	imageClickClose: false,
	displayTitle: false
});


jQuery('.folder-img').hover(function() {
	jQuery(this).next().find('a').eq(0).css('text-decoration', 'underline');
	jQuery(this).next().find('div.lev01').eq(0).show();
}, function() {
	jQuery(this).next().find('a').eq(0).css('text-decoration', '');
	jQuery(this).next().find('div.lev01').eq(0).hide();
});

jQuery('.folder-title').hover(function() {
	jQuery(this).prev().parent().toggleClass('folder').toggleClass('folder-sel');
	jQuery(this).find('div.lev01').eq(0).show();
}, function() {
	jQuery(this).prev().parent().toggleClass('folder').toggleClass('folder-sel');
	jQuery(this).find('div.lev01').eq(0).hide();
});
	
	var interval=8000;
	var fade=800;
	var container=$('#div-specials-container');
	var divs=$('#div-specials-container div');
	if(container.length>0 && divs.length>0) {
		var lastDivSpecial=divs.size()-2;
		var intID=setInterval($.fn.autoChange=function() {
			current=Number($('.div-specials-current').attr('id').replace('div-specials-item-', ''));
			next=current==lastDivSpecial ? 0 : current+1;
			divs.eq(current).fadeOut(fade, function() {
				divs.eq(next).addClass('div-specials-current');
				$(this).removeClass('div-specials-current');
			});
			divs.eq(next).fadeIn(fade);
		}, interval);
		
		$('#div-specials-container button').click(function() {
			clearInterval(intID);
			id=$(this).attr('id').replace('button-specials-', '');
			current=Number($('.div-specials-current').attr('id').replace('div-specials-item-', ''));
			if(id!=current) {
				next=id;
				divs.eq(current).fadeOut(fade, function() {
					divs.eq(next).addClass('div-specials-current');
					$(this).removeClass('div-specials-current');
				});
				divs.eq(next).fadeIn(fade);
			}
			intID=setInterval(function() {
				$.fn.autoChange();
			}, interval);
		});
	}
	
	//var clInterval = setInterval(function(){
		//if(){}
	//}, interval)
	
	/*
	setInterval(function(){
		if($("#__clTag").is(":visible")){
			clYpos = $("#__clTag").offset().top;
			//alert(clYpos);
			var socialTop = clYpos - 200;
			$('#social-buttons').css({"top":socialTop+"px"});
		}
	}, 1);
	*/
	
	setTimeout(function(){ 
		$('#social-buttons').css({"opacity":"0.5","left":"-30px"}).fadeIn(300); 
	
	}, 1000)
	
	var iconLength = $('#social-buttons table').length;
	var socWidth = $('#social-buttons').width();
	
	if(iconLength>4){
		$('#social-buttons').css({"width":socWidth*2+"px"});
		if(iconLength>8){
			$('#social-buttons').css({"width":socWidth*4+"px"});
		}
	} 	
	//alert(socWidth/2);
	var socialWidth = -($('#social-buttons').width()-(socWidth));
	$('#social-buttons').hover(function(){
		$(this).stop().animate({"left":"0px","opacity":"1"}, 300);
	}, function(){
		$(this).stop().animate({"left":socialWidth+"px","opacity":"0.5"}, 300);
	});
	
	
	/*
	$('#social-buttons-a').click(function() {
		if($('#social-buttons').css('display')=='none') {
			$('#social-buttons').css({'display': 'block', 'opacity': 0}).animate({'left': '350px', 'opacity': 1}, 550).animate({'left': '300px'}, 350);
		} else {
			$('#social-buttons').animate({'left': '340px'}, 500).animate({'left': '0px', 'opacity': 0}, 400, 'swing', function() {
				$(this).css({'display': 'none', 'opacity': 1});
			});
		}
		return false;
	});
	
	$('#social-buttons-a').mousedown(function() {
		$(this).css({'outline': 0});
	});
	*/
	
	
	/**
	* Vendors
	*/
	var interval2=3000;
	var svc=$('#scroll-vendors-containter');
	var svi=$('#scroll-vendors-items');
	var images=$('#scroll-vendors-items a');
	var tables = $('#scroll-vendors-items table');
	var last_svi = images.size()-1;
	var width=0;
	var svi_click = 0;
	var _mouse_click = 0;
	
	tables.each(function() {
		width+=$(this).width();
	});
	svi.css({'width': width+'px'});
	
	if(images.length>5) {
		//speed = 200*images.length;
		$('#scroll-vendors-next').mousedown(function() {
			clearInterval(intID2);
			var left = svi.position().left*-1;
			if(left < (width-582-tables.eq(tables.length-1).width())) {
				var count = tables.length;
				var _width = 0;
				svi.stop();
				tables.each(function() {
					if(_width <= left) {
						_width += $(this).width();
						count--;
					} else {
						return ;
					}
				});
				speed = 200*count;
				svi.stop().animate({'left': -(width-582)}, speed, 'linear');
			} else {
				if(_mouse_click == 0) {
					svi.animate({'left': 0}, 800);
					intID2 = setInterval(function() {
						$('#scroll-vendors-next').click();
					}, interval);
					_mouse_click = 1;
				}
			}
		});
		
		$('#scroll-vendors-next').mouseup(function() {
			var left = svi.position().left*-1;
			var count = -1;
			var _width = 0;
			svi.stop();
			tables.each(function() {
				if(_width < left) {
					_width += $(this).width();
					count++;
				} else {
					return ;
				}
			});
			if(left < (width-582)) {
				svi.animate({'left': -(_width)}, 200);
			}
			intID2 = setInterval(function() {
				$('#scroll-vendors-next').click();
			}, interval);
		});
		
		$('#scroll-vendors-prev').mousedown(function() {
			clearInterval(intID2);
			var left = svi.position().left*-1;
			var count = -1;
			var _width = 0;
			svi.stop();
			tables.each(function() {
				if(_width <= left) {
					_width += $(this).width();
					count++;
				} else {
					return ;
				}
			});
			speed = 200*count;
			svi.stop().animate({'left': 0}, speed, 'linear');
		});
		
		$('#scroll-vendors-prev').mouseup(function() {
			var left = svi.position().left*-1;
			var count = -1;
			var _width = 0;
			svi.stop();
			tables.each(function() {
				if(_width < left) {
					_width += $(this).width();
					count++;
				} else {
					return ;
				}
			});
			if(left > 0) {
				svi.animate({'left': -(_width-tables.eq(0).width())}, 200);
			}
			intID2 = setInterval(function() {
				$('#scroll-vendors-next').click();
			}, interval);
		});
		
		$('#scroll-vendors-next').click(function() {
			_mouse_click = 1;
			_this = $(this);
			_this.mousedown();
			setTimeout(function() {
				_this.mouseup();
			}, 100);
		});
		
		var intID2 = setInterval(function () {
			$('#scroll-vendors-next').click();
		}, interval2);
		
		/*images.eq(0).addClass('scroll-item-current');
		var intID2 = setInterval(function () {
			$('#scroll-vendors-next').click();
		}, interval2);
		
		/*var intID2=setInterval(function() {
			var current=$('.scroll-item-current');
			var clone=current.clone().removeClass('scroll-item-current').appendTo(svi);
			svi.stop().animate({
				left: -current.width()
			}, 400, 'swing', function() {
				current.next().addClass('scroll-item-current');
				current.remove();
				$(this).css({left: 0});
			});
		}, interval2);*/
		
		/*$('#scroll-vendors-next').click(function() {
			if (svi_click == 0) {
				svi_click = 1;
				var current=$('.scroll-item-current');
				var clone=current.clone().removeClass('scroll-item-current').appendTo(svi);
				clearInterval(intID2);
				svi.stop().animate({
					left: -current.width()
				}, 400, 'swing', function() {
					current.next().addClass('scroll-item-current');
					current.remove();
					$(this).css({left: 0});
					svi_click = 0;
					intID2 = setInterval(function () {
						$('#scroll-vendors-next').click();
					}, interval2);
				});
			}
		});*/
		
		/*$('#scroll-vendors-prev').click(function() {
			if (svi_click == 0) {
				svi_click = 1;
				var last = $('#scroll-vendors-items a').eq(last_svi);
				var clone=last.clone().prependTo(svi);
				$('#scroll-vendors-items a').removeClass('scroll-item-current');
				clearInterval(intID2);
				svi
				.css({
					'left': -last.width()
				})
				.stop().animate({
					left: 0
				}, 400, 'swing', function() {
					clone.addClass('scroll-item-current');
					last.remove();
					svi_click = 0;
					intID2 = setInterval(function () {
						$('#scroll-vendors-next').click();
					}, interval2);
				});
			}
		});*/
	}
});
