// JavaScript Document

window.addEvent('domready', function(){
	var maxcolheight = 0;
	var handleflag = 0;
	
	//alert("hallo2");
	
	maxcolheight = $('main').getSize().y;
	//var maxcolheightArray;
	//maxcolheightArray = $('main').getDimensions();
	//maxcolheightArray = $('main').getDimensions();
	//alert()
	//maxcolheight = maxcolheightArray['height'];
	
	//if(maxcolheight < $('col1').getSize().size.y) maxcolheight = $('col1').getSize().size.y;
	//if(maxcolheight < $('col2').getSize().size.y) maxcolheight = $('col2').getSize().size.y;
	
	// predefine page height (predefinedPageHeight variable from ts template)
	if(maxcolheight < predefinedPageHeight) 
		maxcolheight = predefinedPageHeight;
	//alert(maxcolheight);
	if ($('stage') == null) {
		//$('col3').setStyle('height', maxcolheight);
	    //$('main').setStyle('height', maxcolheight);
	}		if ($('hmc_right') != null) {		$('col2').setStyle('width', '10px');		$('col3').setStyle('margin-right', '10px');		$('col3').setStyle('border', 'none');		}

	if ($('product_information') != null) {
		var childrenlist = '';
		var selectedTab = 0;

		$('hmc_nav').getChildren().each(function(el, index){
			if (el.hasClass('active'))
			{
				selectedTab = index;
				if (selectedTab == index) {
					if (el.hasClass('active')==false) el.addClass('active');
				}
				else {
					if (el.hasClass('active')) 
						el.removeClass('active');
				}
			}
			el.getFirst().removeProperty('href'); 
		});		
		
		$('product_information').getChildren().each(function(el, index){
			//childrenlist = childrenlist+' '+el.getProperty('id');
			//alert(selectedTab);
			if (selectedTab == index) el.setStyle('display', 'block')
			else el.setStyle('display', 'none');
		});

		$('hmc_nav').getChildren().each(function(el, index){
			el.getFirst().addEvent('click', function(){
				selectedTab = index;

				$('hmc_nav').getChildren().each(function(el, index){				
					if (selectedTab == index) {
						if (el.hasClass('active')==false) el.addClass('active');
					}
					else {
						if (el.hasClass('active'))el.removeClass('active');
					} 
				});				
				
				$('product_information').getChildren().each(function(el, index){
					if (selectedTab == index) el.setStyle('display', 'block')
					else el.setStyle('display', 'none');
				});
			});
		});
	}

	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', '#E1E1E5');
				toggler.getFirst().addClass('active');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#C5C5CA');
				if (toggler.getFirst().hasClass('active'))toggler.getFirst().removeClass('active');
			}
		});		
	}

	if ($('productselect') != null) {
		//alert('Hallo');
		$('submitbutton').dispose();

		$('productselect').getChildren().each(function(el, index){
			el.addEvent('click', function(){
				el.getParent().highlight('#CC0833', '#E1E1E5');
				$('cmpproductlist').submit();		
			});
		});
		/*
		$('productselect').addEvent('click', function(){
				$('productselect').highlight('#CC0833', '#E1E1E5');
				$('cmpproductlist').submit();		
		});
		*/
	}

	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');
			}
		});		
	}	
 
});
