/*
(function() {
	var log = [], first, last;
	time = function(message, since) {
		var now = +new Date;
		var seconds = (now - (since || last)) / 1000;
		log.push(seconds.toFixed(3) + ': ' + message );
		return last = +new Date;
	};

	time.done = function(selector) {
		time('total', first);
		jQuery(selector).html(log.join('<br/>'));
	};
	first = last = +new Date;
})();
*/
// this snippet removes the link from the 'image cycle' image and moves it to the caption, and adds the 'mehr...' text.
jQuery(document).ready(function() {
	jQuery('.tx-imagecycle-pi1 li', '#banner').each(function(index, element) {
		jQuery(this).find('img')
			.removeAttr('longdesc')
			.attr('alt', '')
			.removeAttr('title');
		if (jQuery('a', this).size() > 0) {
			// if there is no link, don't unwrap and re-add 
			var link = jQuery('a', this).attr('href');
			jQuery(this).find('img').unwrap()
				.end()
				.find('span')
					.wrap('<a href="' + link + '"></a>')
					.append('<p>mehr &raquo;</p>');
		}
	});
	jQuery('div.tx-imagecycle-pi1').append('<div class="imagecycle_nav"></div>');
	jQuery('div.imagecycle_nav', '#banner')
		.append('<div id="imagecycle_prev">&laquo;</div')
		.append('<div id="imagecycle_pause">||</div>')
		.append('<div id="imagecycle_play">&gt;</div>')
		.append('<div id="imagecycle_next">&raquo;</div')
		.show().find('#imagecycle_play').hide();
		
	jQuery('#imagecycle_pause').click(function() { 
	    jQuery('.tx-imagecycle-pi1 ul')
			.cycle('pause');
		jQuery('#imagecycle_pause').hide();
		jQuery('#imagecycle_play').show();
	});
	jQuery('#imagecycle_play').click(function() { 
	    jQuery('.tx-imagecycle-pi1 ul')
			.cycle('resume');
		jQuery('#imagecycle_play').hide();
		jQuery('#imagecycle_pause').show();
	});
});

// animate 'Wanderpackages
var browserTimer = null;
var visibleEntity = 0;
var browserDelay = 8; // seconds
var numItems = jQuery('#content #nav-list .news-list-item').size();

jQuery(document).ready(function() {
  newsHeight = 0;
  numItems = jQuery('#content #nav-list .news-list-item').size();
  jQuery('#content #nav-list')
    .find('.news-list-item')
      .each( function(idx, elem) {
        if(jQuery(elem).outerHeight() > newsHeight) {
          newsHeight = jQuery(elem).innerHeight();
        }
      }).height(newsHeight)
    .end()
    .height(newsHeight)
    .find('.wrapper-list').width(220 * numItems).end();

    startTimer();
    showEntity(visibleEntity++);
})

function startTimer() {
        if ( browserTimer == null) {
                browserTimer = setInterval( 'triggerTimer()', browserDelay * 1000);
                //console.log('started timer');
        }
}
function stopTimer() {
        if (browserTimer != null) {
                clearInterval(browserTimer);
                bBrowserTimer = null;
                //console.log('timer stopped');
        }
}
function triggerTimer() {
        showEntity(visibleEntity);
        visibleEntity = (visibleEntity + 1) % numItems;
}
function showEntity($active) {
        jQuery('#content #nav-list .wrapper-list').animate( {left: $active * -220 }, 800);
	jQuery('#content #nav-actions').html($active);
        // console.log('timer fired' + $active)
}
