/****
* Name: gJSlider
* Author: g6Solution
* Version: 1.0
* Web: http://g6.mk
* (c) 2010
*****/

var tekID=1;
var animID=0;
var reverse=0;
var id1=1;
var id2=2;
var xx=0;
var infotxtf=0;
$(document).ready(function(){ 

	animID = animiraj(5000,tekID);
	
	$("#inrotate div").click(function() {
		var index = $("#inrotate div").index(this);
		index+=1;
		clearTimeout(animID);
		animiraj(5000,index);			
	});

	$("#nextitem img").click(function() {

		total=sizeofElem('inrotate','div');

		if(tekID != total) {
			var index = tekID + 1;
			clearTimeout(animID);
			animiraj(5000,index);
		}
			
	});


	$("#previtem img").click(function() {

		if(tekID != 1) {
			var index = tekID - 1;
			clearTimeout(animID);
			animiraj(5000,index);
		}
			
	});
	
	
	$("#insliderright").mouseenter(function()
	{
		clearTimeout(animID);
		element="#intab"+tekID+" #ininfotxt";
		if(infotxtf==0)
		{
			infotxtf=1;
			$(element).show();
			$(element).animate({
				width: '+=200'
			},500 );
		}
	});

	$("#insliderright").mouseleave(function()
	{
		setTimeout('infotxtfInit()',1000);
		element="#intab"+tekID+" #ininfotxt";
		$(element).animate({
			width: '-=200'
		},500,function()
		{
			$(element).hide();
		});
		animID=setTimeout('animiraj('+5000+','+tekID+')',100);
	});
		
});
/* Animation function
* params:
*	- timeout - time between funcion calls
*	- index - new animation id
*/
function animiraj(timeout,index)
{
	total=sizeofElem('inrotate','div');
	if(index!=tekID)
	{
		tekoven="#item"+tekID+"-title";
		sleden="#item"+index+"-title";
		$(tekoven).removeClass("rotitemact").fadeIn('fast');//,"fast");
		$(tekoven).addClass("rotitemnone").fadeIn('slow');
		$(sleden).addClass("rotitemact");

		if(index>=2 && index<total) 
		{
			if(index<tekID) // reverse order
			{
				slideDown(index+2,index-1);
			}
			else // correct order
			{
				slideUp(index-2,index+1);
			}			
		}
		smeniArtikal(tekID,index);
		tekID=index;
	}
	anim(timeout,animID,index)
}
/* Control animation flow
* params:
* 	- timeout - time between function calls
* 	- aid - former animatin id ( parent )
* 	- idx - new animation id
*/
function anim(timeout,aid,idx) //timeout  
{
	total=sizeofElem('inrotate','div');
	clearTimeout(aid);
	if(reverse==1)
	{
		if(idx>1)
		{
			idx--;
			animID=setTimeout('animiraj('+timeout+','+idx+')',timeout);
		}
		else 
		{
			reverse=0;
			idx++;
			animID=setTimeout('animiraj('+timeout+','+idx+')',timeout);
		}
	}
	else if(reverse==0)
	{
		if(idx<total)
		{
			idx++;
			animID=setTimeout('animiraj('+timeout+','+idx+')',timeout);
		}
		else 
		{
			reverse=1;
			idx--;
			animID=setTimeout('animiraj('+timeout+','+idx+')',timeout);
		}
	}
}
function infotxtfInit()
{
	infotxtf=0;
}
function sizeofElem(elemname,base)
{
	str="#"+elemname+" > "+base;
	var x=$(str).size();
	return x;

}

function slideUp(index1,index2)
{
	gore="#item"+index1+"-title:visible";
	dolu="#item"+index2+"-title:hidden";
	$(gore).slideUp("fast",function() {//;
	$(dolu).slideDown("slow");
	});
}

function slideDown(index1,index2)
{
	gore="#item"+index2+"-title:hidden";
	dolu="#item"+index1+"-title:visible";
	$(dolu).slideUp("fast",function(){//;
	$(gore).slideDown("slow");
	});
}


function smeniArtikal(art1,art2)
{
	id1name="#intab"+art1;
	id2name="#intab"+art2;
	$(id2name).removeClass('tabshide');
	$(id1name).css('zIndex','2');
	$(id2name).css('zIndex','3');
	$(id2name).css('opacity','0.8');
	$(id1name).animate({
		//left: '+=175',
		right: '+=175',
		top: '+=63',
		width: '220',
		height: '150',
		opacity: '0.0'
	}, 500, function() {
		$(id1name).animate({
		//left: '-=175',
		right: '-=175',
		top: '-=63',
		width: '570',
		height: '276',
		opacity: '0.0'

	},100);
	$(id1name).addClass('tabshide');
	});
}
