/**
 * mittt.de
 *
 * (en) fixed header and color animation of nav
 * (de) fixierter Kopfbereich und Fabranimation der Navigation
 *
 * @copyright       Copyright 2011, NBproMedia WebDesign GbR, Nils Barenbrock und Felizitas Boecher
 *
 * @link            http://www.NBproMedia.com
 * @version         1.0.0
 * @lastmodified    $Date: 2011-05-30 02:18:15 +0100 (30. Mai 2011) $
 */

$(document).ready(function() {
	$('a[class^="lightbox"]').fancybox({
		'titlePosition' : 'over',
		'overlayColor' : '#000',
		'overlayOpacity' : '0.5',
		'hideOnContentClick' : 'true',
		'speedIn' : '100',
		'speedOut' : '100',
		'changeSpeed' : '100',
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'padding' : '0',
	});
	// JavaScrip css switch
	$('body').addClass('js');
	// fix fixed positioning
	emulateScroll('#header');
	emulateScrollInner('#col1_content');
	emulateScrollInner('#col3_content');
	
	// prepare for animation
	$('#nav > ul > li > a:not(:has(strong))').attr({style:"color: rgb(0, 0, 0);"});
	$('#nav > ul > li > a > strong').attr({style:"color: rgb(81, 81, 81);"});
	$('#nav-sub > ul > li > a:not(:has(strong))').attr({style:"color: rgb(81, 81, 81);"});
	$('#nav-sub > ul > li > a > strong').attr({style:"color: rgb(81, 81, 81);"});
	$('#nav-sub > ul > li:has(ul) > a > strong').attr({style:"color: rgb(0, 0, 0);"});
	$('#nav-sub > ul > li > ul > li a:not(:has(strong))').attr({style:"color: rgb(122, 122, 122);"});
	$('#nav-sub > ul > li > ul > li a > strong').attr({style:"color: rgb(255, 81, 81);"});
	
	// animate main menu
	animateMenu("#nav > ul > li > a:not(:has(strong))","#ff0500", "#000");
	animateMenu("#nav > ul > li > a > strong", "#ff0500", "#515151");
	
	// animate sub menu
	animateMenu("#nav-sub > ul > li > a:not(:has(strong))", "#ff0500", "#515151");
	animateMenu("#nav-sub > ul > li > a > strong", "#ff0500", "#000");
	
	// animate sub sub menu
	animateMenu("#nav-sub > ul > li > ul > li > a:not(:has(strong))", "#ff0500", "#7a7a7a");
	animateMenu("#nav-sub > ul > li > ul > li >  a > strong", "#ff0500", "#515151");
});

// emulate verticalScroll functions

function emulateScroll(element){
	var elem = $(element);
	var win  = $(window);
	win.scroll(function() {
		elem.css('left', win.scrollLeft()*-1/13+'em');
	});	
}

function emulateScrollInner(element){
	var elem = $(element);
	if(element == '#col1_content') {
		elem.css({
			width: elem.width()/13+'em',
			height: (elem.height()+6)/13+'em'
		});
		var wrap = $('<div id="'+element+'_fixed">').css({
			position: 'fixed',
			width: 15.3846+'em',
			height: (elem.height()+6)/13+'em'
		});
	} else {
		elem.css({
			width: 15.3846+'em',
			height: elem.height()/13+'em'
		});
		var wrap = $('<div id="'+element+'_fixed">').css({
			position: 'fixed',
			width: elem.width()/13+'em',
			height: elem.height()/13+'em'
		});
	}
	elem.wrapInner(wrap);
	emulateScroll(element);
}

// animate menu functions

function animateMenu(MenuItems, hColor, nColor) {
	$(MenuItems).hover(function(){
		$(this).colorBlend([{action: "stop", param: "all"}]);
		$(this).colorBlend([{param:"color",colorList:["current",hColor], cycles:1, strobe:false, duration:250 }]);
	}, function (){
		$(this).colorBlend([{action: "stop", param: "all"}]);
		$(this).colorBlend([{param:"color",colorList:["current",nColor], cycles:1, strobe:false, duration:250 }]);
	});
}
