/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	BASIC JS / MATESO Password Safe
	November 2009 / S2 INTERMEDIA GmbH / Roland Stern; Benno Weinzierl; Alexander Buch
	$Id: basic.js 11701 2011-10-19 16:56:54Z ms $
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Mootools specific
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
(function(){
	if (typeof(MooTools) == 'undefined') 
		return;
	var $ = document.id;
	
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       DD_belated // PNG Fix
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	window.addEvent('domready', function(e){
		if (Browser.Engine.trident4) {
			DD_belatedPNG.fix('img.logo, .s2-contentbox-1, .s2-contentbox-2, .s2-contentbox-3, .s2-contentbox-4');
		}
	});
	
	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    	Social Media
 	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	window.addEvent('domready', function(){
		
		if ($$('.social-media a')) {
		
			var morphSpeed = 300;
			
			$$('.social-media a').each(function(el){
				el.addEvents({
					mouseover: function(){
						this.set('morph', {
							duration: morphSpeed,
							transition: 'sine:in:out'
						});
						this.morph({
							'top': -4
						})
					},
					mouseout: function(){
						this.set('morph', {
							duration: morphSpeed,
							transition: 'sine:in:out'
						});
						this.morph({
							'top': 0
						})
					}
				});
			});
		};
	});
	
	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Navigation // Layer Menu // Active States
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	window.addEvent('domready', function(e){
		$$('div.navigation-main-zone>ul>li>a').each(function(link) {
			
			link.addEvents({
				'click': function(e){
					var e = new Event(e).stop();
				},
				'mouseenter': function(e){
					this.store('tmpTitle',this.get('title'));
					this.set('title',null);
				},
				'mouseleave': function(e){
					this.set('title',this.retrieve('tmpTitle'));
				}

			});
			
			link.getAllNext('ul').each(function(list) {
				list.addEvents({
					'mouseenter': function(e) {
						link.addClass('main-active');
					},
					'mouseleave': function(e) {
						if(list.getElements('a').every(function(a){return !a.hasClass('sub-1-active')})) {
							link.removeClass('main-active');
						}
					}
				});
			});
		});
	});
	
	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		Searchbox // Clear Input box
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	window.addEvent('domready', function(e){
		try{
			var inputSearch = $('searchbox-searchword').getProperty('value');
			$('searchbox-searchword').addEvents({
				'focus': function(e) {
					if($('searchbox-searchword').getProperty('value') == inputSearch){
						$('searchbox-searchword').setProperty('value','');
					}
				},
				'blur': function(e) {
					if($('searchbox-searchword').getProperty('value') == ''){
						$('searchbox-searchword').setProperty('value',inputSearch);
					}
				}
			});
		}catch(e){}
	});
	
	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		Sticky Win // Glossar / Tooltip
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	window.addEvent('domready', function(e){
	
		if ($$('.tooltip-link')) {
		
			CustomStickyWin = Class.refactor(StickyWin, {
				currentElement: null
			});
		
			var stickyWinGlobal = new CustomStickyWin({
				content: StickyWin.ui.pointy('', {
					direction: 10,
					theme: 'dark'
				}),
				position: 'upperLeft',
				offset: {
					x: 100,
					y: 100
				}
			});
			
			stickyWinGlobal.hide();
		}
	
		$$('.tooltip-link').each(function(el) {
			el.addEvent('click', function(e) {
				
				if (el.retrieve('stickyWinStatus') == 'open' && stickyWinGlobal.win.getStyle('display') == 'block') {
					stickyWinGlobal.hide();
					el.store('stickyWinStatus', 'close');
				} else {
					if (stickyWinGlobal.currentElement) stickyWinGlobal.currentElement.store('stickyWinStatus', 'close');
					stickyWinGlobal.position({
						relativeTo: el,
						offset: {
							x: 25,
							y: -15
						}
					});
					var stickyWinGlobalContent = $$('.'+el.get('rel'))[0].get('html');
					stickyWinGlobal.setContent(StickyWin.ui.pointy(stickyWinGlobalContent, {
						direction: 10,
						theme: 'dark'
					}));
					stickyWinGlobal.show();
					stickyWinGlobal.currentElement = el;
					el.store('stickyWinStatus', 'open');
				}
				

				
				/* Mehrere eigene Tooltips
				if (!el.retrieve('stickyWin') ) {
					var stickyContent = $$('.'+el.get('rel'))[0].get('html');
					var stickyWinTemp = new StickyWin({
						//content: stickyContent,
						content: StickyWin.ui.pointy(stickyContent, {
							direction: 10,
							theme: 'dark'
						}),
						position: 'upperLeft',
						relativeTo: el,
						offset: {
							x: 30,
							y: -17
						}
					});
					el.store('stickyWin', stickyWinTemp);
					el.store('stickyWinStatus', 'open');
				} else {
					if (el.retrieve('stickyWinStatus') == 'open') {
						el.retrieve('stickyWin').hide();
						el.store('stickyWinStatus', 'close');
					} else {
						el.retrieve('stickyWin').show();
						el.store('stickyWinStatus', 'open');
					}
				}
				*/
				
			});
			
		});
	});
	
	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		Accordion Menu 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	window.addEvent('domready', function(e){
		$$('.accordion-zone').each(function(el) {
			var myAccordion = new Fx.Accordion($$('.toggler'), $$('.toggler-element'), {
				display: -1
			});
		});
	});
	
	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		Product Intro
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	s2_passwordsafe_initialize_intro = function() {
		if (!$('product-intro-wrap')) return;
		
		$$('head>link').each(function(cssel) {
			if (cssel.getProperty('title') == 'productIntroCss') {
				cssel.set('href', 'typo3conf/ext/s2_template/base/css/intro_js.css');
			}
		});
	
		var productIntroStart = $('product-intro-start-wrap');
		var productIntroNavigation = $('product-intro-navigation-wrap');
		var productContents = $$('div#product-intro-content-wrap>div');
		var navigationButtons = $$('div#product-intro-navigation-wrap>div>div');
		var buttonFadeEffect = {duration: 200, transition: 'sine:in:out'};
		var generalFadeEffect = {duration: 1000, transition: 'sine:in:out'};
	
		$$('div#product-intro-start-wrap>div').each(function(startbutton) {
			startbutton.addEvents({
				'mouseenter': function(e) {
					startbutton.set('morph', buttonFadeEffect).morph({'top': '244px'});
				},
				'mouseleave': function(e) {
					startbutton.set('morph', buttonFadeEffect).morph({'top': '278px'});
				},
				'click': function(e) {
					startbutton.store('edition',startbutton.get('id').replace('start-button-', ''));
					
					productIntroStart.set('morph', $merge(generalFadeEffect, {'return': 'element', link: 'chain'})).morph({'opacity': [0.99, 0]});
					productIntroStart.get('morph').addEvent('complete', function(e){
						productIntroNavigation.set('morph', generalFadeEffect).morph({'display': 'block', 'opacity': [0, 0.99]});
						$('content-'+startbutton.retrieve('edition')).set('morph', generalFadeEffect).morph({'display': 'block', 'opacity': [0, 0.99]});
						$('navigation-button-'+startbutton.retrieve('edition')).set('morph', buttonFadeEffect).morph({'opacity': '0'});
					});
					
					//console.log(startbutton.retrieve('edition'));
				}
			});
		});
		
		// Testing 2 Ebene: $('content-enterprise').set('morph', generalFadeEffect).morph({'display': 'block', 'opacity': 1});
		
		navigationButtons.each(function(navigationButton) {
			navigationButton.store('edition',navigationButton.get('id').replace('navigation-button-', ''));
			navigationButton.store('active',false);
			
			navigationButton.addEvents({
				'mouseenter': function(e) {
					navigationButton.set('morph', buttonFadeEffect).morph({'top': '0px'});
				},
				'mouseleave': function(e) {
					if (!navigationButton.retrieve('active') || navigationButton.retrieve('active') == false) {
						navigationButton.set('morph', buttonFadeEffect).morph({'top': '10px'});
					}
					
					//console.log(navigationButton.retrieve('edition'),navigationButton.retrieve('active'));
				},
				'click': function(e) {
					
					navigationButtons.each(function(tempNavigationButton) {
						if (navigationButtons != tempNavigationButton) {
							tempNavigationButton.set('morph', buttonFadeEffect).morph({'top': '10px', 'opacity': 0.99});
							tempNavigationButton.store('active',false);
						}
					});
					
					productContents.each(function(productContent) {
						if ($('content-'+navigationButton.retrieve('edition')) != productContent) {
							productContent.set('morph', buttonFadeEffect).morph({'opacity': 0});
						}
					});
					
					navigationButton.set('morph', $merge(buttonFadeEffect,{'return': 'element', link: 'chain'})).morph({'top': '10px'}).morph({'opacity': '0'});
					$('content-'+navigationButton.retrieve('edition')).set('morph', generalFadeEffect).morph({'display': 'block', 'opacity': [0 ,0.99]});
					navigationButton.store('active',true);
					
					//console.log('click',navigationButton.retrieve('edition'),navigationButton.retrieve('active'));
				}
			});
		});
	}
	
	/**
	 * Inserts the javascript version of the intro to the page
	 * 
	 * @access global
	 * @param {string} lang
	 */
	s2_passwordsafe_insert_intro = function(lang) {
		new Request.HTML({
			url: 'typo3conf/ext/s2_template/base/tmpl/intro/'+lang+'.html',
			update: $('flash-intro-wrap'),
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
				s2_passwordsafe_initialize_intro();
			}
		}).get();
	}
	
})();

