
(function($){
$.fn.uid = function(prefix) {  
	if (!prefix) {
		prefix = "uid";
	}
	var generate = function() {
		var dt = new Date().getMilliseconds();
		var num = Math.random();
		var rnd = Math.round(num*100000);
		return prefix+dt+rnd;
    };
	return this.each(function() {
		this.id = generate();
   		return $;
	});  
 };
})(jQuery);


function showContent(handler, content, prev) {
	if(prev.handler && prev.content.is(':visible')) {
		closeContent(prev.handler, prev.content, {complete:function(){
			prev.open = 0
			prev.handler.text(LOCAL_LANG.showContent)
			// naechsten Content anzeigen
			if(prev.handler.attr('id') != handler.attr('id')) {
				showContent(handler, content, prev)
			}
		}})
		return
	}
	

	handler.text(LOCAL_LANG.hideContent)
	content.animate({height: handler.attr('rel')}, {duration:500, easing:'easeOutQuad', complete: function() {
	}})
}
function closeContent(handler, content, obj) {
	content.animate({height: 0}, {duration:500, easing:'easeOutQuad', complete:function() {
		content.hide()
		obj.complete()
	}})
	//content.hide('slow')
}
function initAccordion() {
	var $ = jQuery
	var c = 0

	var prevContent = {handler:0,content:0, open:0}
	$('.accordion .box, .box-group').each(function() {
//alert($(this).hasClass('textpic-layout-25'))
		if($(this).hasClass('textpic-layout-25')) {
			
			// Thumbnails
			$(this).prepend('<div class="left"></div><div class="right"></div>')
			$(this).find('.header').appendTo($(this).find('.left'))
			$(this).find('.images').appendTo($(this).find('.right'))
		} else {
			//	Das erste Content Bild muss vor den Titel plaziert werden
			/*
			var imgCont = $(this).find('.text-with-image')
			var imgHeight = imgCont.height()
			imgCont.prependTo($(this))
			var imgCapt = imgCont.find('.caption')
			var mt = (imgHeight - imgCapt.height())
			imgCapt.css('margin-top',mt+'px')
			*/
			//imgCont.find('.content').removeClass('.content')
			
		}
		
		// versteckten Content zum oeffnen vorbereiten
		var contentBlock = $(this).find('.content').not('.textpic-layout-26 .text > .content')

		
		// Falls es einen folge link gibt (zu einer anderen Seite), 
		// wird hier sichergestellt das er auch versteckt wird
		$(this).find('.followpage').appendTo(contentBlock)

		//contentBlock.css('border','1px solid')
		var height = contentBlock.height()
		if($.browser.msie) {
			height = contentBlock.get(0).offsetHeight
		}
		//return
//			alert(height)
		contentBlock.hide()
		contentBlock.css('height',0)

		if($(this).has('.header > h3').length) {
			$(this).find('h3:first').append('<a class="readmore" href="javascript:return false;" rel="'+height+'">'+LOCAL_LANG.showContent+'</a>')
		} else {
			$(this).find('h2:first').append('<a class="readmore" href="javascript:return false;" rel="'+height+'">'+LOCAL_LANG.showContent+'</a>')
		}

//		$(this).has('h3').find('h3').append('<a class="readmore" href="javascript:return false;" rel="'+height+'">'+LOCAL_LANG.showContent+'</a>')
//		$(this).find(':has(h2)').append('<a class="readmore" href="javascript:return false;" rel="'+height+'">'+LOCAL_LANG.showContent+'</a>')

		
		$(this).find('a.readmore').uid() // uid generieren, damit die links eine eindeutige bezeichnung haben
		$(this).find('a.readmore').click(function(){
			$(this).blur()
			//	content oeffnen
			showContent($(this), contentBlock, prevContent)
			prevContent = {handler:$(this),content:contentBlock, open:1}
		})
		c+=1
	})
	
}


function initImages() {
	var $ = jQuery
	
	$('#content .right .images').each(function() {
	var len = $(this).find('.image').length
	if(len<=1) {
		return
	}
	$(this).wrapInner('<div class="items"></div>')
	$('<div class="menu"><a class="prev" href="javascript:return false;">&lt;</a><a class="next" href="javascript:return false;">&gt;</a></div>').insertAfter($(this))
	//$('.right .images .image').appendTo($('.right .images .items'))

	$(this).scrollable({
		size: 1,
		onSeek: function(obj,index) {
			//changeText(index,len)
		}, 
		onUpdate:function() {

		}
	}).mousewheel()
	var menu = $(this).find('.menu')
		
	//menu.css('margin-left', ($(this).width() - menu.width()) +'px')
	//menu.css('margin-top', ($(this).height() - menu.height()) +'px')
	var next = menu('.next')
	next.click(function(){
		$(this).scrollable().next();
	})	
	$(this).find('.menu .prev').click(function(){
		$(this).scrollable().prev();
	})

})
//	$('.right .images').seekTo(2)

return
	$('#leftCol .images .image .caption').hide();
	
	$('#leftCol').append('<div id="imageMenu"><ul class="menu"></ul><div class="caption"><p class="caption"> leer </p></div></div>')
	var imgMenu = $('#imageMenu ul.menu')
	imgMenu.append('<li class="prev"><a class="prev" href="">&lt;&nbsp;&nbsp;</a></li>')
	imgMenu.append('<li class="stopplay"><a class="stopplay" href="">start</a></li>')
	imgMenu.append('<li class="next"><a class="next" href="">&nbsp;&nbsp;&gt;</a></li>')
	//$('#leftCol .images').scrollable().seekTo(0)
	imgMenu.find('a.prev').click(function(){$(this).blur(); if(g_ImageTimer) startStopAnimation(); $('#leftCol .images').scrollable().prev(); return false;})
	
	var playing = false
	
	imgMenu.find('a.stopplay').click(function(){
		$(this).blur()
		startStopAnimation()
		return false;
	})
	imgMenu.find('a.next').click(function(){$(this).blur(); if(g_ImageTimer) startStopAnimation(); $('#leftCol .images').scrollable().next(); return false;})
	changeText(0,len);
	
	//var deinTimer = window.setTimeout(changeImage, 3000)
	
}	

jQuery(document).ready(function() {
	var $ = jQuery
	initAccordion()
	initImages()
});

