// JavaScript Document

var activeElementId = 'd-reiter';
var oldElementId    = 'd-reiter';
var contentsXML     = [];
			
function createTeaserbox(){	

	jQuery.noConflict();
	
	jQuery.ajax({
		type:"GET",
		url: "xml/contents.xml",
		dataType: "xml",
		contentType: "application/x-www-form-urlencoded;charset=iso-8859-1",
		success:function(xml){
			var id = 0;
					
			jQuery(xml).find('teaser_content').each(function(){
			contentsXML[id] = jQuery(this);
			id++;
			currentReiter = jQuery('.teaser-box-reiter:nth-child('+id+')');
						
			// PRODUKTE AUFBAUEN
			var pId = 1;
			jQuery(this).find('products').children().each(function(){
				var lnk = jQuery(this).text();
				//alert(lnk);
				currentReiter.find('.productfield').find('map area:nth-child('+ pId +')').attr('href',lnk);
							
				pId++;
			});
						
			// CLICK - INTERAKTION
			currentReiter.find('#btn').click(function(){
				if(activeElementId != jQuery(this).parent().attr('id')){
								
					makeAnimations(jQuery('#'+oldElementId), jQuery(this).parent());
					swapButtons(jQuery('#'+oldElementId), jQuery(this).parent());
								
					activeElementId = jQuery(this).parent().attr('id');
					oldElementId = activeElementId;
				}
			});
						
		});
	}});
				
				
	// Initialisierung
	jQuery('#d-reiter').css('width', 820);
}

		
function makeAnimations(old, neu){
	jQuery(function(){
		jQuery(old).stop().animate({width:50}, 'slow', function(){
			//jQuery(this).hide();
		});
		jQuery(neu).stop().show().animate({width:820}, 'slow', function(){
			//floater(neu);
		});
	});
}
		
function swapButtons(old, neu){
	// Buttons tauschen
	var activeImgSrc = jQuery(neu).find('#btn').attr('src');
	activeImgSrc = activeImgSrc.replace('.png','');
	activeImgSrc += '_a.png';
	jQuery(neu).find('#btn').attr('src', activeImgSrc);
			
	var oldImgSrc = jQuery(old).find('#btn').attr('src');
	oldImgSrc = oldImgSrc.replace('_a.png','');
	oldImgSrc += '.png';
	jQuery(old).find('#btn').attr('src', oldImgSrc);
}
