var resizedelay = 200;
var browser = browserdetect();
var box = [];
var response;
var boxes;
var time = new Date();
var hours = time.getHours();
//hours = 24;
var max_lightening_adjust = 0.15;
var adjustment_by_current_time = Math.floor(Math.sin(hours*Math.PI/24)*100)/100;
var color_adjustment = adjustment_by_current_time*max_lightening_adjust;

function adjust_color(color){
	return rgb2hex(adjust_brightness(color,color_adjustment));
}




var base_colors = new Array();

base_colors[1] = '#493F0B';
base_colors[2] = '#23003F';
base_colors[3] = '#350221';
base_colors[4] = '#113143';
base_colors[5] = '#122800';
base_colors[6] = '#301933';

box[1] = new Array();
box[2] = new Array();
box[3] = new Array();
box[4] = new Array();
box[5] = new Array();
box[6] = new Array();

box[1]['width'] = 5/9;
box[2]['width'] = 6/18;
box[3]['width'] = 4/18;
box[4]['width'] = 4/9;
box[5]['width'] = 4/9;
box[6]['width'] = 4/9;

box[1]['height'] = 6/10;
box[2]['height'] = 4/10;
box[3]['height'] = 4/10;
box[4]['height'] = 4/10;
box[5]['height'] = 3/10;
box[6]['height'] = 3/10;

box[1]['color'] = adjust_color(base_colors[1]);
box[2]['color'] = adjust_color(base_colors[2]);
box[3]['color'] = adjust_color(base_colors[3]);
box[4]['color'] = adjust_color(base_colors[4]);
box[5]['color'] = adjust_color(base_colors[5]);
box[6]['color'] = adjust_color(base_colors[6]);
//box[1]['color'] = new Array();

function browserdetect() {
	$.each(jQuery.browser, function(i, val) {
	      $('html').addClass(i);
	    });
}


	$(document).ready(function(){
		var standardconfig = standard_layout();
		var startpage = init_startpage();
		
//		function alertsomething() {alert('done')}
		var howmanysliderelementsonscreen = howmanyslideritems();
		var direction;
		var centeratstart = verticalcenter();
		var triggerid = '';
		
		if($('body').hasClass('startpage')==true) {
		//	alert('done');
		}
	//	var pixelate = pixeleverything();
		
//BEGIN Color Change Mechanism
/*		$('#footer-menu-main li').mouseenter(function() {
			var menuid = $(this).attr('id');
			triggerid = menuid;
			var colors=new Array(); // regular array (add an optional integer
			colors['team']="#8ECB0B";       // argument to control array's size)
			colors['blog']="#6633CC";
			colors['mobile']="#CC6600";
			colors['interactive']="#993300";
			colors['top']="#000000";
			
			var currentbgcolor = $('body').css('backgroundColor'); // get's RGB Color
			var bgcolor = currentbgcolor;
			bgcolor = bgcolor.replace('rgb(',''); // Removes part of the strings to make it comparable
			bgcolor = bgcolor.replace(')',''); 	  //
			bgcolor = bgcolor.replace(/ /g,'');   //
			bgcolor = bgcolor.replace(/,/g,'');	  // End of removing Strings

			var rgbcolor = '';
			var counter = '';
			var hexcolor = '';
			
			//Converts HexColors into RGB Colors to compare Background and Color to fade into
			for (var x = 0; x<=2; x++ ) {
				var hexcolor = '';
				for (var y = 1; y<=2; y++ ) {
					var index = 2*x+y;
					hexcolor = hexcolor+colors[menuid][index];
				}
				rgbcolor += parseInt(hexcolor,16) ;
			} 
			
			
			//Shots animation if current Background is different from the color in which the animation fades into 
			if (rgbcolor!=bgcolor) {
				$('body').stop().animate( { backgroundColor: colors[menuid] }, 500);
				$('#'+menuid+' a').css( 'color', currentbgcolor);
				$('#'+menuid+' a').stop().animate( { color: colors[menuid] }, 500);
				var footerclass = $( "#footer-bg" ).attr('class');
				if (menuid == 'top' || footerclass=='start' ) {
					$( "#footer-bg" ).toggleClass( "start", 2000 );
				}

				
			} 
			//If current color is the same like the new color, don't animate
			else {
				$('#'+menuid+' a').css( 'color', colors[menuid]);
			}
		})
		$('#footer-menu-main li').mouseleave(function() {
			$('#footer-menu-main li a').stop().css('color', '#fff');
		})*/
// END Color Change Mechanism	





// Begin Color Change
    $('#footer a, #language-switch a').click(function(event) {
        event.preventDefault();
		var url = $(this).attr('href');

        var last_date = $(this).attr('title');
        $.ajax({
            url: url,
            type: 'post',
            data: {url: url, action: 'color'},

            success: function(response) {
				change_styles_to_next_page(response);
				
				
				//$('body').animate({ backgroundColor: response }, 500);
				//$('.columns').fadeOut(500);

				//alert(response);
				window.setTimeout(function(){document.location.href=url;}, 700);
            },

            error: function(error) {

                window.setTimeout(function(){document.location.href=url;}, 100);
            }
        });

    });



// End Color Change


//Slider

//Slider Initialisation
$('.jcarousel').jcarousel({
    	vertical: true,
    	scroll: 1,
		start: 2,
		itemLoadCallback: trigger,
		initCallback: mycarousel_initCallback,
		easing: 'easeInOutCubic',
		        // This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
});



//Slider Trigger
function trigger(carousel, state) {
		var currentcarousel = (carousel.list.attr('id'));
		$('#'+currentcarousel+' li').removeClass('active-item').addClass('non-active-item');//.css('opacity',0.2);
		$('#'+currentcarousel+' li:nth-child('+carousel.first+')').addClass('active-item').removeClass('non-active-item');//.css('opacity',1);
//		console.log(carousel);
//		console.log(carousel.list.attr('id'));

	}

function fadethecarousel() {
	$('.active li').css('opacity',0.2);
}
	
	
//Slider Control Hover
	$('area').hover(
		function(){
		//	alert('done');
			var newclass = $(this).attr('class');
		$('#slider-controller').addClass(newclass);
	},
		function(){
			var newclass = $(this).attr('class');
			$('#slider-controller').removeClass(newclass);
		}
	)

$('area.left, area.right').click(function(){
//	$('#logo').html('clicked');
	var direction = $(this).attr('class');
	switch(direction) {
		case "right": 	movehorizontal('right');
		return false;
		break;
		case "left"	: 	movehorizontal('left');
		break;			
	}
	return false;
})


//Navigation Controller for Left and Right slide
	$(function() {
	    $(document).keyup(function (event) {
	        if (event.keyCode == 37) {
	        movehorizontal('left');
			navigationcontrollerfeedback('left');
	      } else if (event.keyCode == 39) {
	        movehorizontal('right');
			navigationcontrollerfeedback('right');
	      }
	    });
	});

function navigationcontrollerfeedback(direction){
	$('#slider-controller').addClass(direction);
	setTimeout(function(){
	      $('#slider-controller').removeClass(direction);
	},300);	
}

function mycarousel_initCallback(carousel) {
//	console.log(carousel);
	$('area.down').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    $('area.top').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	
		$(function() {
		    $(document).keyup(function (event) {
		        if (event.keyCode == 38) {
		        	carousel.prev();
					fadethecarousel();
					navigationcontrollerfeedback('top');
			        return false;
		      } else if (event.keyCode == 40) {
		        carousel.next();
				fadethecarousel();
				navigationcontrollerfeedback('down');
		        return false;
		      }
		    });
		});
}



function movehorizontal(direction){
	//if slider is animated don't do anything to improve performance
	if($('#horizontal-scroll:animated').length<1){
		var currentposition = ($('#horizontal-scroll').css('marginLeft')).replace('px','');
		currentposition = parseFloat(currentposition);
		var itemwith = $('.horizontal-scroll-item').width()

		//if slide items exit on the right or left side move, if not, don't move
		switch (direction) {
			
			case "left": 
			var newposition = currentposition+itemwith;
			if(($('.horizontal-scroll-item.active').prev().length) !=0) {
				$('.horizontal-scroll-item.active').removeClass('active').prev().addClass('active');
				scrollhorizontal(newposition);
			}
			break;
			
			
			case "right": var newposition = currentposition-itemwith;
			if(($('.horizontal-scroll-item.active').next().length) !=0) {
				$('.horizontal-scroll-item.active').removeClass('active').next().addClass('active');
				scrollhorizontal(newposition);
			}
			break;
			
		}		
	}
	

	

	return false;
	
}

function scrollhorizontal(newposition){
	$('#horizontal-scroll').animate({
		marginLeft: newposition},{duration: 600,
	    specialEasing: {
	      marginLeft: 'easeInOutCubic'
		}
	})
}

$('.image').hover(function(){
	$(this).parent().find('div.clone').css('zIndex',3);
},	function(){
		$(this).parent().find('div.clone').css('zIndex',1);
	}

)



$('.item').click(function(event) {
    event.preventDefault();
	
	var color = $(this).css('backgroundColor');
	var newcolor = increase_brightness(color);


});



//End of $(document).ready()	
});

//Check how many slide items exist and adjust scroll area
function howmanyslideritems(){
		var sliderelements = $('.horizontal-scroll-item').length;
		var widthofhorizontalscroll = sliderelements*604;
			$('#horizontal-scroll').width(widthofhorizontalscroll);
}

function verticalcenter(){
	var sliderheight = 386;
	var adjustment = -10;
	var windowheight = $(window).height();
	var newposition = (windowheight/2)-(386/2)+adjustment;
	if(windowheight>590){
		$('.column.slider, #canvas').css('top',newposition);		
	} else {
		$('.column.slider, #canvas').css('top',94);	
	}
}



var refreshdelay;
window.onresize = function() {
	clearTimeout(refreshdelay);
	refreshdelay = window.setTimeout(function(){
		verticalcenter();
		on_resize_startpage();
		if(typeof window.update_menu == 'function') {
		// function exists, so we can now call it
			update_menu();
		}
	},resizedelay);
	
}

function pixeleverything(){
	
	$('.image').each(function(){
		var image = $(this).html();
		$(this).append('<div class="clone"></div>');
		$(this).find('div').show().html(image);
		$(this+':parent .clone img').pixastic("mosaic", {blockSize:15});
	})
}

function standard_layout() {
	$('.columns').fadeIn(500);
	//$()
//	alert('yes');
}

function change_styles_to_next_page(color) {
	if(color=='') color = '#535223';
	
	$('.columns').fadeOut(500, function(){
		if(($('#footer').css('background'))!='transparent'){
			$('#footer-bg').css({
				backgroundColor:'#000000',
				opacity:0.3
			})//,100).fadeTo(100, 0.3);
			
			$('#footer').animate({ 
				backgroundColor: color, 
				borderTopColor: color
				}, 500);
			
		}
		$('body').animate({ backgroundColor: color }, 500);
	});
}

function init_startpage(){
	sizedetect();
//	get_the_tags();
//	buildboxes();
}

function on_resize_startpage() {
	sizedetect();
	calculate_boxes();
}

function sizedetect() {
	$('.column.news').height(($(window).height())-150+'px');
}



function get_the_tags(){
	if($('.column.news').length > 0) {
			$.ajax({
	   /*         url: url,*/
	            type: 'post',
	            data: {action: 'tag'},

	            success: function(response) {
				
				draw_canvas();
				
		/*		
					boxes = response;
					buildboxes(response);
					calculate_boxes();
					colorize_boxes();
					item_hover();
					item_click();*/
	            },

	            error: function(error) {
					draw_canvas();
					console.log('fail');
	            }
	        });
	}
}

function draw_canvas(){

		var windowwidth = $('.column.news').width();
		var blockwrapheight = $('.column.news').height();
		var blockwrapwidth = windowwidth-1;	


	//	rgbToHsl(r, g, b)

		$('#block-wrap').width(blockwrapwidth).height(blockwrapheight);

	$('#blocks').html('<canvas id="canvas" width="989" height="382"></canvas>');
	var canvas = document.getElementById("canvas");
	var ctx = canvas.getContext("2d");
	we_are_plus_alpha(ctx);
	verticalcenter();
}

function we_are_plus_alpha(ctx) {
			ctx.strokeStyle ="#ffffff";
		  	ctx.save();
			      ctx.beginPath();
			      ctx.moveTo(538.3, 346.2);
			      ctx.lineWidth = 27.0;
			      ctx.lineJoin = "miter";
			      ctx.miterLimit = 4.0;
			      ctx.stroke();

			      // ebene1/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(908.6, 346.2);
			      ctx.bezierCurveTo(908.6, 354.5, 904.0, 361.2, 898.4, 361.2);
			      ctx.lineTo(841.8, 361.2);
			      ctx.bezierCurveTo(836.2, 361.2, 831.6, 354.5, 831.6, 346.2);
			      ctx.lineTo(831.6, 108.5);
			      ctx.bezierCurveTo(831.6, 100.2, 836.2, 93.5, 841.8, 93.5);
			      ctx.lineTo(898.4, 93.5);
			      ctx.bezierCurveTo(904.0, 93.5, 908.6, 100.2, 908.6, 108.5);
			      ctx.lineTo(908.6, 346.2);
			      ctx.closePath();

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(548.5, 361.2);
			      ctx.lineTo(605.1, 361.2);
			      ctx.bezierCurveTo(610.7, 361.2, 615.3, 354.5, 615.3, 346.2);
			      ctx.lineTo(615.3, 108.5);
			      ctx.bezierCurveTo(615.3, 100.2, 610.7, 93.5, 605.1, 93.5);
			      ctx.lineTo(548.5, 93.5);

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(790.7, 238.2);
			      ctx.lineTo(734.2, 238.2);
			      ctx.bezierCurveTo(728.5, 238.2, 723.9, 244.9, 723.9, 253.2);
			      ctx.lineTo(723.9, 371.4);

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(657.4, 215.3);
			      ctx.lineTo(713.9, 215.3);
			      ctx.bezierCurveTo(719.6, 215.3, 724.2, 208.6, 724.2, 200.3);
			      ctx.lineTo(724.2, 82.1);

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(887.4, 360.4);
			      ctx.bezierCurveTo(895.1, 363.6, 905.1, 356.9, 907.9, 345.5);
			      ctx.lineTo(975.9, 95.5);

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(893.6, 361.2);
			      ctx.lineTo(987.9, 361.2);

			      // ebene1/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(611.9, 227.4);
			      ctx.lineTo(548.5, 227.4);
			      ctx.stroke();

			      // ebene1/Pfad
			      ctx.beginPath();
			      ctx.moveTo(0.0, 91.1);
			      ctx.lineTo(444.4, 91.1);
			      ctx.bezierCurveTo(450.0, 91.1, 454.6, 97.8, 454.6, 106.1);
			      ctx.lineTo(454.6, 372.4);
			      ctx.stroke();

			      // ebene1/Pfad
			      ctx.beginPath();
			      ctx.moveTo(0.0, 193.4);
			      ctx.lineTo(352.0, 193.4);
			      ctx.bezierCurveTo(357.6, 193.4, 362.2, 199.1, 362.2, 206.0);
			      ctx.lineTo(362.2, 372.4);
			      ctx.stroke();

			      // ebene1/Pfad
			      ctx.beginPath();
			      ctx.moveTo(0.0, 302.1);
			      ctx.lineTo(259.6, 302.1);
			      ctx.bezierCurveTo(265.2, 302.1, 269.8, 305.4, 269.8, 309.6);
			      ctx.lineTo(269.8, 372.4);
			      ctx.stroke();

			      // ebene1/Gruppe
				ctx.fillStyle ="#ffffff";
			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.save();
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(50.0, 0.3);
			      ctx.lineTo(53.8, 0.3);
			      ctx.lineTo(45.1, 28.3);
			      ctx.lineTo(41.1, 28.3);
			      ctx.lineTo(34.5, 7.1);
			      ctx.lineTo(27.8, 28.3);
			      ctx.lineTo(23.7, 28.3);
			      ctx.lineTo(15.0, 0.3);
			      ctx.lineTo(19.0, 0.3);
			      ctx.lineTo(26.0, 22.7);
			      ctx.lineTo(32.9, 0.3);
			      ctx.lineTo(36.2, 0.3);
			      ctx.lineTo(43.1, 22.6);
			      ctx.lineTo(50.0, 0.3);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(76.8, 4.0);
			      ctx.lineTo(62.4, 4.0);
			      ctx.lineTo(62.4, 12.5);
			      ctx.lineTo(75.1, 12.5);
			      ctx.lineTo(75.1, 16.2);
			      ctx.lineTo(62.4, 16.2);
			      ctx.lineTo(62.4, 24.7);
			      ctx.lineTo(76.8, 24.7);
			      ctx.lineTo(76.8, 28.3);
			      ctx.lineTo(58.5, 28.3);
			      ctx.lineTo(58.5, 0.3);
			      ctx.lineTo(76.8, 0.3);
			      ctx.lineTo(76.8, 4.0);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(116.2, 28.3);
			      ctx.lineTo(113.2, 20.5);
			      ctx.lineTo(101.5, 20.5);
			      ctx.lineTo(98.5, 28.3);
			      ctx.lineTo(94.3, 28.3);
			      ctx.lineTo(105.1, 0.3);
			      ctx.lineTo(109.3, 0.3);
			      ctx.lineTo(120.1, 28.3);
			      ctx.lineTo(116.2, 28.3);
			      ctx.closePath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(107.4, 5.2);
			      ctx.lineTo(102.9, 16.8);
			      ctx.lineTo(111.8, 16.8);
			      ctx.lineTo(107.4, 5.2);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(138.9, 17.1);
			      ctx.lineTo(146.4, 28.3);
			      ctx.lineTo(141.7, 28.3);
			      ctx.lineTo(134.9, 17.7);
			      ctx.lineTo(128.6, 17.7);
			      ctx.lineTo(128.6, 28.3);
			      ctx.lineTo(124.7, 28.3);
			      ctx.lineTo(124.7, 0.3);
			      ctx.lineTo(135.0, 0.3);
			      ctx.bezierCurveTo(138.1, 0.3, 140.6, 1.1, 142.4, 2.5);
			      ctx.bezierCurveTo(144.2, 4.0, 145.1, 6.1, 145.1, 8.8);
			      ctx.bezierCurveTo(145.1, 11.1, 144.5, 12.9, 143.3, 14.3);
			      ctx.bezierCurveTo(142.1, 15.6, 140.7, 16.6, 138.9, 17.1);
			      ctx.closePath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(134.8, 14.0);
			      ctx.bezierCurveTo(137.3, 14.0, 139.0, 13.6, 139.9, 12.6);
			      ctx.bezierCurveTo(140.7, 11.7, 141.2, 10.4, 141.2, 8.9);
			      ctx.bezierCurveTo(141.2, 5.5, 139.0, 3.8, 134.7, 3.8);
			      ctx.lineTo(128.6, 3.8);
			      ctx.lineTo(128.6, 14.0);
			      ctx.lineTo(134.8, 14.0);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(169.6, 4.0);
			      ctx.lineTo(155.2, 4.0);
			      ctx.lineTo(155.2, 12.5);
			      ctx.lineTo(167.9, 12.5);
			      ctx.lineTo(167.9, 16.2);
			      ctx.lineTo(155.2, 16.2);
			      ctx.lineTo(155.2, 24.7);
			      ctx.lineTo(169.6, 24.7);
			      ctx.lineTo(169.6, 28.3);
			      ctx.lineTo(151.3, 28.3);
			      ctx.lineTo(151.3, 0.3);
			      ctx.lineTo(169.6, 0.3);
			      ctx.lineTo(169.6, 4.0);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(202.6, 13.4);
			      ctx.bezierCurveTo(205.7, 14.7, 207.3, 17.0, 207.3, 20.1);
			      ctx.bezierCurveTo(207.3, 21.2, 207.1, 22.3, 206.7, 23.2);
			      ctx.bezierCurveTo(206.3, 24.2, 205.8, 25.1, 205.0, 25.9);
			      ctx.bezierCurveTo(204.2, 26.8, 203.1, 27.5, 201.7, 27.9);
			      ctx.bezierCurveTo(200.3, 28.4, 198.7, 28.7, 196.8, 28.7);
			      ctx.bezierCurveTo(194.4, 28.7, 192.0, 28.1, 189.6, 27.0);
			      ctx.lineTo(189.6, 23.1);
			      ctx.bezierCurveTo(191.8, 24.4, 194.1, 25.0, 196.5, 25.0);
			      ctx.bezierCurveTo(201.1, 25.0, 203.4, 23.4, 203.4, 20.1);
			      ctx.bezierCurveTo(203.4, 16.9, 201.0, 15.3, 196.0, 15.3);
			      ctx.lineTo(193.6, 15.3);
			      ctx.lineTo(193.6, 11.8);
			      ctx.lineTo(195.9, 11.8);
			      ctx.bezierCurveTo(200.0, 11.8, 202.0, 10.5, 202.0, 7.8);
			      ctx.bezierCurveTo(202.0, 5.0, 200.0, 3.6, 196.0, 3.7);
			      ctx.bezierCurveTo(193.9, 3.7, 192.0, 4.1, 190.3, 5.1);
			      ctx.lineTo(190.3, 1.3);
			      ctx.bezierCurveTo(192.2, 0.4, 194.3, -0.0, 196.5, 0.0);
			      ctx.bezierCurveTo(199.7, 0.0, 202.1, 0.8, 203.6, 2.3);
			      ctx.bezierCurveTo(205.1, 3.8, 205.9, 5.6, 205.9, 7.8);
			      ctx.bezierCurveTo(205.9, 10.2, 204.8, 12.0, 202.6, 13.4);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(238.6, 0.3);
			      ctx.bezierCurveTo(241.7, 0.3, 244.0, 1.1, 245.8, 2.6);
			      ctx.bezierCurveTo(247.5, 4.1, 248.3, 6.3, 248.3, 9.1);
			      ctx.bezierCurveTo(248.3, 11.9, 247.5, 14.1, 245.7, 15.7);
			      ctx.bezierCurveTo(244.0, 17.2, 241.6, 18.0, 238.5, 18.0);
			      ctx.lineTo(232.4, 18.0);
			      ctx.lineTo(232.4, 28.3);
			      ctx.lineTo(228.5, 28.3);
			      ctx.lineTo(228.5, 0.3);
			      ctx.lineTo(238.6, 0.3);
			      ctx.closePath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(238.2, 14.5);
			      ctx.bezierCurveTo(240.7, 14.5, 242.3, 14.0, 243.2, 13.1);
			      ctx.bezierCurveTo(244.0, 12.1, 244.5, 10.8, 244.5, 9.1);
			      ctx.bezierCurveTo(244.5, 7.5, 244.0, 6.2, 243.2, 5.2);
			      ctx.bezierCurveTo(242.4, 4.3, 240.7, 3.8, 238.2, 3.8);
			      ctx.lineTo(232.4, 3.8);
			      ctx.lineTo(232.4, 14.5);
			      ctx.lineTo(238.2, 14.5);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(257.3, 24.7);
			      ctx.lineTo(271.3, 24.7);
			      ctx.lineTo(271.3, 28.3);
			      ctx.lineTo(253.4, 28.3);
			      ctx.lineTo(253.4, 0.3);
			      ctx.lineTo(257.3, 0.3);
			      ctx.lineTo(257.3, 24.7);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(294.8, 0.3);
			      ctx.lineTo(298.6, 0.3);
			      ctx.lineTo(298.6, 16.8);
			      ctx.bezierCurveTo(298.6, 20.6, 297.6, 23.5, 295.6, 25.6);
			      ctx.bezierCurveTo(293.7, 27.7, 290.8, 28.7, 287.2, 28.7);
			      ctx.bezierCurveTo(283.5, 28.7, 280.7, 27.7, 278.7, 25.6);
			      ctx.bezierCurveTo(276.8, 23.5, 275.8, 20.6, 275.8, 16.8);
			      ctx.lineTo(275.8, 0.3);
			      ctx.lineTo(279.6, 0.3);
			      ctx.lineTo(279.6, 17.2);
			      ctx.bezierCurveTo(279.6, 19.9, 280.2, 22.0, 281.5, 23.3);
			      ctx.bezierCurveTo(282.7, 24.6, 284.6, 25.3, 287.2, 25.3);
			      ctx.bezierCurveTo(289.8, 25.3, 291.7, 24.6, 292.9, 23.3);
			      ctx.bezierCurveTo(294.1, 22.0, 294.8, 19.9, 294.8, 17.2);
			      ctx.lineTo(294.8, 0.3);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(308.4, 8.0);
			      ctx.bezierCurveTo(308.4, 8.7, 308.8, 9.4, 309.5, 9.9);
			      ctx.bezierCurveTo(310.3, 10.5, 311.2, 11.0, 312.3, 11.3);
			      ctx.bezierCurveTo(313.4, 11.7, 314.6, 12.2, 315.9, 12.6);
			      ctx.bezierCurveTo(317.2, 13.1, 318.4, 13.7, 319.5, 14.3);
			      ctx.bezierCurveTo(320.6, 14.9, 321.5, 15.8, 322.2, 17.0);
			      ctx.bezierCurveTo(322.9, 18.1, 323.3, 19.5, 323.3, 21.1);
			      ctx.bezierCurveTo(323.3, 23.5, 322.4, 25.3, 320.6, 26.7);
			      ctx.bezierCurveTo(318.8, 28.0, 316.4, 28.7, 313.2, 28.7);
			      ctx.bezierCurveTo(310.4, 28.7, 307.6, 28.0, 304.9, 26.7);
			      ctx.lineTo(304.9, 22.7);
			      ctx.bezierCurveTo(307.5, 24.2, 310.1, 25.0, 312.9, 25.0);
			      ctx.bezierCurveTo(317.2, 25.0, 319.4, 23.7, 319.4, 21.0);
			      ctx.bezierCurveTo(319.4, 19.9, 319.1, 19.0, 318.3, 18.2);
			      ctx.bezierCurveTo(317.6, 17.4, 316.7, 16.8, 315.6, 16.4);
			      ctx.lineTo(312.0, 15.2);
			      ctx.bezierCurveTo(310.7, 14.8, 309.5, 14.3, 308.4, 13.8);
			      ctx.bezierCurveTo(307.3, 13.4, 306.4, 12.6, 305.6, 11.6);
			      ctx.bezierCurveTo(304.9, 10.7, 304.5, 9.5, 304.5, 8.1);
			      ctx.bezierCurveTo(304.5, 5.8, 305.3, 3.9, 306.9, 2.4);
			      ctx.bezierCurveTo(308.5, 0.8, 311.0, 0.0, 314.3, 0.0);
			      ctx.bezierCurveTo(316.8, 0.0, 319.2, 0.6, 321.5, 1.8);
			      ctx.lineTo(321.5, 5.7);
			      ctx.bezierCurveTo(319.5, 4.5, 317.2, 3.9, 314.8, 3.9);
			      ctx.bezierCurveTo(310.5, 3.9, 308.4, 5.2, 308.4, 8.0);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(362.7, 28.3);
			      ctx.lineTo(359.7, 20.5);
			      ctx.lineTo(347.9, 20.5);
			      ctx.lineTo(344.9, 28.3);
			      ctx.lineTo(340.7, 28.3);
			      ctx.lineTo(351.6, 0.3);
			      ctx.lineTo(355.7, 0.3);
			      ctx.lineTo(366.5, 28.3);
			      ctx.lineTo(362.7, 28.3);
			      ctx.closePath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(353.8, 5.2);
			      ctx.lineTo(349.3, 16.8);
			      ctx.lineTo(358.3, 16.8);
			      ctx.lineTo(353.8, 5.2);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(375.4, 24.7);
			      ctx.lineTo(389.3, 24.7);
			      ctx.lineTo(389.3, 28.3);
			      ctx.lineTo(371.5, 28.3);
			      ctx.lineTo(371.5, 0.3);
			      ctx.lineTo(375.4, 0.3);
			      ctx.lineTo(375.4, 24.7);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(403.9, 0.3);
			      ctx.bezierCurveTo(406.9, 0.3, 409.3, 1.1, 411.0, 2.6);
			      ctx.bezierCurveTo(412.8, 4.1, 413.6, 6.3, 413.6, 9.1);
			      ctx.bezierCurveTo(413.6, 11.9, 412.7, 14.1, 411.0, 15.7);
			      ctx.bezierCurveTo(409.3, 17.2, 406.9, 18.0, 403.8, 18.0);
			      ctx.lineTo(397.6, 18.0);
			      ctx.lineTo(397.6, 28.3);
			      ctx.lineTo(393.8, 28.3);
			      ctx.lineTo(393.8, 0.3);
			      ctx.lineTo(403.9, 0.3);
			      ctx.closePath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(403.5, 14.5);
			      ctx.bezierCurveTo(406.0, 14.5, 407.6, 14.0, 408.5, 13.1);
			      ctx.bezierCurveTo(409.3, 12.1, 409.7, 10.8, 409.7, 9.1);
			      ctx.bezierCurveTo(409.7, 7.5, 409.3, 6.2, 408.5, 5.2);
			      ctx.bezierCurveTo(407.7, 4.3, 406.0, 3.8, 403.5, 3.8);
			      ctx.lineTo(397.6, 3.8);
			      ctx.lineTo(397.6, 14.5);
			      ctx.lineTo(403.5, 14.5);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(436.2, 0.3);
			      ctx.lineTo(440.0, 0.3);
			      ctx.lineTo(440.0, 28.3);
			      ctx.lineTo(436.2, 28.3);
			      ctx.lineTo(436.2, 16.2);
			      ctx.lineTo(422.7, 16.2);
			      ctx.lineTo(422.7, 28.3);
			      ctx.lineTo(418.9, 28.3);
			      ctx.lineTo(418.9, 0.3);
			      ctx.lineTo(422.7, 0.3);
			      ctx.lineTo(422.7, 12.5);
			      ctx.lineTo(436.2, 12.5);
			      ctx.lineTo(436.2, 0.3);
			      ctx.closePath();
			      ctx.fill();

			      // ebene1/Gruppe/Zusammengesetzter Pfad
			      ctx.beginPath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(466.7, 28.3);
			      ctx.lineTo(463.7, 20.5);
			      ctx.lineTo(452.0, 20.5);
			      ctx.lineTo(449.0, 28.3);
			      ctx.lineTo(444.8, 28.3);
			      ctx.lineTo(455.6, 0.3);
			      ctx.lineTo(459.8, 0.3);
			      ctx.lineTo(470.6, 28.3);
			      ctx.lineTo(466.7, 28.3);
			      ctx.closePath();

			      // ebene1/Gruppe/Zusammengesetzter Pfad/Pfad
			      ctx.moveTo(457.9, 5.2);
			      ctx.lineTo(453.4, 16.8);
			      ctx.lineTo(462.3, 16.8);
			      ctx.lineTo(457.9, 5.2);
			      ctx.closePath();
			      ctx.fill();
			      ctx.restore();
			      ctx.restore();
}




function calculate_boxes(){
	var windowwidth = $('.column.news').width();
	var blockwrapheight = $('.column.news').height();
	var blockwrapwidth = windowwidth-1;	

	
//	rgbToHsl(r, g, b)
	
	$('#block-wrap').width(blockwrapwidth).height(blockwrapheight);
	
	
	$('.part-1').width(blockwrapwidth*box[1]['width']);
	$('.part-2').width(blockwrapwidth*box[4]['width']);
	
//	console.log(blockwrapwidth+', '+blockwrapheight)
	
	var whichblock = 1;
	var borderright = 1;
	var borderbottom = 1;

	$('.block').each(function(){
		
		var boxheight = box[whichblock]['height']*(blockwrapheight);
		var boxwidth = box[whichblock]['width']*(blockwrapwidth);
		$(this).width(boxwidth).height(boxheight);

		var box_1_height = boxheight-borderbottom;
		var box_2_height = boxheight/5*2-borderbottom;
		var box_3_height = boxheight/5*3-borderbottom;
		var box_4_height = boxheight/5*2-borderbottom;
		var box_5_height = boxheight/5*1-borderbottom;

		var box_1_width = boxwidth/5*2-borderright;
		var box_2_width = boxwidth/5*3-borderright;
		var box_3_width = boxwidth/5*2-borderright;
		var box_4_width = boxwidth/5-borderright;
		var box_5_width = boxwidth/5-borderright;

		$('.item.n1',this).width(box_1_width).height(box_1_height);
		$('.item.n2',this).width(box_2_width).height(box_2_height);
		$('.item.n3',this).width(box_3_width).height(box_3_height);
		$('.item.n4',this).width(box_4_width).height(box_4_height);
		$('.item.n5',this).width(box_5_width).height(box_5_height);

	

		$('.item.n1 span',this).css('top',box_1_height/2-($('.item.n1 span',this).css('height')).replace('px','')/2);
		$('.item.n2 span',this).css('top',box_2_height/2-($('.item.n2 span',this).css('height')).replace('px','')/2);
		$('.item.n3 span',this).css('top',box_3_height/2-($('.item.n3 span',this).css('height')).replace('px','')/2);
		$('.item.n4 span',this).css('top',box_4_height/2-($('.item.n4 span',this).css('height')).replace('px','')/2);
		$('.item.n5 span',this).css('top',box_5_height/2-($('.item.n5 span',this).css('height')).replace('px','')/2);


		whichblock++;

	})
		
}

function colorize_boxes(){
	var whichblock = 1;
	$('.block').each(function(){
		var adjustment = 0;
		var difference = -0.015*(1+adjustment_by_current_time);
		box[whichblock]['colors'] = new Array();
		
		for (i=0;i<=4;i++){
			box[whichblock]['colors'][i] = 'rgb('+adjust_brightness(box[whichblock]['color'],adjustment)+')';
			console.log(box[whichblock]['colors'][i]);
			adjustment+=difference;
			$('.item.n'+(i+1)+'',this).css('backgroundColor',box[whichblock]['colors'][i]);
		}
		
		
		/*
		$('.item.n1',this).css('backgroundColor',box[whichblock]['color']);
		$('.item.n2',this).css('backgroundColor','rgb('+adjust_brightness(box[whichblock]['color'],-0.015)+')');
		$('.item.n3',this).css('backgroundColor','rgb('+adjust_brightness(box[whichblock]['color'],-0.03)+')');
		$('.item.n4',this).css('backgroundColor','rgb('+adjust_brightness(box[whichblock]['color'],-0.045)+')');
		$('.item.n5',this).css('backgroundColor','rgb('+adjust_brightness(box[whichblock]['color'],-0.06)+')');
*/

		whichblock++;

	})
	
}



function adjust_brightness(color,brightness){
	
	var R_GB = hexToR(color);
	var R_G_B = hexToG(color);
	var RG_B = hexToB(color);
	
	var hsl = rgbToHsl(R_GB,R_G_B,RG_B);

	var rgb = (hslToRgb(hsl[0],hsl[1],(hsl[2])+brightness));
	var rounded_rgb = [Math.round(rgb[0]),Math.round(rgb[1]),Math.round(rgb[2])];

	return rounded_rgb;
	
}

function intToHex(i) {  
    var hex = parseInt(i).toString(16);  
    return (hex.length < 2) ? "0" + hex : hex;  
}

function increase_brightness(color) {
	color = color.replace('rgb(','');
	color = color.replace(')','');
	console.log(color);
	
	var temp = new Array();
	temp = color.split(',');
	
	R_GB = parseInt(temp[0]);
	R_G_B = parseInt(temp[1]);
	RG_B = parseInt(temp[2]);
	
	
	
	var increasefactor = 0.09;
	var hsl = rgbToHsl(R_GB,R_G_B,RG_B);

	var rgb = (hslToRgb(hsl[0],hsl[1],(hsl[2])+increasefactor));
	
	var rounded_rgb = [Math.round(rgb[0]),Math.round(rgb[1]),Math.round(rgb[2])];
	var hexcolor = rgb2hex(rounded_rgb);
//	console.log(rgb2hex(rounded_rgb));
	
	return (hexcolor);
}

function item_hover (){
	var tempcolor;
	var tempfontsize;
	var topmove = 0;
	$('.item').hover(

	//	var color = $(this).css('backgroundColor');
	//	var newcolor = increase_brightness(color);


	  function () {
			console.log(this);
			
			var parentclasses = $(this).parent().attr('class');
			var block_index = parentclasses.replace('block b','');
			var item_index = $(this).attr('class');
			item_index = item_index.replace('item n','');
			
			
			
			
//			console.log(block_index+', '+item_index);
			
		//	tempcolor = $(this).css('backgroundColor');

			tempcolor = (box[block_index]['colors'][item_index-1]);
			tempfontsize = (box[block_index]['fontsizes'][item_index-1]);
			
//			tempfontsize = $('span', this).css('font-size');
			newfontsize = parseFloat(tempfontsize)*1.5;

			var lines = (Math.round($('span',this).height() / parseFloat($('span',this).css('line-height'))));
			topmove = 0;
			if(lines>1) {
				topmove = (newfontsize-tempfontsize)*(lines-1);
			}
			var newcolor = increase_brightness(tempcolor);
			//console.log(newcolor);

			$(this).stop(true,true).animate(
				{ backgroundColor: newcolor
					}, 
				500);
			$('span',this)	.stop(true,true).animate(
					{ fontSize: newfontsize+'px',
						top: '-='+topmove+'px'
						}, 
					150);

	  }, 
	  function () {
			$(this).stop(true,true).animate(
				{ 
					backgroundColor: tempcolor
					}, 
				500);
				$('span',this).stop(true,true).animate(
					{ fontSize: tempfontsize,
						top: '+='+topmove+'px'
						}, 
				200);
	console.log(topmove);  
	}
	);
}

function random_highlighting(){
	var AmountOfItems = $('.item').length;
	console.log(AmountOfItems);
	
	
	var random_highlighting_loop = window.setInterval("highlight_it("+AmountOfItems+")", 500);
	
	/*
	
	function () {
			console.log(this);
			tempcolor = $(this).css('backgroundColor');
			tempfontsize = $('span', this).css('font-size');
			newfontsize = parseFloat(tempfontsize)*1.5;

			var newcolor = increase_brightness(tempcolor);


			$(this).stop().animate(
				{ backgroundColor: newcolor
					}, 
				500);
			$('span',this)	.stop().animate(
					{ fontSize: newfontsize+'px'
						}, 
					150);

	  }
	
	*/
	

	
}

function highlight_it(AmountOfItems){
			index = Math.round(Math.random()*AmountOfItems);

			tempcolor = $('.item:eq('+index+')').css('backgroundColor');
			tempfontsize = $('.item:eq('+index+') span').css('font-size');
			newfontsize = parseFloat(tempfontsize)*1.5;
			console.log(tempcolor);
			var newcolor = increase_brightness(tempcolor);


			$('div.item:eq('+index+')').stop().animate(
				{ backgroundColor: newcolor
					}, 
				500	, 
					  function () {
							$('div.item:eq('+index+')').animate(
								{ 
									backgroundColor: tempcolor
									}, 
								2000);
								$('div.item:eq('+index+') span').stop().animate(
									{ fontSize: tempfontsize
										}, 
								2000);
					  });
			$('div.item:eq('+index+') span').stop().animate(
					{ fontSize: newfontsize+'px'
						}, 
					150);

	 
}

function item_click(){
	$('.item a').click(function(event) {
        event.preventDefault();
		var url = $(this).attr('href');

        var last_date = $(this).attr('title');
        $.ajax({
            url: url,
            type: 'post',
            data: {url: url, action: 'color'},

            success: function(response) {
				change_styles_to_next_page(response);
				
				
				//$('body').animate({ backgroundColor: response }, 500);
				//$('.columns').fadeOut(500);

				//alert(response);
				window.setTimeout(function(){document.location.href=url;}, 700);
            },

            error: function(error) {
	
                window.setTimeout(function(){document.location.href=url;}, 100);
            }
        });

    });
}
