//Ajax-Handling
function updateNaviCart() 
{				
	var url = "index.php?article_id=69&updateNaviCart";
	if($$('.articleid_65')[0]){
		new Request.HTML({
			method: 'get',
			update: $('NavigationMitte'),
			url: url
		}).send();
	}
}

function closeShopInformation(){
	var shopInformation = $('shopInformation');
	shopInformation.get('morph').start( { 'opacity': 0 } ).chain(
		function(){
			shopInformation.dispose();
		}
	);
}

function showShopInformation() { // callAJAX
	var anchor = this;
	var listElement = anchor.getParent('li');
	var listElementSize = listElement.getSize();
	var anchorCoordinates = anchor.getCoordinates('wrapper');
	var pageid = anchor.get('href').split('-')[0];
	var url = "index.php?article_id=58&pageid=" + pageid;
	
	if($('shopInformation')){
		$('shopInformation').dispose();
	}
	
	var shopInformation = new Element('div',
		{
			'id': 'shopInformation',
			'styles': {
				'opacity': 0,
				// 'top': anchorCoordinates.top + listElementSize.y,
				'top': 40,
				// 'left': anchorCoordinates.left
				'left': 150
			},
			'events': {
				'click': closeShopInformation
			}
		}
	);
	shopInformation.inject($('wrapper'));

	new Fx.Tween('shopInformation',{
			onComplete: function(){

				new Request.HTML({
					method: 'get',
					update: shopInformation,
					url: url,
					onSuccess: function(responseText, responseXML){
						
						shopInformation.set('html', $('article_contents').innerHTML);
						new Fx.Tween('shopInformation').start('opacity', '0', '1');
						
					}
				}).send();			
			}
		}).start('opacity', '0');

	return false;
}


function initShopSearch(){
	var elements = $$('.shop_search_worldwide');
	var num_elements = elements.length;
	var list;
	if(num_elements > 0){
		elements.each(
			function(element){
				var listElements = element.getChildren('ul')[0].getChildren('li');
				listElements.each(
					function(el){
						var anchor = el.getChildren('a')[0];
						anchor.addEvent('click', showShopInformation.bind(anchor));
					}
				);
			}
		);
	}
	return false;
}

window.addEvent('domready',
	function(){
		updateNaviCart();
		initShopSearch();
	}
);

Cufon.replace('#headline h1');
