$(document).ready(function(){
		
	//Twitter	
	if($('#twitter').length){
		$("#twitter").getTwitter({
			userName: "tagitmobile",
			numTweets: 2,
			loaderText: "Loading tweets...",
			slideIn: true,
			showHeading: false,
			showProfileLink: false
		});
	}

	//set margin of icons
	if($('#icon_list').length){
		var children = $('#icon_list').children().length;
		var platz = children * 115;
		platz = 930 - platz;
		children++;
		platz = platz / children;
		$('#icon_list li').each(function(){
			$(this).css({'margin-left': platz + 'px'});
		});
	}
	
	//start Slideshow at Home
	$('.slideshow').jcarousel({
			wrap: 'circular',
			scroll: 1,
			auto: 6,
			start: 1
	});
	
	//Change Headline at Home every 10 seconds
	$('.headline_list ul').cycle({ 
		fx:     'fade', 
		speed:   1000, 
		timeout: 10000, 
		next:   '.headline_list ul', 
		pause:   1 
	});
	
	$('#awards .item').each(function(){
		$(this).hide();
	});
	$('#awards .item:eq(0)').show();
	$('#awards .item:eq(1)').show();
	$('#awards .item:eq(2)').show();
	
	if($('#awards .item').length < 4){
		$('.openclose.awards').remove();
	}
	
	$('#clients_overview li').each(function(index){
		$(this).hide();
		if(index%3 == 0){
			$(this).addClass('noMargin');
		}
	});
	$('#clients_overview li:eq(0)').show();
	$('#clients_overview li:eq(1)').show();
	$('#clients_overview li:eq(2)').show();
	$('#clients_overview li:eq(3)').show();
	$('#clients_overview li:eq(4)').show();
	$('#clients_overview li:eq(5)').show();

	
	$('.openclose.awards .button').bind('click', function(){
		if($(this).parent().hasClass('open')){
			$(this).parent().removeClass('open');
			$(this).parent().addClass('close');
			var image = $(this).find('img');
			image.attr('src','fileadmin/template/img/icons/open.gif');
			var current_height = $('#awards').height();
			$('#awards .item').each(function(){
				$(this).show();
			});
			$('#awards').css('height','auto');
			var height = $('#awards').height();
			$('#awards').css('height', current_height + 'px');
			$('#awards').animate({	'height': height});
		}else{
			if($(this).parent().hasClass('close')){
				$(this).parent().removeClass('close');
				$(this).parent().addClass('open');
				var image = $(this).find('img');
				image.attr('src','fileadmin/template/img/icons/close.gif');
				var current_height = $('#awards').height();
				$('#awards .item').each(function(){
					$(this).hide();
				});
				$('#awards .item:eq(0)').show();
				$('#awards .item:eq(1)').show();
				$('#awards .item:eq(2)').show();
				$('#awards').css('height','auto');
				var height = $('#awards').height();
				$('#awards .item').each(function(){
					$(this).show();
				});
				$('#awards').css('height', current_height + 'px');
				$('#awards').animate({	'height': height});
				$('#awards .item').each(function(){
					$(this).hide();
				});
				$('#awards .item:eq(0)').show();
				$('#awards .item:eq(1)').show();
				$('#awards .item:eq(2)').show();
			}
		}
	});
	
	$('#industries .item').each(function(){
		$(this).height('auto');
	})
	
	$('#industries .button').bind('click', function(){
		if($(this).parent().hasClass('open')){
			var item = $(this).parent().parent();
			var current_height = item.height();
			item.find('div:eq(0)').hide();
			item.find('div:eq(1)').show();
			$(this).parent().removeClass('open');
			$(this).parent().addClass('close');
			var image = $(this).find('img');
			image.attr('src','fileadmin/template/img/icons/open.gif');
			item.css('height','auto');
			var height = item.height();
			item.css('height', current_height +'px');
			item.animate({	'height': height});
		}else{
			if($(this).parent().hasClass('close')){
				var item = $(this).parent().parent();
				var current_height = item.height();
				//item.find('div:eq(1)').hide();
				item.find('div:eq(0)').css({'display':'block','position':'absolute','visibility':'hidden'});
				//item.find('div:eq(0)').show();
				$(this).parent().removeClass('close');
				$(this).parent().addClass('open');
				var image = $(this).find('img');
				image.attr('src','fileadmin/template/img/icons/close.gif');
				//item.css('height','auto');
				var height = item.find('div:eq(0)').height();
				var height1 = item.find('div:eq(1)').height();
				var dif = height1 - height;
				var itemheight = current_height - dif;
				item.find('div:eq(0)').css({'display':'none','position':'static','visibility':'visible'});
				//item.find('div:eq(0)').hide();
				//item.find('div:eq(1)').show();
				//item.css('height', current_height +'px');
				item.animate({	'height': itemheight}, function(){
					item.find('div:eq(1)').hide();
					item.find('div:eq(0)').show();
				});
			}
		}
	});
	
	$('#case_studies .button').bind('click', function(){
		if($(this).parent().hasClass('open')){
			var item = $(this).parent().parent();
			var current_height = item.height();
			item.find('.intro').hide();
			item.find('.main').show();
			$(this).parent().removeClass('open');
			$(this).parent().addClass('close');
			var image = $(this).find('img');
			image.attr('src','fileadmin/template/img/icons/open.gif');
			item.css('height','auto');
			var height = item.height() + 40;
			item.css('height', current_height +'px');
			item.animate({	'height': height});
		}else{
			if($(this).parent().hasClass('close')){
				var item = $(this).parent().parent();
				var current_height = item.height();
				//item.find('.main').hide();
				//item.find('.intro').show();
				var image_height = item.find('.left img').height();
				$(this).parent().removeClass('close');
				$(this).parent().addClass('open');
				var image = $(this).find('img');
				image.attr('src','fileadmin/template/img/icons/close.gif');
				//item.css('height','auto');
				//var height = item.height();
				//item.css('height', current_height +'px');
				item.animate({	'height': image_height}, function(){
					item.find('.main').hide();
					item.find('.intro').show();
				});
			}
		}
	});
	
	$('#two_columns.bborder .button').bind('click', function(){
		if($(this).parent().hasClass('open')){
			var item = $('#two_columns.bborder');
			var current_height = item.height();
			$(this).parent().removeClass('open');
			$(this).parent().addClass('close');
			var image = $(this).find('img');
			image.attr('src','fileadmin/template/img/icons/open.gif');
			$('#two_columns.bborder .intro').hide();
			$('#two_columns.bborder .main').show();
			item.css('height','auto');
			var height = item.height() + 40;
			$('#two_columns.bborder .main').hide();
			$('#two_columns.bborder .intro').show();
			
			item.css('height', current_height +'px');
			item.animate({	'height': height}, function(){
				$('#two_columns.bborder .intro').hide();
				$('#two_columns.bborder .main').show();
			});
		}else{
			if($(this).parent().hasClass('close')){
				var item = $('#two_columns.bborder');
				var current_height = item.height();
				$(this).parent().removeClass('close');
				$(this).parent().addClass('open');
				var image = $(this).find('img');
				image.attr('src','fileadmin/template/img/icons/close.gif');
				item.animate({	'height': '245px'}, function(){
					$('#two_columns.bborder .intro').show();
					$('#two_columns.bborder .main').hide();
				});
			}
		}
	});
	
	$('.openclose.clientover .button').bind('click', function(){
		if($(this).parent().hasClass('open')){
			var item = $('#clients_overview');
			var current_height = item.height();
			$('#clients_overview li').each(function(){
				$(this).show();
			});
			$(this).parent().removeClass('open');
			$(this).parent().addClass('close');
			var image = $(this).find('img');
			var span = $(this).parent().find('span');
			span.hide();
			image.attr('src','fileadmin/template/img/icons/open.gif');
			item.css('height','auto');
			var height = item.height();
			item.css('height', current_height +'px');
			item.animate({'height': height});
		}else{
			if($(this).parent().hasClass('close')){
				var item = $('#clients_overview');
				var current_height = item.height();
				$(this).parent().removeClass('close');
				$(this).parent().addClass('open');
				var image = $(this).find('img');
				var span = $(this).parent().find('span');
				span.show();
				image.attr('src','fileadmin/template/img/icons/close.gif');
				item.animate({'height': '340px'}, function(){
					$('#clients_overview li').each(function(){
						$(this).hide();
					});
					$('#clients_overview li:eq(0)').show();
					$('#clients_overview li:eq(1)').show();
					$('#clients_overview li:eq(2)').show();
					$('#clients_overview li:eq(3)').show();
					$('#clients_overview li:eq(4)').show();
					$('#clients_overview li:eq(5)').show();
				});
			}
		}
	});	
	
	$('#jobs .button').bind('click', function(){
		if($(this).parent().hasClass('open')){
			var item = $(this).parent().parent();
			var current_height = item.height();
			$(this).parent().removeClass('open');
			$(this).parent().addClass('close');
			var image = $(this).find('img');
			image.attr('src','fileadmin/template/img/icons/open.gif');
			item.find('.description').show();
			item.css('height','auto');
			var height = item.height() + 40;
			item.css('height', current_height +'px');
			item.animate({	'height': height});
		}else{
			if($(this).parent().hasClass('close')){
				var item = $(this).parent().parent();
				//var current_height = item.height();
				$(this).parent().removeClass('close');
				$(this).parent().addClass('open');
				var image = $(this).find('img');
				image.attr('src','fileadmin/template/img/icons/close.gif');
				var desc_height = item.find('.description').height();
				//item.css('height','auto');
				var height = item.height();
				height = height - desc_height - 40;
				//item.find('.description').show();
				//item.css('height', current_height +'px');
				item.animate({	'height': height}, function(){
					item.find('.description').hide();
				});
			}
		}
	});
	
	$('#icon_list img').bind('click', function(){
		var number = $(this).attr('alt');
		if($('#industries .item.num'+number+' .openclose').hasClass('open')){
			$('#industries .item.num'+number+' a.button').click().delay(500).show(1,function(){
				$.scrollTo('#industries .item.num'+number, 1000);
			});
		}else{
			$.scrollTo('#industries .item.num'+number, 1000);
		}
	});
	
	function numberList(){
		//var counter = 0;
		$('#icon_list img').each(function(index){
			$(this).attr('alt',index);
		});
		$('#industries div.item').each(function(index){
			$(this).addClass('num'+index);
		});
	}
	
	numberList();
	
	$.extend({
	  getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
		  hash = hashes[i].split('=');
		  vars.push(hash[0]);
		  vars[hash[0]] = hash[1];
		}
		return vars;
	  },
	  getUrlVar: function(name){
		return $.getUrlVars()[name];
	  }
	});
	
	var allVars = $.getUrlVars();
	var id = $.getUrlVar('id');
	if(id){
		id = id.split("#");
		if(id[0] == 12){
			var pro_intro = $('#'+id[1]).find('.intro');
			var pro_main = $('#'+id[1]).find('.main');
			pro_main.show();
			pro_intro.hide();
			$('#'+id[1]).find('.button img').attr('src','fileadmin/template/img/icons/open.gif');
			var pro_height = $('#'+id[1]).find('.item').height();
			$('#'+id[1]).find('.item').css({'height': pro_height + 40 + 'px'});
			$('#'+id[1]).find('.openclose').removeClass('open');
			$('#'+id[1]).find('.openclose').addClass('close');
		}
	}
	
});
