/*
 * 	Easy Slider 1.5 - jQuery plugin
 *	written by Nikesh Kumar
 *  under guidelines of Pixel Webtech Employee	
 *	http://www.pixelwebtech.com/
 *
 *	Copyright (c) 2011 Pixel Webtech (http://www.pixelwebtech.com)
 */
 
 

$(document).ready(function(){

$('div.portfolio div.gallery img').each(function() {
		$(this).attr('title', '').parent().attr('title', '');
		var cnts = $(this).parent().contents();
		$(this).parent().replaceWith(cnts);
	});

	var index = 0;
	var indit;
	var tarolo = $('div.showcase div.gallery');
	var next = index + 1;
	var prev = $(tarolo).children().size() - 1;
	var valtido = 8000;
	var animido;
	
	function Kepvalt(index) {
	
		clearInterval(indit);
		
		if (index >= $(tarolo).children().size()) {
			index = 0;
			next = index + 1;
			prev = $(tarolo).children().size() - 1;
		} else {
			if (index < 0) { index = $(tarolo).children().size() - 1; }
			prev = index - 1;
			next = index + 1;
		}
		
		
		var pos = index * 350;
		var maxpos = $(tarolo).children().size() * 350;
		
		if (pos < maxpos) { pos = (index * - 350); animido = 1000; } else { pos = 0;  animido = 1500;}
		
		var active = index + 1;
		var name = $(tarolo).find('img').eq(index).attr('alt');
		
		$('a#show_name').fadeOut('fast', function() { $('a#show_name').html(name).fadeIn('normal'); });
		
		//$(tarolo).animate({ left: pos }, {duration: animido, easing:"easeOutExpo"});
		$(tarolo).animate({ left: pos }, animido);
		
		indit = setInterval(function() { Kepvalt(next); }, valtido);
		
		$('ul.controller li a').removeClass('on');
		$('ul.controller li a#work_' + active).attr('class', 'on');
		
		
	}
	
	indit = setInterval(function() { Kepvalt(next); }, valtido);
	
	$(tarolo).mouseover(function() { clearInterval(indit); }).mouseout(function() { indit = setInterval(function() { Kepvalt(next); }, 3000); });
	$('div.showcase div.topshadow').mouseover(function() { clearInterval(indit); }).mouseout(function() { indit = setInterval(function() { Kepvalt(next); }, 3000); });
	
	$('a#next').click(function () {
		clearInterval(indit);
		Kepvalt(next);
	});
	
	$('a#prev').click(function () {
		clearInterval(indit);
		Kepvalt(prev);
	});
	
	$('ul.controller li a').click(function() {
		var href = $(this).attr("id").replace(/work_/g, '');
		href--;
		Kepvalt(href);
	});
	
	
});

