var shareIconsPath = 'fileadmin/templates/images/icons/';

document.observe('dom:loaded', function(e) {
		if ($('font-size-small') && $('font-size-medium') && $('font-size-large')) {
			$('font-size-small').observe('click', changeFontSize);
			$('font-size-medium').observe('click', changeFontSize);
			$('font-size-large').observe('click', changeFontSize);
		}
		
		var mailAFriendLink = $$('.mailafriend')[0];
		var mailAFriendForm = $('mail-a-friend-form');
			
		if (mailAFriendLink && mailAFriendForm) {
			mailAFriendLink.observe('click', function(e) {
					// Give the form a position in the center of the viewport
					var offset = document.viewport.getScrollOffsets();
					var wrapper = $('wrapper-all');
					var x = Math.round(wrapper.getWidth() / 2 - mailAFriendForm.getWidth() / 2);
					var y = Math.round(document.viewport.getHeight() / 2 - mailAFriendForm.getHeight() / 2);
					
					mailAFriendForm.style.position = 'absolute';
					mailAFriendForm.style.left = x + offset[0] + 'px';
					mailAFriendForm.style.top = y + offset[1] + 'px';
					
					Effect.toggle(mailAFriendForm, 'appear', {duration: 0.3});
					
					e.stop();
				}
			);
			
			var submit = mailAFriendForm.getInputs('submit')[0];
			var loading = $$('#mail-a-friend-form .loading')[0];
			
			submit.observe('click', function(e) {
					loading.show();
										
					new Ajax.Request(mailAFriendForm.action, {
							parameters: mailAFriendForm.serialize(true),
							onSuccess: function(transport) {
								
								loading.hide();
								submit.disable();
								//doneLoading.show();
							}
						}
					);
					
					submit.stopObserving('click');
					e.stop();
				}
			);
		}
		
		// start the carousel
		if(document.getElementById('carousel-bg')){
			new Carousel('carousel-wrapper', $$('#carousel-content .slide'), null, {auto: true, circular: true, effect: 'fade', duration: 0.5, frequency: 3} );
		}
	}
);

function changeFontSize(e) {
	var element = e.element();
	
	switch (element.id) {
		case 'font-size-small':
			//document.body.setStyle({fontSize: '0.95em'});
			document.body.style.fontSize = '0.95em';
			break;
		case 'font-size-medium':
			//document.body.setStyle({fontSize: '1.25em'});
			document.body.style.fontSize = '1.25em';
			break;
		case 'font-size-large':
			//document.body.setStyle({fontSize: '1.40em'});
			document.body.style.fontSize = '1.40em';
			break;
	}
	
	e.stop();
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = '; expires='+date.toGMTString();
	} else {
		var expires = '';
	}
	document.cookie = name+'='+value+expires+'; path=/';
}

function readCookie(name) {
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,'',-1);
}


