/* -------------------------------------------------- *
 * Project scripts
 * -------------------------------------------------- *
 * Author: Morozov Igor
 * URL: http://www.morozoff.info/
 * Copyright: 2010 Morozov Igor
** -------------------------------------------------- */
var gtindex =-1;
$(document).ready(function() {
	simple_tooltip("a.tip","tooltip");

	if($('#filter-link').length > 0) {
		filterportfolio()
	}
	if($('#preview-scroll').length > 0) {
		var $viewscroll = $('#preview-scroll');
		$('.lt-work',$viewscroll).attr('href',$('li:first a',$viewscroll).attr('href'))
		$("#preview-scroll .b-preview-i").scrollable({
			items:'ul',
			next:'.ar-r',
			prev:'.ar-l',
			circular:true,
			
			onSeek: function() {
				var ind = this.getIndex();
				$('.lt-work',$viewscroll).attr('href',$('li:eq('+(ind+1)+') a',$viewscroll).attr('href'))
			}
		}).autoscroll({ interval: 4000 });
		$("#preview-scroll .ar").click(function() {
			return false;
		});
		$("#visual-outer").scrollable({
			items:'.slide-it',
			vertical:true,
			touch: false,
			api: true
		});
		$('.choose-character a.c').click(function() {
		if (gtindex!=$('.choose-character a.c').index(this))
			{gtindex = $('.choose-character a.c').index(this);}
		else {gtindex=-1;}
			$("#visual-outer").scrollable().seekTo(gtindex+1);
			return false;
		});

		$('.b-navigation a.nav-1234962003').click(function() {
			$("#visual-outer").scrollable().seekTo(0);
			return false;
		});
	}
	
	$('div.b-opinions ul').innerfade({
		speed: 750,
		timeout: 7000,
		type: 'sequence',
		containerheight: '140px'
	});
	$(".b-search input, .b-feedback .i-p").toggleVal({populateFrom: "title"});
});

function filterportfolio() {
	var $fname = $('#filter-link');
	$('a',$fname).click(function() {
		var getattr = $(this).attr('rel');
		openfilter(getattr)
		if(getattr === 'brands') {
			$('.type-ch i',$fname).css('left','18px')
		}
		else {
			$('.type-ch i',$fname).css('left','0')
		}
		
		return false;
	});
	$('.type-ch',$fname).click(function() {
		if($('i',$(this))[0].offsetLeft === 1) {
			$('i',$(this)).css('left','18px')
			var getattr = $(this).next().find('a').attr('rel');
			openfilter(getattr)
		}
		else {
			$('i',$(this)).css('left','0');
			var getattr = $(this).prev().find('a').attr('rel');
			openfilter(getattr);
		}
	});
	
	$('ul.b-filter-works a').hover(function() {
		var hght = $(this).find('span').height();
		var $span = $(this).find('span').css('bottom','-'+(hght+3)+'px');
		$span.stop().animate({bottom:'-1px'},{duration:300, queue:false});
	}, function() {
		var hght = $(this).find('span').height();
		var $span = $(this).find('span');
		$span.stop().animate({bottom:'-'+(hght+3)+'px'},{duration:300, queue:false});
	});
	
	function openfilter(getattr) {
		$('div.filter-txt .panes').hide().filter('.txt-'+getattr).show();
		$('a',$fname).removeClass('active');
		$('a[rel='+getattr+']',$fname).addClass('active');
		//console.info($('a',$fname).filter('.'+getattr))
		$('ul.b-filter-works li').hide().filter('.'+getattr).show();
	}
}

