var atom = {};
atom.log = function() {
  if (window.console && window.console.log) {
    console.log(arguments);
  }
};




window.addEvent('domready', function(){
	if($$('.flash-link-box a.popup-flash').length != 0)
		pdfFlashReader();
	
	
	if( $('banner')  )
		var slideshow = new SlideShow();
	
	
	var nav = $$('#wrap.front #head .nav > ul > li');
	
	nav.each(function(item){
		var sublist = item.getChildren('ul');
		var sublistchildren = 0;
		
		if( sublist.length > 0 ){
			sublistchildren = sublist[0].getChildren('li');
		}
		var itemFx = new Fx.Morph(item, { 'duration': 250, 'link': 'cancel' });
		
		if( sublistchildren.length > 0 )
		{
			
			var sublistFx = new Fx.Morph(sublist[0], { 'duration': 200, 'link': 'cancel' });
			var wrap = new Element('div', { 'class': 'wrap' } ).wraps(sublist[0]);
			var wrapFx = new Fx.Morph(wrap, { 'duration': 350, 'link': 'cancel', 'transition': Fx.Transitions.Circ.easeInOut });
			
			var wrapSize = wrap.getSize();
			wrap.setStyles({
				'height': 0
			});
			
			sublist.setStyles({
				'display': 'block',
				'opacity': 0
			});
			
			var timer;
			
			item.addEvents({
				'mouseenter': function(){
					timer = (function(){
						wrapFx.start({ 'height': wrapSize.y+10 });
					}).delay(250);
					
					sublistFx.start({ 'opacity': 1 });
					itemFx.start({ 'background-color': '#fff' });
				},
				'mouseleave': function(){
					timer = $clear(timer);
					
					wrapFx.start({ 'height': 0 });
					sublistFx.start({ 'opacity': 0 });
					itemFx.start({ 'background-color': '#ffcc00' });
					
				}
			});
			
		}
		else
		{
			item.addEvents({
				'mouseenter': function(){
					itemFx.start({ 'background-color': '#fff' });
				},
				'mouseleave': function(){
					itemFx.start({ 'background-color': '#ffcc00' });
				}
			});
		}
		
	});
	
	var subnav = $$('#wrap.sub #head .nav > ul > li');
	var subnavselected = $$('#wrap.sub #head .nav > ul > li.selected > a');
	
	//if( subnavselected[0] )
		var selFx = new Fx.Morph(subnavselected[0], { 'duration': 250, 'link': 'cancel' });
	
	subnav.each(function(item){
		//var sublistchildren = 0;
		var sublist = item.getChildren('ul');
		//console.log(sublist);
		
		//if( sublist.length > 0 )
			//var sublistchildren = sublist[0].getChildren('li');
		
		//if( sublistchildren.length > 0 )
		//{
			var itemFx = new Fx.Morph(item, { 'duration': 250, 'link': 'cancel' });
			
			//var wrap = new Element('div', { 'class': 'wrap' } ).wraps(sublist[0]);
			//var wrapFx = new Fx.Morph(wrap, { 'duration': 350, 'link': 'cancel', 'transition': Fx.Transitions.Circ.easeInOut });
			
			//var wrapSize = wrap.getSize();
			/*wrap.setStyles({
				'height': 0
			});*/
	
			item.addEvents({
				'mouseenter': function(){
					
					if( selFx )
						if( !item.hasClass('selected') )
							selFx.start({ 'background-color': '#ffcc00' });
					
					itemFx.start({ 'background-color': '#fff' });
					
					
					/*wrapFx.start({
						'opacity': 1
					});*/
					
				},
				'mouseleave': function(){
					
					itemFx.start({ 'background-color': '#ffcc00' });
					selFx.start({ 'background-color': '#fff' });
					
				}
			});
		//}
		
	});
	
	
	$$('ul.tabs').each(function(element){
		var tabs = element.getChildren('li');
		var tabareas = [];
		
		tabs.each(function(tab,index){
			var tabarea = tab.get('rel');
			tabareas.include( $(tab.get('rel')) );
			
			if(index != 0)
				$(tab.get('rel')).setStyle('opacity',0);
			
			tab.addEvent('click', function(e){
				e.stop();
				
				tabs.removeClass('selected');
				tab.addClass('selected');
				
				tabareas.each(function(element){
					element.fade('out');
				});
				
				$(tabarea).fade('in');
				
			});
		});
		
		
	});
	
	var Faq = new Fx.Accordion($$('.question'), $$('.answer'), {
		duration: 250,
		display: 0,
		alwaysHide: true,
		onActive: function(toggler, element){
			toggler.addClass('selected');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('selected');
		}
	});
	
	
	$$('.print-page').addEvent('click', function(){
		window.print();
	});
	
	
	
	if( $('feedback-popup') && $('show-feedback') ) 
	{
		var fpop = new AlvogenPopup( $('feedback-popup'), {
			width: 500
		});
		
		$('show-feedback').addEvent('click', function(){
			fpop.Show();
		});
		
		$$('.show-feedback').each(function(el){
		el.addEvent('click', function(){
			fpop.Show();
		});
		});
		

	}
	
});

// Dropdown for Alvogen Worldwide
window.addEvent('domready',function(){
	$$('.dropdown').each(function(drpItem) {
		drpItem.getElement('.drp-panel').slide('hide');
		drpItem.addEvent('mouseenter', function() {
			drpItem.getElement('.drp-panel').setStyle('visibility', 'visible');
			drpItem.getElement('.drp-panel').slide('in');
		});
		drpItem.addEvent('mouseleave', function() {
			drpItem.getElement('.drp-panel').slide('out');
		});
	});
});

window.addEvent('load', function(){
/*make yellow and grey box the same height in col middle*/
var row = $$('.r3 .row');
row.each(function(item){
	var box = item.getChildren('div.col div.box');
	var box2 = item.getChildren('div.col');
	var boxheight = 0;
	box.each(function(b){
	var size = b.getSize();
		//atom.log(size);
		if(boxheight < size.y){
			boxheight = size.y;		
		}
	});
	box.each(function(b){
		var size = b.getSize();
		if(boxheight > size.y){
			b.setStyle('height', boxheight-30);
		}
	});
});

});

	

	
	/*popup for pdf viewer from issuu*/
pdfFlashReader = function(){
	$$('.flash-link-box a.popup-flash').each(function(item) {
		item.addEvent('click', function(evt) {
			evt.stop();

			var winsize = window.getSize();
			var winscroll = window.getScroll();
			var winscrollsize = $(document.body).getScrollSize();
			
			var frame = new Element('div', {
				'class': 'video-frame',
				'styles': {
					'width': winsize.x-80,
					'height': winsize.y-80,
					'top': 40,
					'left': 40
				}
			}).inject( $(document.body) );
				var headline = new Element('h2', { 'class': 'cufon', 'text': item.get('title')}).inject( frame );
				var close = new Element('div', { 'class': 'close' }).inject( frame );
				var video = new Element('div', { 'class': 'video', 'html': '<div id="flash-container"></div>' }).inject( frame );
			
			var overlay = new Element('div', {
				'class': 'video-overlay',
				'styles': {
					'width': winscrollsize.x,
					'height': winscrollsize.y,
					'background': '#000',
					'opacity': 0.75
				}
			}).inject( $(document.body) );
			
			swfobject.embedSWF(item.get('href'), "flash-container", "100%", "100%", "9.0.0");
			
	
		
			
			
			$$(overlay,close).addEvent('click', function(){
				frame.destroy();
				overlay.destroy();
			});

		});
	});
}

