runCheckId = false;
var checkId = function() {
	var ids = $('#imageArea').children();
	var cont = $('.textCont').children();
	var id = '';
	for(var i = 0, j = ids.length; i < j; i++) {
		$('.'+ids[i].id+'_image').css('display', 'none');
		if($('#'+ids[i].id).css('display') == 'block') {
			id = ids[i].id;
		}
	}
	$('.'+id+'_image').css('display', 'block');
	if(runCheckId) { window.setTimeout(checkId, 100) }
};
$(document).ready(function() {
	$('a[href^="http://"],a[href$=".pdf"]').attr("target", "_blank");

	var images = $('#imageArea').children();
	if(images.length > 1) {
		$('#imageArea').cycle({
			fx: 'scrollRight',
			speed: '3000',
			timeout: '6000',
			easing:  'easeInOutBack',
			prev: '.bLeft',
			pager: '.buttons'
		});
		runCheckId = true;
		window.setTimeout(checkId,100);
	}
	/*
	var Cycle = {
		grow: 0,
		init: function() {
			if($('#cycle')) {
				
				var childObj = $('#cycle').children();
				for(var i = 0; i < childObj.length; i++) {
					if(childObj[i].id == "cycle_main") {
						this.canvasDrawCycles(childObj[i].id, '#f28b00');
					} else {
						this.canvasDrawCycles(childObj[i].id, '#ffffff');
					}
				}
			}
		},
		canvasDrawCycles: function(id, color) {
			if((id != '') && (color != '')) {
				var obj = $('#'+id);
				var objCanvas = document.getElementById(id);
				if(objCanvas.getContext) {
					console.log(objCanvas.getContext('2d'));
					var objContext = objCanvas.getContext('2d');
					var x = obj.width()/2;
					var y = obj.height()/2;
					var radius = (x+y)/2;
					if((x != '') && (y != '')) {
						objContext.beginPath();
						objContext.arc(x,y,radius,0, Math.PI*2, true);
						objContext.closePath();
						objContext.fillStyle = color;
						objContext.fill();
					}
					
				}
			}
		},
		changeColor: function(id, color) {
			var objCanvas = document.getElementById(id);
			if(objCanvas.getContext) {
				var objContext = objCanvas.getContext('2d');
				objContext.fillStyle = color;
				objContext.fill();
			}
		}
	}
	Cycle.init();
	if($('.circle')) {
		$('.circle').mouseover(function(e) {
			if(this.id != "cycle_main") {
				Cycle.changeColor(this.id, '#f28b00');
			}
		}).mouseout(function(e) {
			if(this.id != "cycle_main") {
				Cycle.changeColor(this.id, '#ffffff');
			}
		});
	}
	*/
	/* preload the images into the cache */
	var corpCache = new Image();
	corpCache.src = '/images/circle/cycle_corpdesign.jpg';
	var printCache = new Image();
	printCache.src = '/images/circle/cycle_print.jpg';
	var webCache = new Image();
	webCache.src = '/images/circle/cycle_web.jpg';
	var appsCache = new Image();
	appsCache.src = '/images/circle/cycle_apps.jpg';
	var socialmediaCache = new Image();
	socialmediaCache.src = '/images/circle/cycle_socialmedia.jpg';
	var radioimgtv = new Image();
	radioimgtv.src = '/images/circle/cycle_radioimtv.jpg';
	var powerpointCache = new Image();
	powerpointCache.src = '/images/circle/cycle_powerpoint.jpg';
	var verpackungCache = new Image();
	verpackungCache.src = '/images/circle/cycle_verpackung.jpg';
	var messeCache = new Image();
	messeCache.src = '/images/circle/cycle_messe.jpg';
	/* End the preloader */
	var imageCircle = $('#circleImg');
	var stdCircleImg = '/images/circle/cycleBg.jpg';
	$('#corporate').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_corpdesign.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//PRINT
	$('#print').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_print.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//WEB
	$('#web').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_web.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//APPS
	$('#apps').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_apps.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//SOCIALMEDIA
	$('#socialmedia').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_socialmedia.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//RADIO IMAGEFILM TV
	$('#radioimgtv').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_radioimtv.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//POWERPOINT
	$('#powerpoint').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_powerpoint.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//VERPACKUNG
	$('#verpackung').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_verpackung.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
	//MESSE
	$('#messe').mouseover(function(e) {
		imageCircle.attr('src','/images/circle/cycle_messe.jpg');
	}).mouseout(function(e) {
		imageCircle.attr('src',stdCircleImg);
	});
});

