var count, counthalf, currentItem, dir, label, el;
var imageArray = new Array();
var textArray = new Array();
var hideArray = new Array();
var xfaktor = 0.5;
var active = 0;




jQuery(document).ready(function() {
	
	//jQuery(".user-eyecatcher-pi1").hide()
	//jQuery(".user-eyecatcher-pi1 img").each()
	
	
	// show next prev
	jQuery('.eye-btn').show();
	// hide all images
	resizeImage(jQuery('.image-item').find('img'),xfaktor);
	jQuery('.image-item').hide();
	
	// set variables
	count = parseInt(jQuery('.count').html()); 	// counter namen
	counthalf = parseInt((count+1)/2); 			// startelement
	currentItem = counthalf; 					// current counter name
	dir = 0;									// item forward 1; item backward -1
	
	
	label = jQuery('.label-text');				// label element
	
	Cufon.replace('.label-text');
	
	jQuery('.image-item').each(function(){
		imageArray.push(jQuery(this));			// image elemente
	});
	jQuery('.text-item').each(function(){
		textArray.push(jQuery(this));			// text elemente
	});
	
	firstContent(dir, xfaktor);

	jQuery('.eye-btn').click(function(){
		if(active == 0){
			active = 1;
		el = jQuery(this);
		if(el.hasClass('btn-back')){
			dir = -1;
		} else
		if(el.hasClass('btn-fwd')){
			dir = 1;
		};
		
		moveContent(dir, xfaktor);
		}
		//el.addClass('active');
		return false;
	});
	
});

// change maincontent
function firstContent(altdir, faktor){
	currentItem = currentItem + altdir;
	prevItem = currentItem - 1;
	nextItem = currentItem + 1;
	
	label.html(textArray[currentItem].html());
	imageArray[currentItem].css({'left': '250px', 'z-index':'700', 'bottom': '0'}).show()
	.find('img').css({'width':imageArray[currentItem].find('img').outerWidth()/faktor});
	
	imageArray[prevItem].css({'left': '75px', 'z-index':'680', 'bottom': '-100'}).show();
	imageArray[nextItem].css({'left': '435px', 'z-index':'680', 'bottom': '-100'}).show();

}

function resizeImage(imgData, faktor){
	var width = imgData.outerWidth()*faktor;
	imgData.css('width', "200");
}

function moveContent(altdir, faktor){
	if( (currentItem == 0 && altdir == -1) || (currentItem == count && altdir == 1) ){
		active = 0;
		return false;
	}
	oldItem = currentItem;
	currentItem = currentItem + altdir;
	prevItem = currentItem - 1;
	nextItem = currentItem + 1;
	
	for(i = 0; i <= count; i++){
		if(i != prevItem && i != currentItem && i != nextItem){
			imageArray[i].fadeOut();
		};
	};
	
	label.html(textArray[currentItem].html());
	
	Cufon.replace('.label-text');
	
	if(altdir == 1){
			imageArray[prevItem].animate({'left': '75px', 'bottom': '-100'}).css({'z-index':'680'}).show()
			.find('img').css({'width': imageArray[prevItem].find('img').outerWidth()*faktor});
		if(nextItem <= count){
			imageArray[nextItem].css({'left': '435px', 'bottom': '-100'}).css({'z-index':'680'}).fadeIn(1000)
			.find('img').animate({'width': imageArray[nextItem].find('img').outerWidth()});
		}
	};
	if(altdir == -1){
			imageArray[nextItem].animate({'left': '435px', 'bottom': '-100'}).css({'z-index':'680'}).show()
			.find('img').css({'width': imageArray[nextItem].find('img').outerWidth()*faktor});
		if(prevItem >= 0){
			imageArray[prevItem].css({'left': '75px', 'bottom': '-100'}).css({'z-index':'680'}).fadeIn(1000)
			.find('img').animate({'width': imageArray[prevItem].find('img').outerWidth()});
		}
	};
	
	
	
	imageArray[currentItem].animate({'left': '250px', 'bottom': '0'}).css({'z-index':'700'}).show()
	.find('img').animate({'width':imageArray[currentItem].find('img').outerWidth()/faktor}, 1000, function(){
		active = 0;
	});
	
}

