var worldslide = new Object();

/* check which script needs to be loaded */

stc = {};
Event.observe(window, 'load', function() {
	if(typeof(console)!='object') console = {log: function(str) {alert(str)}};
	$$('body')[0].addClassName('stcActive');

	/* recentList */
	if($$('.recentList').length) {
		stc.recentLists = [];
		var i = 0;
		$$('.recentList').each(function(elm){
			elm.id = 'stcrt'+i;
			//console.log(elm.id);
			stc.recentLists.push(new recentList(elm.id));
			i++;
		});
	}
	
	/* topTeaserSlider */
	if($$('#bigTeaserSlideContainer .topTeaserBox').length > 1){
		var options = {
			elements:'div.topTeaserBox',
			handleContainer:'body',
			effectTransition: Effect.Transitions.sinoidal,
			effectDuration: 0.2,
			loop: false
		};
		
		/*<ul class="handles">
			<li class="one"><a href="#" rel="bigTeaserSlideContainer[0]">1</a></li>
			<li class="two"><a href="#" rel="bigTeaserSlideContainer[1]">2</a></li>
			<li class="three"><a href="#" rel="bigTeaserSlideContainer[2]">3</a></li>
		</ul>*/							
		
		var i = 0;
		$$('#bigTeaserSlideContainer .topTeaserBox').each(function(elm){
			var handlelist = new Element('ul',{'class':'handles'});
			var boxes = $$('#bigTeaserSlideContainer .topTeaserBox').length;
			if(boxes>0){handlelist.insert(new Element('li',{'class':'one'}).update(new Element('a',{'href':'#','rel':'bigTeaserSlideContainer[0]'}).update('1')));}
			if(boxes>1){handlelist.insert(new Element('li',{'class':'two'}).update(new Element('a',{'href':'#','rel':'bigTeaserSlideContainer[1]'}).update('2')));}
			if(boxes>2){handlelist.insert(new Element('li',{'class':'three'}).update(new Element('a',{'href':'#','rel':'bigTeaserSlideContainer[2]'}).update('3')));}
			elm.insert({'bottom':handlelist});
		});
		stc.topTeaserSlider = new simpleSlider('bigTeaserSlideContainer', options);
	}
	
	
	
	
	
	/* worldmap */
	
	if($$('#worldslide').length){
		worldslide = new simpleSlider('worldslide',{
			'elements': '.item',
			'effect': false
		});
		worldslide.slideTo($F('continent'));
		$('continent').observe('change', function(){
			//console.log(worldslide);
			worldslide.slideTo($F('continent'));
		});
		$('countryList').observe('change', function(){
			$('countryListForm').submit();
		});
		document.observe('simpleslider:slide:done', function(event){
			if(event.target.id.match(/worldslide/)){
				$('continent').selectedIndex = worldslide.currentActive;
				$('selectcontinent').update($('continent').options[worldslide.currentActive].text);
				//console.log(worldslide.currentActive, $('countryList').options[0].text, $('selectid'));
				$('countryList').selectedIndex = 0;
				$('selectid').update($('countryList').options[0].text);
			}
		});
	}
	
	/* accordion */
	if($$('.accordion').length){
		stc.accordion = [];
		var i = 0;
		$$('.accordion').each(function(elm){
			elm.id = 'stcacc'+i;
			stc.accordion.push(new simpleAccordion(elm.id));
			i++;
		});
	}
	
	/* readmore */
	if($$('.cbox .more').length){
		stc.readmore = [];
		var i = 0;
		$$('.cbox .more').each(function(elm){
			elm.id = 'stcrm'+i;
			i++;
			stc.readmore.push(new readMoreBox(elm.id));
		});
		document.observe('moreBox:done', function(event) {
			if(event.target.id.match(/stcrm/)){
				if(event.target.up('.tabwrapper')){
					var j = event.target.up('.tabwrapper').id.replace('tw','');
					$('tw'+j).up().setStyle({'height':($$('#tw'+j+' .tabcontent')[stc.tabs[j].currentActive].offsetHeight)+'px'});
				}
			}
		});
	}
	
	/* tabs */
	if($$('.tabbox').length){
		stc.tabs = [];
		var i = 0;
		var options = {
			effect:false,
			elements:'.tabcontent',
			handleContainer:'.tabs'
			
		};
		$$('.tabbox').each(function(elm){
			//console.log('hmm');
			elm.id = 'tabbox'+i;
			elm = elm.down('.tabwrapper');
			elm.id = 'tw'+i;
			
			$$('#'+'tabbox'+i+' .tabhandle').each(function(handle){
				handle.rel = handle.rel.replace(/tabhandle/, elm.id);
			});
			//console.log('hm',$$('#tw'+i+' .tabcontent')[0].offsetHeight);
			$('tw'+i).up().setStyle({'height':($$('#tw'+i+' .tabcontent')[0].offsetHeight)+'px'});
			stc.tabs.push(new simpleSlider(elm.id, options));
			i++;
			document.observe('simpleslider:slide:done', function(event) {
				if(event.target.id.match(/tw/)){
					var j = event.target.id.replace('tw','');
					$('tw'+j).up().setStyle({'height':($$('#tw'+j+' .tabcontent')[stc.tabs[j].currentActive].offsetHeight)+'px'});
				}
			});
		});
	}
	
	/* slideshow */
	if($$('.t2cSlideshow').length) {
		stc.slideShows = [];
		stc.slideShowUpdater = [];
		var i = 0;
		var options = {
			elements:'li',
			handleContainer:'body',
			effectTransition: Effect.Transitions.sinoidal,
			effectDuration: 0.3,
			loop: true
		};
		
		$$('.t2cSlideshow').each(function(elm){
			elm.id = 't2cSlideshow'+i;
			var tags = $F(elm.down('.tags'));
			elm = elm.down('.slideshow');
			elm.id = 'stcss'+i;
			$(elm.id).style.width = ($$('#'+elm.id+' li')[0].offsetWidth*10) + 'px';
			/* prepare handles */
			
			$$('#'+'t2cSlideshow'+i+' .handle').each(function(handle){
				handle.rel = handle.rel.replace(/handle/, elm.id);
			});
			stc.slideShows.push(new simpleSlider(elm.id, options));
			stc.slideShowUpdater.push(new slideShowUpdater(elm.id,stc.slideShows[i], i, tags));
			stc.slideShowUpdater[i].update(0, true);
			i++;
			
			/* $$('#'+elm.id+' li a').each(function(link){
				link.observe('click', function(evt){
					evt.stop();
					//console.log(link.rel);
					link.zoom = new simpleLayer(link.href, link.options);
					//console.log(link);
				});
			}); */
		});
		document.observe('simpleslider:slide:done', function(event) {
			if(event.target.id.match(/stcss/)){
				var i = event.target.id.replace('stcss','');
				var base = stc.slideShows[i];
				if((base.slideElements+1 - base.currentActive)<10 && base.lastDirection==1 && ((base.slideElements+1)%10)==0) {
					stc.slideShowUpdater[i].update(base.slideElements+1, false);
				}
			}
		});
	}
	
	/* Grusstext zaehlen */
	if($$('.grussmsg').length) {
		$$('.grussmsg').each(function(elm){
			//alert(elm.id);
			var elTextarea      = $(elm.id); 
			var elCountTarget   = $('counttarget_'+elm.id);
			var maxLength       = Number("250");
			
			elCountTarget.innerHTML = Number(maxLength) + " ";
			
			elTextarea.observe('keyup', function () {
				if( elTextarea.value.length >= maxLength ) {
					elTextarea.value = elTextarea.value.substring(0,maxLength);
					elCountTarget.innerHTML = "0";
				} else {
					elCountTarget.innerHTML = Number( maxLength-elTextarea.value.length ) +" ";
				}
			})
			
			if( elTextarea.value.length >= maxLength ) {
				elTextarea.value = elTextarea.value.substring(0,maxLength);
				elCountTarget.innerHTML = "0";
			} else {
				elCountTarget.innerHTML = Number( maxLength-elTextarea.value.length ) +" ";
			}
		});
	}
	
	/* ok, and some ieTweaks */
	if(Prototype.Browser.IE) {
		stc.ieTweaks = new ieTweaks();
	}
	//console.log(stc);
});