/* Author: Andreas Walter */
/* Company: Euroweb Internet GmbH */
/* Copyright: 2009 - Andreas Walter & Euroweb Internet GmbH */

/* ///////////////////////////////////////////////////////////
	=> mailmask 
/////////////////////////////////////////////////////////// */

function noSpam() {
	if (document.getElementById) {
		var at = "@";
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			var linkElem = links[i];
			if (linkElem.className == 'escape') {
				var mail = linkElem.firstChild; var domain = linkElem.lastChild;
				mail.nextSibling.firstChild.innerHTML = at;
				linkElem.href = "mailto:" + mail.data + at + domain.data;
			}
		}
	}
}

/* ///////////////////////////////////////////////////////////
	=> smoothScroll 
/////////////////////////////////////////////////////////// */

function smoothScroll() {
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 500);
                return false;
            }
        }
    });
}

/* ///////////////////////////////////////////////////////////
	=> backgroundColor 
/////////////////////////////////////////////////////////// */

(function(jQuery){
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}
			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});
	function getRGB(color) {
		var result;
		if ( color && color.constructor == Array && color.length == 3 )
			return color;
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
		return colors[jQuery.trim(color).toLowerCase()];
	}
	function getColor(elem, attr) {
		var color;
		do {
			color = jQuery.curCSS(elem, attr);
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 
			attr = "backgroundColor";
		} while ( elem = elem.parentNode );
		return getRGB(color);
	};
})(jQuery);

/* ///////////////////////////////////////////////////////////
	=> jQueryEeasing | easeInOutExpo
/////////////////////////////////////////////////////////// */

jQuery.extend( jQuery.easing,
{
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});

/* ///////////////////////////////////////////////////////////
	=> slideSwitch
/////////////////////////////////////////////////////////// */

function slideSwitch() {
	$('#navi').animate({width:'898px'},2000,'easeInOutExpo');
	var $active=$('#media img.active');
	var $activeColor=$active.attr('alt');
	$('#header').css({backgroundColor:$activeColor});
	if ($active.length==0)$active=$('#media img:last');
	var $next=$active.next().length?$active.next():$('#media img:first');
	var $activeColor=$next.attr('alt');
	$active.addClass('last-active');
	$next.css({opacity:0.0}).addClass('active').animate({opacity:1.0},4000,function(){
		$active.removeClass('active last-active');
	});
	$('#navi').animate({width:'150px',backgroundColor:'#'+$activeColor},2000,'easeInOutExpo');
	$('#header').animate({backgroundColor:'#'+$activeColor},6000,'easeInOutExpo');
}

/* ///////////////////////////////////////////////////////////
	=> sortimentSlide
/////////////////////////////////////////////////////////// */

function sortimentSlide(e) {
	$(e+' span').css({top:'50px',opacity:0.0});
	$(e).mouseenter(function(){$(this).children().stop().animate({top:'0px',opacity:1},150);}).mouseleave(function(){$(this).children().stop().animate({top:'50px',opacity:0},150);});
}

/* ///////////////////////////////////////////////////////////
	=> onload
/////////////////////////////////////////////////////////// */

$(function(){
	noSpam();
	smoothScroll();
	sortimentSlide('#sortiment li a');
	setInterval("slideSwitch()",10000);
	$('input.Search').attr('value','Suchbegriff eingeben').click(function(){if($(this).attr('value')=='Suchbegriff eingeben'){$(this).attr('value','');}
	}).blur(function(){if($(this).attr('value')==''){$(this).attr('value','Suchbegriff eingeben');}});
});
