// JavaScript Document
var data_arr;
var aktEntryIndex = 0;

function initNewsTeaser(post_arr,teaser_arr,urls_arr) {
	data_arr = post_arr;
	teaser_arr = teaser_arr;
	urls_arr = urls_arr;
	numEntry = data_arr.length;
	for(var i=0;i<numEntry;i++) {
		myDate = data_arr[i].post_date;
		if(myDate.length == 7) {
			myDate = "0"+myDate;	
		}
		myTitle = data_arr[i].post_title;
		myTeaser = data_arr[i].post_content;
		myURL = urls_arr[i];
		// Strip Teasertext
		var indexPos = myTeaser.indexOf('<!--more-->');
		myTeaser = myTeaser.substr(0,indexPos-1);	
		
		teaserImage = teaser_arr[i];
		elementContent = "<a href='"+myURL+"'>";
		elementContent += "<div class='teaserimage'><img src='"+teaserImage+"' alt='"+myTeaser+"' ></img></div></a>";
		element = $('#newsteaserimagelist #news'+i).html(elementContent);
		
		elementContent = "<div class='teasertext'><span class='title'>"+myDate+' '+myTitle+"</span><p class='desc'>"+myTeaser+"<a href='"+myURL+"'>Mehr ...</a></p></div>";
		element = $('#newsteasertextlist #newstext'+i).html(elementContent);
		
	}
	initButtons();
	
}

function initButtons() {
	$('#prevBtn').click(function(e) {
		showPrevEntry();
	})
	$('#nextBtn').click(function(e) {
		showNextEntry();
	})
	checkArrows();	
}
function showPrevEntry() {
	if(aktEntryIndex-1 >=0) {
		aktEntryIndex--;
		home_showEntry(aktEntryIndex);
	}
}
function showNextEntry() {
	if(aktEntryIndex+1 < numEntry) {
		aktEntryIndex++;
		home_showEntry(aktEntryIndex);	
	} 
}
function checkArrows() {
	if(aktEntryIndex == 0) {
		$('#prevBtn').hide();	
	} else {
		$('#prevBtn').show();		
	}
	if(aktEntryIndex == numEntry-1) {
		$('#nextBtn').hide();	
	} else {
		$('#nextBtn').show();	
	}
}
function home_showEntry(index) {
	imageWidth = 656;
	textHeight = 315;
	
	targetX = index * imageWidth;
	
	targetY = index* textHeight;
	
	$('#newsteaserimagelist').animate( {marginLeft:-targetX}, {duration: 1000,easing:"easeOutExpo"});
	$('#newsteasertextlist').animate( {marginTop:-targetY}, {duration: 1000,easing:"easeOutExpo" });
	checkArrows();
}

/* Testimonial */
function initTestimonial(post_arr,image_arr) {
	data_arr = post_arr;
	images_arr = image_arr;
	numEntry = data_arr.length;
	if(numEntry >2) {
		numEntry = 2;
	}
	for(var i=0;i<numEntry;i++) {
		myDate = data_arr[i].post_date;
		myTitle = data_arr[i].post_title;
		myTeaser = data_arr[i].post_content;
		
		imageHTML = "<img src='"+images_arr[i]+"'</img>";
		$('#testimonial #box'+i+' .testiImage').html(imageHTML);
		
		titleHTML = myTitle;
		$('#testimonial #box'+i+' .testiTitle').html(titleHTML);
		
		textHTML = myTeaser;
		$('#testimonial #box'+i+' .testiText').html(textHTML);
		
		
	}
	
	
}





