/**
 * MME Javascript stuff.
 * @author NOSE
 * 
 * @version 1.0.0 initial version
 *
 */
var MME = {

	/**
	 * Initialize.
	 */
	initialize : function() { 
		
		// develop
		//jQuery().devTools();
		
		// init all
		MME.initShuffler();
		MME.initVisual();
		MME.initTeaser();
		MME.initForms();
		MME.initHoverable();
		MME.initPrintLinks();
		
		// template employees
		if (jQuery("body.employees").size() > 0) {
			MME.initEmployees();
		}
	},
	
	/**
	* Initializes the hoverable.
	*/
	initHoverable: function() {
		
		// elements
		jQuery(".hoverable").each(function(i,els){
			
			// check
			if (jQuery("a",els).length > 0) {
				
				// events
				jQuery(els).bind("mouseenter",function(){
					jQuery("img",this).animate({opacity: 0.9}, 180);
					jQuery(this).addClass("hover");
				});
				jQuery(els).bind("mouseleave",function(){
					jQuery("img",this).animate({opacity: 1.0}, 300);
					jQuery(this).removeClass("hover");
				});
				jQuery(els).bind("click",function(){

					// modal
					if (jQuery(this).hasClass("modal")) {
						return true;
					}		
					// follow link
					var h = jQuery("a",this).attr("href");
					if (h == null) {
						h = jQuery(this).attr("href");
					};
					if (h != null) {
						window.location.href = h;
						return false;
					};
				});
				
			}
		
		});
	},
	
	/**
	* Initialize shuffler.
	*/
	initShuffler: function(ctx) {	
		// shuffler
		jQuery(".shuffler",ctx).each(function(i,el){
			jQuery(el).shuffler();
		});
	},
	
	/**
	* Initialize visuals.
	*/
	initVisual: function(ctx) {	
		// select current
		jQuery(".visuals .visual:first").addClass("current");
	},
	
	/**
	* Initializes the employees.
	*/
	initEmployees: function() {
		
		// employees
		jQuery(".employees").each(function(i,el){
			
			// employee break
			jQuery(".employee:nth-child(3n+1)",this).addClass("break");
			
			// employee link
			jQuery(".employee",this).each(function(j,employee) {
				
				// check
				if (jQuery("a",employee).length > 0) {

					// events
					jQuery(employee).bind("mouseenter",function(){
						jQuery(employee).addClass("hover");
					});
					jQuery(employee).bind("mouseleave",function(){
						jQuery(employee).removeClass("hover");
					});
					jQuery(employee).bind("click",function(){

						// follow link
						var h = jQuery("a",employee).attr("href");
						if (h == null) {
							h = jQuery(this).attr("href");
						};
						if (h != null) {
							window.location.href = h;
							return false;
						};
					});

				}
			});

		});
	},
	
	/**
	* Initializes the teaser.
	*/
	initTeaser: function() {
		
		// teaser
		jQuery(".teaser").each(function(i,teaser){

				
			// check
			if (jQuery("a",teaser).length > 0) {

					// events
					jQuery(teaser).bind("mouseenter",function(){
						jQuery(teaser).addClass("hover");
					});
					jQuery(teaser).bind("mouseleave",function(){
						jQuery(teaser).removeClass("hover");
					});
					jQuery(teaser).bind("click",function(){

						// follow link
						var h = jQuery("a",teaser).attr("href");
						if (h == null) {
							h = jQuery(this).attr("href");
						};
						if (h != null) {
							window.location.href = h;
							return false;
						};
					});

			}

		});
	},
	
	/**
	* Initializes a form.
	*/
	initForms: function() {
		
		// search
		var searchTitle = jQuery("#search_title").html();
		jQuery("#q").fieldEnhancer("cref_iframe","#cref_iframe",{"fieldValue":searchTitle});
		
	},
	
	/**
	* Initializes the print stuff.
	*/
	initPrintLinks: function() {
		jQuery(".printLink").click(function(){window.print();});
	}
}
jQuery(document).ready(function(){
	MME.initialize();
});




