/**
 *  Copyright Alnovi
 *  All Rights resered 
 *  Author: Andreas Jonderko
 */



var Site = {
	start: function(){
		Site.startBoxAnimation();
		Site.startLightBox();
		Kwix.start();
		
	},
	startLightBox:function(){
		if (jQuery.fn.lightBox){
			jQuery('a.thumbnail').each(function(){
				jQuery(this).attr('href', jQuery(this).find('img').attr('src'));
			});
			jQuery('a.thumbnail').lightBox({
			imageLoading:			'fileadmin/templates/gfx/lightbox-ico-loading.gif',
			imageBtnPrev:			'fileadmin/templates/gfx/lightbox-btn-prev.gif',
			imageBtnNext:			'fileadmin/templates/gfx/lightbox-btn-next.gif',
			imageBtnClose:			'fileadmin/templates/gfx/lightbox-btn-close.gif',
			imageBlank:				'fileadmin/templates/gfx/lightbox-blank.gif',
			txtImage : 'Bild',
			txtOf: '/'
			});
		}
	},
	startBoxAnimation : function(){
		var elements = jQuery.find('.content_element_outer');
		
		var highLightColor = '#ffaa86'; 
		
		var bodyClass = jQuery('body').className;
		switch (bodyClass){
			case 'hosting':
				highLightColor = '#a9cc66';
			break;
			
			case 'developer':
				highLightColor = '#66cccc';
			break;
		}
		
		elements.each(function(el, i){
			//var bgColor = el.getStyle('backgroundColor');
			//var border = el.getStyle('border');
			//el = jQuery(el);
			var border = '#f7f7f7';
			var initialAlpha = 0.7;
			var afterAlpha = 0.9;
			
			// set all elements besides the first and the news container to lower opacity
			var isNews = el.className.search(/news/i);
			if (i>0 && isNews==-1) 
			try{
				el.set('opacity', initialAlpha);
			} catch(e) {
				// Could not set opacity
			};
			
			
			el.addEvents({
				mouseenter: function(){
				
					// This morphes the opacity and backgroundColor
					try{
						this.morph({
							opacity: 1,
							'border-color': highLightColor
						});
					} catch(e){
						var exampleFx = new Fx.Style(this, 'opacity', {
							duration: 1000, 
							transition: Fx.Transitions.Quart.easeInOut
						});
						exampleFx.start(el.getStyle('opacity'),1); 
					}
				},
				mouseleave: function(){
					// Morphes back to the original style
					try{
						this.morph({
							opacity: afterAlpha,
							'border-color': border
						});
					}catch(e){
						//alert(e);
						var exampleFx = new Fx.Style(this, 'opacity', {
							duration: 1000, 
							transition: Fx.Transitions.Quart.easeInOut
						});
						exampleFx.start(el.getStyle('opacity'),afterAlpha); 
					}
				}
			});

			
		});
	}
};




var Kwix = {

	start: function(){
		Kwix.parseKwicks();
	},

	parseKwicks: function(){

		var squeeze_to = 100;
		var max_width = 160;

		//get original widths
		var start_widths = new Array();
		var kwicks = $$('.kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 250, transition:Fx.Transitions.Cubic.easeOut});
		
		kwicks.each(function(kwick, i){
			start_widths[i] = kwick.getStyle('width').toInt();

			//mouse is in, squeeze and expand
			kwick.addEvent('mouseenter', function(e){

				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), max_width]
				};
				var counter = 0;
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != squeeze_to) obj[j] = {'width': [w,squeeze_to] };
					}
				});
				fx.start(obj);
			}
			);
		});
		
		
		//mouse is out, squeeze back
		$('menu1').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), start_widths[j]]};
			});
			fx.start(obj);
		});
		
	}
	
};

//lock and load!

jQuery.noConflict();

jQuery(function() {
	Site.start();
});