/*
 * speedART Modellauswahl
 * http://www.speedart.de
 *
 * Author: Gedankengut.de
 * Date: 2009-10-20
 */
 
// Stage 4 default caption
var txtShow = 'show infos';
var txtHide = 'hide infos';

// jQuery no conflict mode
jQuery.noConflict();

// disable anchors
jQuery('a.anchor').remove().prependTo('body');

// check anchor call
var currentFile = document.location.toString();
// the URL contains an anchor
if (currentFile.match('#')) {
	var currentAnchor = currentFile.split('#')[1];
} else {
	var currentAnchor = '';
}
	
// onload events
jQuery(document).ready(function() {
	// anchor call activates stage2
	if(currentAnchor != ''){
		jQuery('#p' + currentAnchor).addClass('active');
		jQuery('.p' + currentAnchor).show();
	}
	// STAGE 1
	jQuery('#stage1 li a').bind("mouseenter",function(event){
		jQuery('#stage1 li a').removeClass('active');
		jQuery(this).addClass('active');
		jQuery('.stage2').hide();
		jQuery('.' + jQuery(this).attr("id") + '').show();
	});
	// STAGE 3 bottom align
	jQuery('.stage2 > li').hover(function(){
		var currentPosition = jQuery(this).parent().find('> li').index(this);
		var subCount = jQuery('> ul > li',this).length;
		var positionCount = currentPosition + subCount;
		if(positionCount > 9 && currentPosition > 0){
			var positionOffset = (((positionCount - 9)*24)+26)*(-1); // 24 = height of <li>
			jQuery('.stage3',this).css('margin-top',positionOffset);
			jQuery('.stage4',this).css('margin-top',positionOffset);
		}
	});
	// STAGE 4 top align
	jQuery('.stage3 > li').hover(function(){
		var tmpParent = jQuery(this).parent().parent();
		var currentPosition2 = jQuery(this).parent().parent().parent().find('> li').index(tmpParent);
		var currentPosition3 = jQuery(this).parent().find('> li').index(this);
		var positionOffset = ((currentPosition2+currentPosition3)*25)*(-1)-25;
		var parentOffset = parseInt(jQuery(this).parent().css('margin-top').split('px')[0])+25;
		positionOffset -= parentOffset;
		jQuery('.stage4',this).css('margin-top',positionOffset);
	});
	// info button toggle
	jQuery('.stage4 .infoBtn').click(function(e){
		e.preventDefault();
		if(jQuery(this).text() == txtShow){
			jQuery(this).text(txtHide);
		} else {
			jQuery(this).text(txtShow);
		}
		jQuery(this).parent().find('.infoLayer').toggle();
	});
	// IE7 stage4 fix
	if(jQuery.browser.msie && jQuery.browser.version == 7){
		jQuery('.stage2').hover(function(){
			jQuery('.stage4').hide();
		});
	}
	// IE6 hover fix
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		jQuery('#cntModels li').hover(function(){
	    	jQuery(this).addClass('hover');
	    }, function() {
	    	jQuery(this).removeClass('hover');
	    });
	}
});