var MCS = {};


MCS.carousel = {
   
 		slideShow: function(speed) {
 
            if(speed == 0 || speed == '') {
	        	if(jQuery('#stage .stageCarousel[class*=interval-]').length >= 1) {
					var intRaw = jQuery('#stage .stageCarousel').attr('class').split(" ")[1]; //.className.match(/interval-(\d+)/)[1];
				   	speed = parseInt(intRaw.split("-")[1]) * 1000;
				} else {
					speed = 6000;
				}
			} else {
				speed = speed;
			}
			
			//Set the opacity of all images to 0
			jQuery('#stage .stageCarousel .stageImage').css({display: 'none'});


			//Get the first image and display it (set it to full opacity)
			jQuery('#stage .stageCarousel .stageImage:first').fadeIn(1000, function() {
				jQuery(this).addClass('show');
			});


			//Call the gallery function to run the slideshow
			var timer = setInterval('MCS.carousel.gallery()',speed);


		},


		gallery: function() {


			//if no IMGs have the show class, grab the first image
			var current = (jQuery('#stage .stageCarousel .stageImage.show'));
			
			var next;
			if(current.next().length == 1) {
			   	next = current.next(); 
			} else {
				next = jQuery('#stage .stageCarousel .stageImage:first');
			}
			//Set the fade in effect for the next image, show class has higher z-index
			next.fadeIn(1000, function() {
				jQuery(this).addClass('show');
			});	


			//Hide the current image
			current.fadeOut(1000, function() {
				jQuery(this).removeClass('show');
			});


		}
}


MCS.plz = {
	strDefault : "",
	
	init: function() {
	  this.strDefault = jQuery('.mcs-plz-suche input[type=text]').attr('value');
	
	  jQuery('.mcs-plz-suche input[type=text]').bind('focus', function() {
		   jQuery(this).attr('value', '');
	  });
	  
	  jQuery('.mcs-plz-suche input[type=text]').bind('blur', function() {
		   if(jQuery(this).attr('value') == '' || jQuery(this).attr('value') == MCS.plz.strDefault) {
			jQuery(this).attr('value', MCS.plz.strDefault);
		}
	  });
	}
}


MCS.regionSelect = {
	
	init: function() {
		
		jQuery("#region div.jqTransformSelectWrapper ul li a").click(function(){
			var value = jQuery("#region div.jqTransformSelectWrapper span").text();
			var selection = jQuery('#region-select option:selected').attr('value');
			
			if(selection !== 'default') {
				window.location.href = selection;
			}


		});
	}
}

MCS.enhanceForms = {
	
	init: function() {
		if(jQuery.browser.msie == true && parseInt(jQuery.browser.version, 10) < 8) {
			jQuery('.form-wrapper input[type=text], .form-wrapper textarea, .mcs-plz-suche input').bind('focus', function() {
				jQuery(this).addClass('focus');
			});
			jQuery('.form-wrapper input[type=text], .form-wrapper textarea, .mcs-plz-suche input').bind('blur', function() {
				jQuery(this).removeClass('focus');
			});
		}
	}
}


jQuery(document).ready(function() {
    jQuery("#region").jqTransform();
	jQuery('.form-wrapper').jqTransform();
	MCS.plz.init();
	MCS.regionSelect.init();
	MCS.carousel.slideShow(0);
	MCS.enhanceForms.init();
	if(jQuery.browser.msie == true && parseInt(jQuery.browser.version, 10) < 8) {
		if(jQuery('#stage').length < 1 && jQuery('#region').length > 0) {
			jQuery('#wrapper-2').css('zIndex', '-999');
		}
		jQuery('div.super-list h3 a').bind('click',function() {
			setTimeout(function() {
				jQuery('#site-info').css('margin-bottom', parseInt(jQuery('#site-info').css('marginBottom')) - 1 +'px');
			}, 100);
			
		});
	}
});


