// Function for events calendar tool tips.
function initTips() {
	
	// Store the event titles.
	$$( 'a.product_tip' ).each( function( element, index ) {
		
		/* Get the title attribute and replace any instance of '::' with a <br /> tag so
		that multiple events will appear on a new line. */
		var content = element.get( 'title' ).replace( /::/g, '<br / >' );
		
		element.store( 'tip:title', content );
		
	});
	
	// Create the tooltips.
	var tips = new Tips( '.product_tip', {
					
		className: 'cal_tip_wrap',
		hideDelay: 50,
		showDelay: 50,
		fixed: true
		
	});
	
}

function initAccordion() {
	var cat = 0;
	
	if ($('initElement')) {
		cat = $('initElement').value;
	}
	
	var accordion = new Accordion( 'h3.toggle', 'div.accordion_content', {
							
		opacity: false,
		show: parseInt(cat),
		
		onActive: function( toggler, element ) {
		
			toggler.setStyle( 'background-position', '0 -35px' );
			
		},
		
		onBackground: function( toggler, element ) {
			
			toggler.setStyle( 'background-position', '0 0' );
			
		}

	}, $( 'accordion' ));

	
}

// Swap product detail tab system information
function initProductTabs() {

	var menuAnchors = $( 'detail_tabs' ).getElements( 'a' );

	for ( var i = 0; i < menuAnchors.length; i++ ) {

		if ( menuAnchors[ i ].getAttribute( 'href' ) && menuAnchors[ i ].getAttribute( 'rel' ) == 'swap' ) {

			menuAnchors[ i ].addEvent( 'click', function() {
				
				// Remove the active state from all links
				for ( var j = 0; j < menuAnchors.length; j++ ) {
					
					menuAnchors[ j ].getParent( 'li' ).removeClass( 'active' );
					
				}
				
				swapProductContent( this.id );

			});

		}

	}

}

function swapProductContent( _id ) {
	// Set the active state on the selected link // ////////////////////////////// // AR - Changed the first tab ID from description to descriptionZ because IE JS didn't like that ID??????
	$( _id ).getParent( 'li' ).addClass( 'active' );

	var tabs = $$( '.details' );
	
	for ( var i = 0; i < tabs.length; i++ ) {

		tabs[ i ].setStyle( 'display', 'none' );		

	}

	var newID = 'content_' + _id;

	var content = $( newID ).setStyle( 'display', 'block' );
	
}

window.addEvent( 'domready', function() {
	
	// Accordion
	if( $( 'accordion' ) ) initAccordion();
	
	// Product detail tabbing system
	if( $( 'detail_tabs' ) ) initProductTabs();
	// Tool tips
	if( $( 'image_detail' ) ) initTips();
	
	// Init drop down menu in header
	var industryList = new createDropDown({
		
		Menu: 'product_guide',
		Button: 'guide_button',
		OptionList: 'guide_list',
		InputField: 'guide_input'
		
	});
	
});