// JavaScript Document

window.addEvent('domready', function(){
	var maxcolheight = 0;
	var handleflag = 0;
	
	if ($('faq_accordion') != null) {
		//create our Accordion instance
		var faq_accordion = new Accordion($('faq_accordion'), 'p.toggler', 'div.element', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#FFFFFF');
				toggler.getFirst().addClass('active');
				toggler.addClass('active');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#6A6A73');
				if (toggler.getFirst().hasClass('active'))toggler.getFirst().removeClass('active');
				if (toggler.hasClass('active'))toggler.removeClass('active');
			}
		});		
	}
	
	if ($('content_accordion_container') != null) {
		//create our Accordion instance
		var faq_accordion = new Accordion($('content_accordion_container'), 'h5.element_headline', 'div.element_container', {
			opacity: false,
			onActive: function(element_headline, element_container){
			element_headline.setStyle('color', '#FFFFFF');
			element_headline.getFirst().addClass('active');
			element_headline.addClass('active');
			},
			onBackground: function(element_headline, element_container){
				element_headline.setStyle('color', '#6A6A73');
				if (element_headline.getFirst().hasClass('active'))element_headline.getFirst().removeClass('active');
				if (element_headline.hasClass('active'))element_headline.removeClass('active');
			}
		});		
	}

	if ($('product_information') != null) {
		
		//set active element for compare bikes
		var active_element = 0;
		if (($('mcc_compare_bikes').getPrevious().hasClass('active'))) 
		{
			active_element=3 ;
			$('cmpproductlist').addClass('show');
		}
		//$('cmpproductlist').addClass('show');

		
		//create our Accordion instance
		var faq_accordion = new Accordion($('product_information'), 'h5.element_headline', 'div.element_container', {
			opacity: false,
			show: active_element,
			onActive: function(element_headline, element_container){
			element_headline.setStyle('color', '#FFFFFF');
			element_headline.getFirst().addClass('active');
			element_headline.addClass('active');
			if(($('mcc_compare_bikes').getPrevious().hasClass('active'))) $('cmpproductlist').addClass('show');			
			},
			onBackground: function(element_headline, element_container){
				element_headline.setStyle('color', '#6A6A73');
				if (element_headline.getFirst().hasClass('active'))element_headline.getFirst().removeClass('active');
				if (element_headline.hasClass('active'))element_headline.removeClass('active');
				if(!(($('mcc_compare_bikes').getPrevious().hasClass('active')))) $('cmpproductlist').removeClass('show');
			}
		});		
	}	
	
	if ($('product_accordion') != null) {
		//create our Accordion instance
		var productAccordion = new Accordion($('product_accordion'), 'h5.toggler', 'div.element', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#FFFFFF');
				toggler.getFirst().addClass('active');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#FFFFFF');
				if (toggler.getFirst().hasClass('active'))toggler.getFirst().removeClass('active');
			}
		});		
	}
	
	// Compare Bikes: remove submit button
	if ($('productselect') != null) {
		$('submitbutton').dispose();

		$('productselect').getChildren().each(function(el, index){
			el.addEvent('click', function(){
				el.getParent().highlight('#9FB000', '#E1E1E5');
				$('cmpproductlist').submit();		
			});
		});
	}
	
	if ($('propertycont') != null) {
		$$('#propertycont span.imgtooltip').each(function(el, index){ 
		//alert(index);
			el.getNext().addEvent('mouseenter', function(event){ 
				el.setStyles({
				    'margin-right': 0,
				    'margin-top': -41,
				    'margin-left': -9,
				    'margin-bottom': 0
				});
				el.style.display = "block";
				el.fade('show');
			});
			el.addEvent('mouseleave', function(event){ 
				el.fade('out');
				var delayFunction = function(){
					el.style.display = "none";
				};
				delayFunction.delay(500);
			});			
		}); 	
	
	}
	
	if ($('col1_contentleft') != null) { 
		var mainheight = $('main').getCoordinates().height;
		var v_navheight = $('col1_contentleft').getPrevious().getCoordinates().height;
		var col1_contentleftheight = $('col1_contentleft').getCoordinates().height;
		var col1_contentleft_toppos = mainheight - v_navheight - col1_contentleftheight + 3 - 35;
		//alert(col1_contentleft_toppos);
		//$('col1_contentleft').setStyle('margin-top', col1_contentleft_toppos+'px');
	}
 
});
