var bytepark = bytepark || {};
var browserPlatform = navigator.platform.toLowerCase();
bytepark.isMobile = false;
bytepark.isMobile = -~browserPlatform.indexOf('iphone') || -~browserPlatform.indexOf('ipad') || -~browserPlatform.indexOf('ipod') || -~browserPlatform.indexOf('android');

// Inputfield auf der Startseite bei Fokus leeren und bei Blur füllen
bytepark.toggleInputValue = function() {
	var value;
	var inputField;
	
	function clearValue(input) {
		value = 'E-Mail';
		input.attr('value', '');
	}
	
	function setValue(input) {
		if(input.val() == '') { 
			input.attr('value', value); 
		}
	}
	
	return {
		init:function() {
			jQuery('form input[name=newsletter]').click(function() { clearValue($(this)); });
			jQuery('form input[name=newsletter]').blur(function() { setValue($(this)); });
		}
	};
}();

// Hover-Effekt für die Referenzboxen auf der Startseite und der Seite "Referenzen"
bytepark.toggleReference = function() {
	var reference;
	var referenceHeadlineCount;
	var maxHeadlineHeight = 15;
	var refBgHeight;
	var containerHeight;

	function alignHeadlines() {
		referenceHeadlineCount = $('.reference').children('h4').length;
		//alert(containerHeight);
		for (i = 0; i < referenceHeadlineCount; i++) {
			if($('.reference h4:nth(' + i + ')').height() > maxHeadlineHeight) {
				containerHeight === 140 ? $('.reference h4:nth(' + i + ')').css({'top' : '145px'}) : $('.reference h4:nth(' + i + ')').css({'top' : '158px'});
			}
		}
	}
	
	function referenceOver(referenceBox) {
		reference = referenceBox;
		reference.find('.refBg').stop().animate({'top' : containerHeight}, 100);
		reference.find('.refPattern').fadeOut(100);
	}
	
	function referenceOut() {
		reference.find('.refBg').stop().animate({'top' : containerHeight - refBgHeight}, 100);
		reference.find('.refPattern').fadeIn(100);
	}
	
	function resize() {
		window.setTimeout(function() {
			refBgHeight = parseInt($('.reference').find('.refBg').outerHeight(), 10);
			containerHeight = parseInt($('.refThumbnail').outerHeight(), 10);
			bytepark.isMobile || $('.refBg').css({'top' : containerHeight - refBgHeight});
			alignHeadlines();
		}, 100);
	}
	
	return {
		init:function() {
			if (jQuery.browser.msie && jQuery.browser.version <= 6 || bytepark.isMobile) {
				$('.refThumbnail').parent().remove('.refPattern');
			} else {
				$('.refThumbnail').parent().append('<span class="refPattern"></span>');
			}
			$('.refBg').show();
			bytepark.isMobile || $('.reference').removeClass('referenceNonJs');
			bytepark.isMobile || $('.reference').hover(function() { referenceOver($(this)); }, function() { referenceOut(); });
			window.setTimeout(function() {
				refBgHeight = parseInt($('.reference').find('.refBg').outerHeight(), 10);
				containerHeight = parseInt($('.refThumbnail').outerHeight(), 10);
				bytepark.isMobile || $('.refBg').css({'top' : containerHeight - refBgHeight});
				alignHeadlines();
			}, 100);
			$(window).bind('resize', resize);
		}
	};
}();

// Hover-Effekt für die Leistungen-Boxen
bytepark.toggleSolution = function() {
	var solution;
	var solutionHeadlineCount;
	var refBgHeight;
	var containerHeight;
	var maskHeight;
	
	function alignHeadlines() {
		solutionHeadlineCount = $('.solution').children('h4').length;
		for (i = 0; i < solutionHeadlineCount; i++) {
			if($('.solution h4:nth(' + i + ')').height() > 15 ) {
				//$('.solution h4:nth(' + i + ')').css({'top' : '157px'});
				maskHeight === 136 ? $('.solution h4:nth(' + i + ')').css({'top' : '141px'}) : $('.solution h4:nth(' + i + ')').css({'top' : '157px'});
			}
		}
	}
	
	function solutionOver(solutionBox) {
		solution = solutionBox;
		solution.find('.refBg').stop().animate({'top' : containerHeight}, 100);
		solution.find('a img').animate({'top' : '0px'}, 100);
		solution.find('.mask').animate({'top' : -maskHeight}, 100);
	}
	
	function solutionOut() {
		solution.find('.refBg').stop().animate({'top' : containerHeight - refBgHeight}, 100);
		solution.find('a img').stop().animate({'top' : maskHeight}, 100);
		solution.find('.mask').stop().animate({'top' : '0px'}, 100);
	}
	
	function resize() {
		window.setTimeout(function() {
			maskHeight = parseInt($('.mask').outerHeight(), 10);
			refBgHeight = parseInt($('.solution').find('.refBg').outerHeight(), 10);
			containerHeight = parseInt($('.solutionImg').outerHeight(), 10);
			bytepark.isMobile || $('.refBg').css({'top' : containerHeight - refBgHeight});
			$('.solution a img').css({'top' : maskHeight});
			alignHeadlines();
		}, 100);
		
		window.setTimeout(function() {
			alignHeadlines();
		}, 110);
	}
	
	return {
		init:function() {
			$('.refBg').show();
			//alignHeadlines();
			bytepark.isMobile || $('.solution').removeClass('solutionNonJs');
			window.setTimeout(function() {
				maskHeight = parseInt($('.mask').outerHeight(), 10);
				refBgHeight = parseInt($('.solution').find('.refBg').outerHeight(), 10);
				containerHeight = parseInt($('.solutionImg').outerHeight(), 10);
				bytepark.isMobile || $('.refBg').css({'top' : containerHeight - refBgHeight});
				alignHeadlines();
				$('.solution a > img').css({'top' : maskHeight});
				$('.solutionNonJs a > img').css({'top' : 'auto'});
			}, 100);
			$(window).bind('resize', resize);
			
			bytepark.isMobile || $('.solution').hover(function() { solutionOver($(this)); }, function() { solutionOut(); });
		}
	};
}();

//Hover-Effekt fuer die Download-Boxen
bytepark.toggleDownload = function() {
	var download;
	var refBgHeight;
	var containerHeight;
	
	function downloadOver(downloadBox) {
		download = downloadBox;
		download.find('.refBg').stop().animate({'top' : containerHeight}, 100);
		download.find('.refPattern').fadeOut(100);
	}
	
	function downloadOut() {
		download.find('.refBg').stop().animate({'top' : containerHeight - refBgHeight}, 100);
		download.find('.refPattern').fadeIn(100);
	}
	
	function resize() {
		window.setTimeout(function() {
			refBgHeight = parseInt($('.download').find('.refBg').outerHeight(), 10);
			containerHeight = parseInt($('.downloadImg').outerHeight(), 10);
			bytepark.isMobile || $('.refBg').css({'top' : containerHeight - refBgHeight});
			//alignHeadlines();
		}, 100);
	}
	
	return {
		init:function() {
			if (jQuery.browser.msie && jQuery.browser.version <= 6 || bytepark.isMobile) {
				$('.downloadImg').parent().remove('.refPattern');
			} else {
				$('.downloadImg').parent().append('<span class="refPattern"></span>');
			}
			
			window.setTimeout(function() {
				refBgHeight = parseInt($('.download').find('.refBg').outerHeight(), 10);
				containerHeight = parseInt($('.downloadImg').outerHeight(), 10);
				bytepark.isMobile || $('.refBg').css({'top' : containerHeight - refBgHeight});
				//alignHeadlines();
			}, 100);
			bytepark.isMobile || $('.refBg').show();
			bytepark.isMobile || $('.download').removeClass('downloadNonJs');
			bytepark.isMobile || $('.download').hover(function() { downloadOver($(this)); }, function() { downloadOut(); });
			$(window).bind('resize', resize);
		}
	};
}();

//Hover-Effekt für die Team-Boxen
bytepark.toggleTeam = function() {
	var team;
	
	function teamOver(teamBox) {
		team = teamBox;
		//team.find('.refBg').stop().animate({'top' : '150px'}, 100);
		team.find('.mask').animate({'opacity' : '0'}, 300);
	}
	
	function teamOut() {
		//team.find('.refBg').stop().animate({'top' : '103px'}, 100);
		team.find('.mask').stop().animate({'opacity' : '1'}, 300);
	}
	
	return {
		init:function() {
			$('.refBg').show();
			$('.team').removeClass('teamNonJs');
			$('.team').hover(function() { teamOver($(this)); }, function() { teamOut(); });
		}
	};
}();

//Hover-Effekt für die News-Boxen
bytepark.toggleNews = function() {
	var solution;
	var refBgHeight;
	var newsContainerHeight;
	function newsOver(newsBox) {
		news = newsBox;
		bytepark.isMobile || news.find('.refBg').stop().animate({'top' : newsContainerHeight}, 100);
	}
	
	function newsOut() {
		bytepark.isMobile || news.find('.refBg').stop().animate({'top' : newsContainerHeight - refBgHeight}, 100);
	}
	
	function resize() {
		window.setTimeout(function() {
			refBgHeight = parseInt($('.news').find('.refBg').outerHeight(), 10);
			newsContainerHeight = parseInt($('.newsContainer').outerHeight(), 10);
			bytepark.isMobile || $('.refBg').css({'top' : newsContainerHeight - refBgHeight});
		}, 100);
	}
	
	return {
		init:function() {
			$('.refBg').show();
			bytepark.isMobile || $('.news').removeClass('newsNonJs');
			bytepark.isMobile || $('.newsCollection li').hover(function() { newsOver($(this)); }, function() { newsOut(); });
			window.setTimeout(function() {
				refBgHeight = parseInt($('.news').find('.refBg').outerHeight(), 10);
				newsContainerHeight = parseInt($('.newsContainer').outerHeight(), 10);
			}, 100);
			$(window).bind('resize', resize);
		}
	};
}();

// Hover-Effekt neutrale Sublinks in der Sidebar (ToDo mit Leistungen-Klasse zusammenschließen!)
bytepark.toggleNeutralSidebar = function() {
	var neutralLink;
	
	function neutralSmallboxOver(sidebarLink) {
		neutralLink = sidebarLink;
		if(neutralLink.attr('id') != 'neutralActive') {
			neutralLink.find('span span').stop().animate({'height' : '0px'}, 50);
		}
	}
	
	function neutralSmallboxOut() {
		if(neutralLink.attr('id') != 'neutralActive') {
			neutralLink.find('span span').stop().animate({'height' : '18px'}, 50);
		}
	}
	
	return {
		init:function() {
			$('.neutralLink').hover(function() { neutralSmallboxOver($(this)); }, function() { neutralSmallboxOut(); });
		}
	};
}();

//Hover-Effekt Leistungen-Links in der Sidebar
bytepark.toggleSolutionSidebar = function() {
	var solutionLink;
	
	function solutionSmallboxOver(sidebarLink) {
		solutionLink = sidebarLink;
		if(solutionLink.attr('id') != 'solutionActive') {
			solutionLink.find('span span').stop().animate({'height' : '0px'}, 50);
		}
	}
	
	function solutionSmallboxOut() {
		if(solutionLink.attr('id') != 'solutionActive') {
			solutionLink.find('span span').stop().animate({'height' : '18px'}, 50);
		}
	}
	
	return {
		init:function() {
			$('.solutionLink').hover(function() { solutionSmallboxOver($(this)); }, function() { solutionSmallboxOut(); });
		}
	};
}();

// Hover-Effekt für Socialbuttons
bytepark.toggleSocialbutton = function() {
	var socialButton;

	function socialbtnOver(btn) {
		socialButton = btn;
		socialButton.find('.arrow').stop().animate({'left' : '46px'}, 100);
	}
	
	function socialbtnOut() {
		socialButton.find('.arrow').stop().animate({'left' : '43px'}, 100);
	}
	
	return {
		init:function() {
			$('.socialBtn').find('.arrow').css({'left' : '43px'});
			$('.socialBtn').hover(function() { socialbtnOver($(this)); }, function() { socialbtnOut(); });
		}
	};
}();

// Selectbox für Referenzen und Newsseiten
bytepark.customSelectbox = function() {
	var optionSet;
	var optionValue;
	var optionLink;
	var selectedOption;
	var messyList;
	var childElements;
	var compA;
	var compB;
	var listItems;
	var initCount = 0;
	
	function itemOver(item) {
		if(!item.hasClass('selected')) {
			item.css({'background' : '#dfdfdf'});
		}
	}
	
	function itemOut() {
		$('.customSelect .options ul li a:not(.selected)').css({'background' : '#FFFFFF', 'color' : '#000'});
	}
	
	function sortItems(messyList, childElements) {
		listItems = messyList.children(childElements).get();
		listItems.sort(function(a, b){
			compA = $(a).text().toUpperCase();
			compB = $(b).text().toUpperCase();
			return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
		});
		//messyList.append('<li><a href="' + $('select option:nth(0)').attr('value') + '">' + $('select option:nth(0)').text() + '</a></li>');
		$.each(listItems, function(idx, itm){ 
			messyList.append(itm); 
		});
	}
	
	function setItems() {
		$('.customSelect .options').append('<ul></ul>');
		
		optionSet = $('.customSelect .options ul');
		options = $('.refSelect option').length;
		
		for(i = 0; i < options; i++) {
			optionValue = $('select option:nth(' + i + ')').text();
			optionLink = $('select option:nth(' + i + ')').attr('value');
			optionSet.append('<li><a href="' + optionLink + '">' + optionValue + '</a></li>');
		}		
		
		selectedOption = $('select option:selected').index();
		//sortItems(optionSet, 'li');
		selectItem($('.customSelect .options ul li a:nth(' + selectedOption + ')')); // TODO funktioniert nicht korrekt im IE6 + 7
		$('.customSelect .options ul li').css({'cursor' : 'default'});
	}
	
	function showList() {
		if ($('.customSelect .options').hasClass('opened')) {
			hideList();
		} else {
			$('.customSelect .options, .customSelect div ul').fadeIn(100);
			if(initCount === 0) $('.customSelect .options').jScrollPane();
			$('.customSelect .options').addClass('opened');
		}
		initCount = 1;
	}
	
	function hideList() { 
		$('.customSelect .options, .customSelect .options ul').fadeOut(100);
		$('.customSelect .options').removeClass('opened');
	}
	
	function checkIfOpened(e) {
		target = $(e.target);
		if (!target.is('.customSelect, .customSelect .selection, .customSelect .selection p, .customSelect img, .customSelect .options, .customSelect ul, .customSelect ul li, .jspTrack, .jspDrag')) {
			hideList();
		}
	}
	
	function selectItem(item) {
		$('.customSelect .options ul li a').removeClass().css({'background' : '#FFFFFF', 'color' : '#000'});
		selected = item.text();
		item.addClass('selected').css({'background-color' : '#000', 'color' : '#FFF'});
		$('.customSelect p').text(selected);
		hideList();
	}
	
	return {
		init:function() {
			$('form select').hide();
			setItems();
			$('.customSelect').show();
			$('.customSelect .selection, .customSelect img').click(function() { showList(); });
			$('.customSelect .options ul li a').mouseover(function() { itemOver($(this)); }).mouseout(function() { itemOut(); });
			$('.customSelect .options ul li a').click(function() { selectItem($(this)); });
			$(document.window || 'body').bind('click', checkIfOpened);
		}
	};
}();

// Referenz-Slider
bytepark.referenceSlider = function() {
	var countRefImages;
	var count = 0;
	var currentXPos;
	var imgSrc;
	var stepWidth;
	
	function setStage() {
		stepWidth = parseInt($('ul.refImages li:first-child').width(), 10);
		countRefImages = $('#referenceSlider ul.refImages li').length;
		
		$('.refImages li').not(':first-child').addClass('loadIt');
		
		$('#referenceSlider ul.refImages').css({'width' : countRefImages * stepWidth});
		for(var i = 0; i < countRefImages; i++) {
			$('.subNavi').append('<img src="files/site/img/pic_0.png" alt="" />');
			$('#content').before('<span class="home"></span>');
			$('span.home:nth(' + i + ')').css({'background-image' : 'url(' + bytepark.headerPattern[i] + ')'});
		}
		var subNaviWidth = (countRefImages * 10) + ((countRefImages - 1) * 10) + 48;
		var subNaviMargin =  subNaviWidth / 2;
		$('.subNavi').css({'width' : subNaviWidth, 'margin-left' : -subNaviMargin});
		$('.subNavi img').css({'margin-right' : 10});
		$('.subNavi img:last-child').css({'margin-right' : 0});
		$('.subNavi img:nth(0)').attr('src', 'files/site/img/pic_1.png');
		$('#referenceSlider').append('<a name="prevImage" class="slideBtn btnPrev"><img src="files/site/img/prev.gif" alt="" /></a><a name="nextImage" class="slideBtn btnNext"><img src="files/site/img/next.gif" alt="" /></a>');
		$('span.home:not(:nth(' + count + '))').hide();
		$('.infoBox:not(:nth(' + count + '))').hide();
		// Krücke für den IE7
		$('.infoBox:nth(0))').show();
		if ( jQuery.browser.msie && jQuery.browser.version <= 7 ) {
			$('.home').css({'top' : '191px'});
		}
		
		// Lazy Loading Images
		$('.refImages li > p').hide();
	}
	
	function loadIt(c) {
		imgSrc = $('.refImages li').eq(c).find('> p').text();
		$('.refImages li').eq(c).append('<img src="files/site/img/grafik.gif" alt="" width="980" height="400" />').removeClass();
		$('.refImages li').eq(c).find('> p').remove();
		$('.refImages li').eq(c).find('> img').attr('src', imgSrc);
	}
	
	function showInfoBox() {
		$('.infoBox:not(:nth(' + count + '))').hide();
		$('ul.refImages li:nth(' + count + ') .infoBox').fadeIn(500);
	}
	
	function setNewBgImage() {
		$('.home').css({'background-image' : 'url(files/site/img/' + slideshowBgName + count + '.gif)'});
	}
	
	function nextImage() {
		count++;
		if(count <= countRefImages - 1) {
			if($('.refImages li').eq(count).hasClass('loadIt')) loadIt(count);
			$('#referenceSlider ul.refImages').stop().animate({'left' : -count * stepWidth}, 1500, "easeOutExpo", function() { showInfoBox(); });
			$('.subNavi img:nth(' + (count - 1) + ')').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			$('.infoBox').fadeOut(500);
			$('.home:nth(' + count + ')').fadeIn();
		// Wenn beim letzten Bild, dann zurück auf Anfang
		} else if(count == countRefImages) {
			count = 0;
			if($('.refImages li').eq(count).hasClass('loadIt')) loadIt(count);
			$('#referenceSlider ul.refImages').stop().animate({'left' : -count * stepWidth}, 1500, "easeOutExpo", function() { showInfoBox(); });
			$('.subNavi img').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			$('.infoBox').fadeOut(500);
			$('span.home:not(:nth(' + count + '))').fadeOut();
		}
	}
	
	function prevImage() {
		count--;
		if(count >= 0) {
			if($('.refImages li').eq(count).hasClass('loadIt')) loadIt(count);
			$('#referenceSlider ul.refImages').stop().animate({'left' : -count * stepWidth}, 1500, "easeOutExpo", function() { showInfoBox(); });
			$('.subNavi img:nth(' + (count + 1) + ')').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			$('.infoBox').fadeOut(500);
			if(count == 0) {
				$('span.home:not(:nth(' + count + '))').fadeOut();
			} else { 
				$('span.home:nth(' + count + ')').fadeIn();
				$('span.home:nth(' + (count + 1) + ')').fadeOut();
			}
		// Wenn beim ersten Bild, zurück zum letzten
		} else if(count <= 0) {
			count = countRefImages - 1;
			for(var i = 0; i <= count; i++) {
				if($('.refImages li').eq(i).hasClass('loadIt')) loadIt(i);
			}
			$('#referenceSlider ul.refImages').stop().animate({'left' : -count * stepWidth}, 1500, "easeOutExpo", function() { showInfoBox(); });
			$('.subNavi img').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			$('.infoBox').fadeOut(500);
			$('span.home').fadeIn();
		}
	}
	
	function gotoImage(item) {
		itemIndex = $('.subNavi img').index(item);
		for(var i = count; i <= itemIndex; i++) {
			if($('.refImages li').eq(i).hasClass('loadIt')) loadIt(i);
			//console.log(i);
		}
		count = itemIndex;
		//loadImage(count);
		setTimeout(function() {
			$('#referenceSlider ul.refImages').stop().animate({'left' : -count * stepWidth}, 1500, "easeOutExpo", function() { showInfoBox(); });
			$('.subNavi img').attr('src', 'files/site/img/pic_0.png');
			item.attr('src', 'files/site/img/pic_1.png');
			$('.infoBox').fadeOut(500);
			if(count == 0) {
				$('span.home:not(:nth(' + count + '))').fadeOut();
			} else {
				$('span.home:not(:nth(0))').fadeOut();
				$('span.home:nth(' + count + ')').fadeIn();
			}
		}, 10);
	}
	
	function resize() {
		window.setTimeout(function() {
		stepWidth = parseInt($('ul.refImages li:first-child').width(), 10);
			$('#referenceSlider ul.refImages').stop().animate({'left' : -count * stepWidth}, 1500, "easeOutExpo");
		}, 100);
	}
	
	return {
		init:function() {
			setStage();
			$('.btnNext').click(function() { nextImage(); $(this).trigger('loadIt'); });
			$('.btnPrev').click(function() { prevImage(); $(this).trigger('loadIt'); });
			$('.subNavi img').click(function() { gotoImage($(this)); $(this).trigger('loadIt'); });
			$(window).bind('resize', resize);
		}
	};
}();

// Content-Slideshow
bytepark.contentSlider = function() {
	var countImages;
	var count = 0;
	var currentXPos;
	var imgTitle;
	
	function setStage() {
		countImages = $('#contentSlider ul.slideshowImages li').length;
		$('#contentSlider ul.slideshowImages').css({'width' : countImages * 730});
		for(var i = 0; i < countImages; i++) {
			$('.subNavi').append('<img src="files/site/img/pic_0.png" alt="" />');
		}
		var subNaviWidth = (countImages * 10) + ((countImages - 1) * 10) + 48;
		var subNaviMargin =  subNaviWidth / 2;
		$('.subNavi').css({'width' : subNaviWidth, 'margin-left' : -subNaviMargin});
		$('.subNavi img').css({'margin-right' : 10});
		$('.subNavi img:last-child').css({'margin-right' : 0});
		$('.subNavi img:nth(0)').attr('src', 'files/site/img/pic_1.png');
		$('#contentSlider').append('<a name="prevImage" class="slideBtn btnPrev"><img src="files/site/img/prev.gif" alt="" /></a><a name="nextImage" class="slideBtn btnNext"><img src="files/site/img/next.gif" alt="" /></a>');
		imgTitle = $('#contentSlider ul li:nth(0) img').attr('alt');
		$('#contentSlider .info p').text(imgTitle);
	}
	
	function nextImage() {
		count++;
		if(count <= countImages - 1) {
			$('#contentSlider ul.slideshowImages').stop().animate({'left' : -count * 730}, 1500, "easeOutExpo");
			$('.subNavi img:nth(' + (count - 1) + ')').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			imgTitle = $('#contentSlider ul li:nth(' + count + ') img').attr('alt');
			$('#contentSlider .info p').text(imgTitle);
		// Wenn beim letzten Bild, dann zurück auf Anfang
		} else if(count == countImages) {
			count = 0;
			$('#contentSlider ul.slideshowImages').stop().animate({'left' : -count * 730}, 1500, "easeOutExpo");
			$('.subNavi img').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			imgTitle = $('#contentSlider ul li:nth(' + count + ') img').attr('alt');
			$('#contentSlider .info p').text(imgTitle);
		}
	}
	
	function prevImage() {
		count--;
		if(count >= 0) {
			$('#contentSlider ul.slideshowImages').stop().animate({'left' : -count * 730}, 1500, "easeOutExpo");
			$('.subNavi img:nth(' + (count + 1) + ')').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			imgTitle = $('#contentSlider ul li:nth(' + count + ') img').attr('alt');
			$('#contentSlider .info p').text(imgTitle);
		// Wenn beim ersten Bild, zurück zum letzten
		} else if(count <= 0) {
			count = countImages - 1;
			$('#contentSlider ul.slideshowImages').stop().animate({'left' : -count * 730}, 1500, "easeOutExpo");
			$('.subNavi img').attr('src', 'files/site/img/pic_0.png');
			$('.subNavi img:nth(' + count + ')').attr('src', 'files/site/img/pic_1.png');
			imgTitle = $('#contentSlider ul li:nth(' + count + ') img').attr('alt');
			$('#contentSlider .info p').text(imgTitle);
		}
	}
	
	function gotoImage(item) {
		itemIndex = $('.subNavi img').index(item);
		count = itemIndex;
		$('#contentSlider ul.slideshowImages').stop().animate({'left' : -count * 730}, 1500, "easeOutExpo");
		$('.subNavi img').attr('src', 'files/site/img/pic_0.png');
		item.attr('src', 'files/site/img/pic_1.png');
		imgTitle = $('#contentSlider ul li:nth(' + count + ') img').attr('alt');
		$('#contentSlider .info p').text(imgTitle);
	}
	
	return {
		init:function() {
			setStage();
			$('.btnNext').click(function() { nextImage(); });
			$('.btnPrev').click(function() { prevImage(); });
			$('.subNavi img').click(function() { gotoImage($(this)); });
		}
	};
}();

//Banner-Beispiele
bytepark.bannerStage = function() {
	var params = {};
	var banner = [{
		filename : "files/site/flash/bannerbeispiele/banner1.swf",
		width : 160,
		height : 600,
		flashversion : "10",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner5.swf",
		width : 300,
		height : 250,
		flashversion : "10",
		description : "Medium Rectangle Banner",
		format : "300 x 250 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner3.swf",
		width : 980,
		height : 246,
		flashversion : "10",
		description : "Flash Stage",
		format : "980 x 246 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner4.swf",
		width : 160,
		height : 600,
		flashversion : "10",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner8.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner10.swf",
		width : 160,
		height : 600,
		flashversion : "10",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner12.swf",
		width : 160,
		height : 600,
		flashversion : "10",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/eventbanner_skyscraper.swf",
		width : 200,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "200 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/hm_hotel_skyscraper.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/boc_rectangle.swf",
		width : 250,
		height : 250,
		flashversion : "8",
		description : "Square Pop-Up",
		format : "250 x 250 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/banner_easychip_skyscraper.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/bm_shop_skyscraper.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/ebay_standard.swf",
		width : 468,
		height : 90,
		flashversion : "8",
		description : "Fullsize Banner",
		format : "468 x 90 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/kyosho_standard.swf",
		width : 468,
		height : 60,
		flashversion : "8",
		description : "Fullsize Banner",
		format : "468 x 60 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/runnersworld_superbanner.swf",
		width : 728,
		height : 90,
		flashversion : "8",
		description : "Superbanner",
		format : "728 x 90 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/km_shop_skyscraper.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/dutyfree_skyscraper.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/hm_kollektion_skyscraper.swf",
		width : 160,
		height : 600,
		flashversion : "8",
		description : "Wide Skyscraper Banner",
		format : "160 x 600 px"
	},
	{
		filename : "files/site/flash/bannerbeispiele/leaderboard.swf",
		filename2 : "files/site/flash/bannerbeispiele/skyscraper.swf",
		width : 952,
		width2 : 160,
		height : 90,
		height2 : 600,
		flashversion : "8",
		description : "Wallpaper Banner",
		format : "952 x 90 px / 160 x 600 px"
	}];
	var countBanner;
	var count = 0;
	
	function setStage() {
		$('#bannerStageWallpaper').hide();
		swfobject.embedSWF( banner[count].filename, "bannerStageBanner", banner[count].width, banner[count].height, banner[count].flashversion, null, params );		
		countBanner = banner.length;
		$('#bannerStage').append('<a name="prevImage" class="slideBtn btnPrev"><img src="files/site/img/prev.gif" alt="" /></a><a name="nextImage" class="slideBtn btnNext"><img src="files/site/img/next.gif" alt="" /></a>');
		$('#bannerWrap p').html('<strong>' + banner[count].description + '</strong><br />Format: ' + banner[count].format);
	}
	
	function nextBanner() {
		count++;
		if(count <= countBanner - 1) {
			if(banner[count].filename2) {
				$('#bannerStageBanner').hide();
				$('#bannerStageWallpaper').show();
				swfobject.embedSWF( banner[count].filename, "leaderboard", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
				swfobject.embedSWF( banner[count].filename2, "skyscraper", banner[count].width2, banner[count].height2, banner[count].flashversion, null, params );
			} else {
				$('#bannerStageWallpaper').hide();
				swfobject.embedSWF( banner[count].filename, "bannerStageBanner", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
			}
			$('#bannerWrap p').html('<strong>' + banner[count].description + '</strong><br />Format: ' + banner[count].format);
		// Wenn beim letzten Bild, dann zurück auf Anfang
		} else if(count == countBanner) {
			count = 0;
			if(banner[count].filename2) {
				$('#bannerStageBanner').hide();
				$('#bannerStageWallpaper').show();
				swfobject.embedSWF( banner[count].filename, "leaderboard", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
				swfobject.embedSWF( banner[count].filename2, "skyscraper", banner[count].width2, banner[count].height2, banner[count].flashversion, null, params );
			} else {
				$('#bannerStageWallpaper').hide();
				swfobject.embedSWF( banner[count].filename, "bannerStageBanner", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
			}
			$('#bannerWrap p').html('<strong>' + banner[count].description + '</strong><br />Format: ' + banner[count].format);
		}
	}
	
	function prevBanner() {
		count--;
		if(count >= 0) {
			if(banner[count].filename2) {
				$('#bannerStageBanner').hide();
				$('#bannerStageWallpaper').show();
				swfobject.embedSWF( banner[count].filename, "leaderboard", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
				swfobject.embedSWF( banner[count].filename2, "skyscraper", banner[count].width2, banner[count].height2, banner[count].flashversion, null, params );
			} else {
				$('#bannerStageWallpaper').hide();
				swfobject.embedSWF( banner[count].filename, "bannerStageBanner", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
			}
			$('#bannerWrap p').html('<strong>' + banner[count].description + '</strong><br />Format: ' + banner[count].format);
		// Wenn beim ersten Bild, zurück zum letzten
		} else if(count <= 0) {
			count = countBanner - 1;
			if(banner[count].filename2) {
				$('#bannerStageBanner').hide();
				$('#bannerStageWallpaper').show();
				swfobject.embedSWF( banner[count].filename, "leaderboard", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
				swfobject.embedSWF( banner[count].filename2, "skyscraper", banner[count].width2, banner[count].height2, banner[count].flashversion, null, params );
			} else {
				$('#bannerStageWallpaper').hide();
				swfobject.embedSWF( banner[count].filename, "bannerStageBanner", banner[count].width, banner[count].height, banner[count].flashversion, null, params );
			}
			$('#bannerWrap p').html('<strong>' + banner[count].description + '</strong><br />Format: ' + banner[count].format);
		}
	}
	
	return {
		init:function() {
			setStage();
			$('.btnNext').click(function() { nextBanner(); });
			$('.btnPrev').click(function() { prevBanner(); });
		}
	};
}();

// byteBlog-Archiv in der Sidebar
bytepark.blogArchiv = function() {
	var currentArchive;
	
	function toggleArchive(year) {
		currentArchive = year;
		if(!currentArchive.hasClass('active')) {
			$('.blogArchiv h4').next('ul').animate({'height' : '0px'}, 100, function() { 
				$('.blogArchiv h4').removeClass('active');
			});
			currentArchive.next('ul').animate({'height' : '44px'}, 100, function() { 
				currentArchive.addClass('active');
			});
		} else { 
			currentArchive.next('ul').animate({'height' : '0px'}, 100, function() { 
				currentArchive.removeClass('active');
			});
		}
	}
	
	return {
		init:function() {
			$('.blogArchiv ul').css({'height' : '0px'});
			$('.blogArchiv h4:nth(0)').next('ul').css({'height' : '44px'});
			$('.blogArchiv h4:nth(0)').addClass('active');
			$('.blogArchiv h4').click(function() { toggleArchive($(this)); });
		}
	};
}();

bytepark.fixMobileZoomBug = function() {
	mobilePlatform = navigator.platform.toLowerCase()
	isMobile = -~mobilePlatform.indexOf("iphone") || -~mobilePlatform.indexOf("ipad") || -~mobilePlatform.indexOf("ipod");
	metaViewport = $('meta[name="viewport"]');
	
	function setMetaViewport() {
		metaViewport.attr('content', 'width=device-width, minimum-scale=0.25, maximum-scale=1.6');
	}
	
	function init() {
		metaViewport.attr('content', 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0');
		$(document).bind('gesturestart', setMetaViewport);
	}
	
	init();
};

// Popup auf Startseite
bytepark.popup = function(o) {
    if(o.length === 0) return;
    
    var curURL = window.location.href;
    curLocation = curURL.match(/http\:\/\/www\.bytepark\.de\/english\/(be|fr|cn|il|nz|uk|za|cz|dk|es|gr|in|it|pl|se|tv|us)(?=\/)/i);
    
    curLocation = !!curLocation && curLocation[1];
    var langContent = {
    	"be" : {
    		"headline" : "Welkom bij bytepark!",
    		"welcomeText" : "Wat leuk dat je ons gevonden hebt. Als je meer over ons te weten wilt komen, neem dan een kijkje op onze Engelse pagina, waar je meer informatie kan vinden over onze werkwijze, de diensten die wij bieden op het gebied van design, IT & web development en E-business consultancy, maar ook onze reeds gedane projecten. We horen graag meer over jezelf en jouw spannende nieuwe ideeën."
    	},
    	"fr" : {
    		"headline" : "Bienvenue à bytepark!",
    		"welcomeText" : "C'est génial que vous nous ayez trouvés. Afin de mieux nous connaître, veuillez visiter notre page en anglais, et jetez un coup d'œil à notre façon de travailler, nos services dans les domaines du design, du développement informatique et internet et des conseils en commerce en ligne, ainsi qu'à nos projets passés. Nous serions heureux d'avoir de vos nouvelles et de prendre connaissance de vos idées passionnantes."
    	},
		"cn" : {
    		"headline" : "欢迎来到bytepark！",
    		"welcomeText" : "很高兴您能找到我们。要了解我们，请访问我们的英文网页，您可以更深入地了解：我们的工作方式、我们在设计领域提供的服务、IT和Web开发、电子商务咨询，以及我们做过的项目。我们期待收到您的来电并听到激动人心的想法！"
    	},
		"il" : {
    		"headline" : "ברוכים הבאים לבייטפארק!",
    		"welcomeText" : "טוב שהגעתם אלינו. כדי להכיר אותנו, אנא היכנסו לאתר שלנו באנגלית ותתרשמו מהעבודה שלנו, משירותינו בתחום העיצוב, IT ובניית אתרים, ייעוץ לאי-ביזנס ומפרויקטים קודמים שלנו. נשמח לשמוע מכם ולשמוע את הרעיונות המעניינים שלכם."
    	},
		"nz" : {
    		"headline" : "Welcome to bytepark!",
    		"welcomeText" : "It's great that you found us. To get to know us, please visit our English page, and have a closer look at our way of working, our services in the areas of design, IT & web development and e-business consulting, and our past projects. We'd be happy to hear from you and about your exciting ideas."
    	},
		"uk" : {
    		"headline" : "Welcome to bytepark!",
    		"welcomeText" : "It's great that you found us. To get to know us, please visit our English page, and have a closer look at our way of working, our services in the areas of design, IT & web development and e-business consulting, and our past projects. We'd be happy to hear from you and about your exciting ideas."
    	},
		"za" : {
    		"headline" : "Welcome to bytepark!",
    		"welcomeText" : "It's great that you found us. To get to know us, please visit our English page, and have a closer look at our way of working, our services in the areas of design, IT & web development and e-business consulting, and our past projects. We'd be happy to hear from you and about your exciting ideas."
    	},
		"cz" : {
    		"headline" : "Vítejte v bytepark!",
    		"welcomeText" : "Je skvělé, že jste nás našli. Seznámit se s námi můžete na naší anglické stránce, kde se dozvíte více o způsobu naší práce, našich službách v oblasti designu, IT a vývoje webových aplikací, poradenství v oboru e-business a našich předcházejících projektech. Rádi uvítáme vaše podnětné nápady."
    	},
		"dk" : {
    		"headline" : "Velkommen til bytepark!",
    		"welcomeText" : "Det er fantastisk at du har fundet os. For at lære os at kende, gå da venligst til vores engelske side og kig nærmere på hvordan vi arbejder, vores tjenesteydelser inden for design, IT og netudvikling, e-handelsrådgivning, og vores tidligere projekter. Vi vil blive glade for at høre fra dig og om dine spændende ideer."
    	},
		"es" : {
    		"headline" : "¡Bienvenido/a a bytepark!",
    		"welcomeText" : "Es estupendo que nos haya encontrado. Para conocernos mejor, por favor, visite nuestra página en inglés y eche un vistazo a nuestra forma de trabajar, nuestros servicios en las áreas del diseño, informática y desarrollo de páginas web y consultoría e-business, y nuestros proyectos previos. Nos encantará que se ponga en contacto con nosotros y conocer sus ideas."
    	},
		"gr" : {
    		"headline" : "Καλωσήλθατε στο bytepark!",
    		"welcomeText" : "Είμαστε πολύ χαρούμενοι που μας βρήκατε. Για να μας γνωρίσετε, παρακαλούμε επισκεφτείτε την σελίδα μας στα Αγγλικά, γνωρίστε από κοντά τον τρόπο εργασίας μας, τις υπηρεσίες μας στα πεδία σχεδιασμού, πληροφορικής, ανάπτυξης ιστοσελίδων και συμβουλευτικής για επιχειρήσεις στο διαδίκτυο όπως και παλαιότερα πρότζεκτ μας. Με χαρά μας θα ακούσουμε εσάς και τις συναρπαστικές ιδέες σας."
    	},
		"in" : {
    		"headline" : "बाइटपार्क (bytepark) में आपका स्वागत है!",
    		"welcomeText" : "कितनी अच्छी बात है कि आपने हमें ढूंढ लिया. हमारे बारे में जानने के लिए कृपया हमारे अंग्रेज़ी पृष्ठ को देखें, और वहाँ हमारे काम करने के तौर तरीके, डिजाइन के क्षेत्रों में हमारी सेवाओं, आईटी और वेब डेवलपमेंट तथा ई-बिज़नेस कंसल्टिंग तथा हमारी पिछली परियोजनाओं को बारीकी से देखें. हमें आपके विचारों व शानदार सुझावों को पाकर प्रसन्नता होगी."
    	},
		"it" : {
    		"headline" : "Benvenuto su bytepark!",
    		"welcomeText" : "È fantastico che tu sia riuscito a trovarci! Per conoscerci meglio, visita la nostra pagina in inglese: potrai scoprire nei dettagli il nostro modo di lavorare ed i servizi che ti offriamo nei settori della progettazione, dell'IT, dello sviluppo sul web e della consulenza per l'e-business, oltre ai nostri progetti precedenti. Saremmo davvero felici se ci facessi sapere cosa ne pensi e ci spiegassi le tue idee più innovative!"
    	},
		"pl" : {
    		"headline" : "Witamy w bytepark!",
    		"welcomeText" : "Świetnie, że nas znalazłeś. Aby nas poznać, przejdź do naszej strony po angielsku i przyjrzyj się bliżej jak pracujemy, jakie świadczymy usługi w zakresie projektowania, IT i tworzenia stron internetowych oraz konsultacji e-business i naszych już zakończonych projektów. Z niecierpliwością oczekujemy, że podzielisz się z nami swoimi genialnymi pomysłami."
    	},
		"se" : {
    		"headline" : "Välkommen till bytepark!",
    		"welcomeText" : "Jätteroligt att du hittade oss. För att lära känna oss bättre, besök vår engelska sida och ta en närmare titt på vårt sätt att arbeta, våra tjänster inom design, IT & webbutveckling och e-handelsrådgivning, och våra tidigare projekt. Vi vill gärna höra från dig och höra dina spännande idéer."
    	},
		"tv" : {
    		"headline" : "Welcome to bytepark!",
    		"welcomeText" : "It's great that you found us. To get to know us, please visit our English page, and have a closer look at our way of working, our services in the areas of design, IT & web development and e-business consulting, and our past projects. We'd be happy to hear from you and about your exciting ideas."
    	},
		"us" : {
    		"headline" : "Welcome to bytepark!",
    		"welcomeText" : "It's great that you found us. To get to know us, please visit our English page, and have a closer look at our way of working, our services in the areas of design, IT & web development and e-business consulting, and our past projects. We'd be happy to hear from you and about your exciting ideas."
    	}
    };
                
    function setOverlay() {
        $('#bpOverlayBg').css({'height' : '100px', 'width' : '100px', 'z-index' : 1000, 'position' : 'absolute', 'top' : 0, 'left' : 0, 'visibility' : 'visible', 'background-color' : '#000', 'opacity' : '.8', 'filter' : 'alpha(opacity=80)', '-ms-filter' : 'progid:DXImageTransform.Microsoft.Alpha(Opacity=80)'});
        $('#bpOverlay').css({'height' : '100px', 'width' : '100px', 'z-index' : 1000, 'position' : 'absolute', 'top' : 0, 'left' : 0, 'visibility' : 'hidden'});
        
        $(window).resize(resizeOverlay);
        $(window).scroll(resizeOverlay);
        $(window).trigger('resize');
       	setContent();
    }
    
    function setContent() {    	
    	o.find('.modalHeadline').text(langContent[curLocation].headline);
    	o.find('.modalHeadline ~ p').text(langContent[curLocation].welcomeText);
    	if(curLocation === "il") {
    		o.find('.modalHeadline, .modalHeadline ~ p').css({'text-align' : 'right'});
    	}
    	o.find('.international').attr('src', 'files/site/img/international/' + curLocation + '.jpg');
    }
                
    function showOverlay() {
        if($('#bpOverlay').hasClass('active')) { 
            hidePopup(); 
        } else {
            $('#bpOverlay').css('visibility','visible').addClass('active');
            window.setTimeout(function() { $('#bpOverlayBg').fadeIn(300, showPopup); }, 1000);
        }
    }
                
    function showPopup() {
    	$('object').css('visibility','hidden');
        o.fadeIn(300);
    }
                
    function hidePopup() {
        o.fadeOut();
        $('#bpOverlay').fadeOut().removeClass('active');
        $('#bpOverlayBg').fadeOut(function() {
        	$('object').css('visibility','visible');
        });
        $(document).unbind('click', hidePopup);
        
       /*var date = new Date();
		date.setTime(date.getTime()+(12*60*60));
		var expires = "; expires="+date.toGMTString();
        document.cookie = "munichmodal=visited"+expires+"; path=/";*/
    }
                
    function resizeOverlay() {
        $('#bpOverlay, #bpOverlayBg').css({'width' : $(document).width(), 'height' : $(document).height()});
    }
                
    function init() {
        if(curLocation) {
        	setOverlay();
        	showOverlay();
        	console.log(curLocation);
        }
        o.find('.closeBox').click(showOverlay);
        //$(document).bind('click', hidePopup);
    }
                
    init();
};

$(function() {
	bytepark.fixMobileZoomBug();
	//if (document.cookie.indexOf('munichmodal') == -1 && document.cookie.indexOf('visited') == -1) {
	bytepark.popup(jQuery('#bpPopup'));
	//}
});

/*
//bytepark.Newsletter = {
	//init : function() {
		//var isSending = false;
		//var responseField = $('<p id="newsletterError"></p>').hide();
		//var form = $("#footer form");
		//form.after(responseField);
		//$("#footer input[type=submit]").click(function(e) {
			//if (!isSending) {
				//responseField.fadeOut();
				//isSending = true;
				
				//$.ajax({
					//type: "POST",
					//dataType: "json",
					//data: form.serialize(),
					//url: "/newsletter_ajax.html",
					//success: function(result) {
						//isSending = false;
						//var message = "";
						//if (result.mail == "ok") {
							//message = "Vielen Dank für die Anmeldung.";
						//} else {
							//message = "Bitte geben Sie Ihre E-Mail Adresse an.";
						//}
						
						//responseField.text(message).fadeIn();
					//},
					//error: function() {
						//isSending = false;
						//responseField.text("Leider ist ein Fehler passiert. Bitte versuchen Sie es erneut.").fadeIn();
					//}
				//});
			//}
			//e.preventDefault();
		//});
	//}
//};
//$(bytepark.Newsletter.init);
*/
