function grayscaleImageIE(imgObj)
	{
			imgObj.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)';
	}

function grayscaleImage(imgObj)
	{
			var canvas = document.createElement('canvas');
			var canvasContext = canvas.getContext('2d');
			
			var imgW = imgObj.width;
			var imgH = imgObj.height;
			canvas.width = imgW;
			canvas.height = imgH;
			
			canvasContext.drawImage(imgObj, 0, 0);
			var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
			
			for(var y = 0; y < imgPixels.height; y++){
					for(var x = 0; x < imgPixels.width; x++){
							var i = (y * 4) * imgPixels.width + x * 4;
							var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
							imgPixels.data[i] = avg; 
							imgPixels.data[i + 1] = avg; 
							imgPixels.data[i + 2] = avg;
					}
			}
			
			canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
			return canvas.toDataURL();
	}


$(document).ready(function() {
	
	var tmpInd = 0;
	var tmpIndOld = 0;
	var aktFlag = 0;

	$("#carousel_wrapper").everyTime(5000, 'controlled', function() {
		if ( tmpInd < 2 ) {
			tmpInd++;
			$(".homeTab:eq("+ tmpIndOld +")").fadeOut("slow", function() {
				 $("#carousel_top_right li").removeClass('akt');
					$("#carousel_top_right li:eq("+tmpInd+")").addClass('akt');
				 $(".homeTab:eq("+tmpInd+")").fadeIn("slow",function () { 
				 }); 
			});
			tmpIndOld = tmpInd;
		} else {
			tmpInd=0;
			$(".homeTab:eq("+tmpIndOld+")").fadeOut("slow", function() {
				 $("#carousel_top_right li").removeClass('akt');
				 $("#carousel_top_right li:eq("+tmpInd+")").addClass('akt');
				 $(".homeTab:eq("+tmpInd+")").fadeIn("slow",function () { 
					 
				 });
			});
			tmpIndOld = tmpInd;
		}
	});

	$(window).blur(function() {
		$("#carousel_wrapper").stopTime();
		aktFlag = 1;
	});

	$(window).focus(function() {
		if ( aktFlag == 1 ) {
			$("#carousel_wrapper").everyTime(5000, 'controlled', function() {
				if ( tmpInd < 2 ) {
					tmpInd++;
					$(".homeTab:eq("+ tmpIndOld +")").fadeOut("slow", function() {
						 $("#carousel_top_right li").removeClass('akt');
							$("#carousel_top_right li:eq("+tmpInd+")").addClass('akt');
						 $(".homeTab:eq("+tmpInd+")").fadeIn("slow",function () { 
						 }); 
					});
					tmpIndOld = tmpInd;
				} else {
					tmpInd=0;
					$(".homeTab:eq("+tmpIndOld+")").fadeOut("slow", function() {
						 $("#carousel_top_right li").removeClass('akt');
						 $("#carousel_top_right li:eq("+tmpInd+")").addClass('akt');
						 $(".homeTab:eq("+tmpInd+")").fadeIn("slow",function () { 
							 
						 });
					});
					tmpIndOld = tmpInd;
				}
			});
		aktFlag = 0;
		}
	});

	$('#carousel_top_right a').click(function() {
		$("#carousel_wrapper").stopTime('controlled');
		var indexTmp = $(this).parent().parent().find("a").index(this);
		var indexAkt = $(".akt").index("#carousel_top_right li");
		tmpInd = indexTmp;
		if (indexTmp != indexAkt) {
			$(".homeTab:eq("+indexAkt+")").fadeOut("slow", function() {
				 $("#carousel_top_right li").removeClass('akt');
					$("#carousel_top_right li:eq("+indexTmp+")").addClass('akt');
				 $(".homeTab:eq("+indexTmp+")").fadeIn("slow",function () { 
			 
				 }); 
			});
		}
		tmpIndOld = tmpInd;
		$("#carousel_wrapper").everyTime(5000, 'controlled', function() {
			if ( tmpInd < 2 ) {
				tmpInd++;
				$(".homeTab:eq("+ tmpIndOld +")").fadeOut("slow", function() {
					 $("#carousel_top_right li").removeClass('akt');
					 $(".homeTab:eq("+tmpInd+")").fadeIn("slow",function () { 
						 $("#carousel_top_right li:eq("+tmpInd+")").addClass('akt');
						 
					 }); 
				});
				tmpIndOld = tmpInd;
			} else {
				tmpInd=0;
				$(".homeTab:eq("+tmpIndOld+")").fadeOut("slow", function() {
					 $("#carousel_top_right li").removeClass('akt');
					 $(".homeTab:eq("+tmpInd+")").fadeIn("slow",function () { 
						 $("#carousel_top_right li:eq("+tmpInd+")").addClass('akt');
						 
					 });
				});
				tmpIndOld = tmpInd;
			}
		});
		return false;
	});


	$('#carousell')
		.anythingSlider({
		 width          : 301,
		 height         : 208,
		 delay          : 3500,  
		 autoPlay       : true,
		 buildStartStop : false,
		 hashTags				: false,
		 buildArrows		: true,
		 buildNavigation: false,
		 startStopped   : false,
		 stopAtEnd      : false,
		 infiniteSlides	: false,
		 theme          : 'metallic',
		 onSlideComplete : function(slider){
		 	$("#carousell").parents("div.user").find(".currentSl").text(slider.currentPage);
			checkCurrentSlide('#carousell', slider.currentPage);
		 }
	});

	$('#carousel2')
		.anythingSlider({
		 width          : 301,
		 height         : 140,
		 delay          : 4000,  
		 autoPlay       : false,
		 buildStartStop : false,
		 hashTags				: false,
		 buildArrows		: true,
		 buildNavigation: false,
		 startStopped   : false,
		 infiniteSlides	: false,
		 stopAtEnd      : false,
		 theme          : 'metallic',
		 onSlideComplete : function(slider){
		 	$("#carousel2").parents("div.user").find(".currentSl").text(slider.currentPage);
			checkCurrentSlide('#carousel2', slider.currentPage);
		 }
	});

	$('#carousel3')
		.anythingSlider({
		 width          : 301,
		 height         : 205,
		 delay          : 4000,  
		 autoPlay       : false,
		 buildStartStop : false,
		 hashTags				: false,
		 buildArrows		: false,
		 buildNavigation: false,
		 startStopped   : false,
		 infiniteSlides	: false,
		 stopAtEnd      : false,
		 theme          : 'metallic',
		 onSlideComplete : function(slider){
		 	$("#carousel3").parents("div.user").find(".currentSl").text(slider.currentPage);
			checkCurrentSlide('#carousel3', slider.currentPage);
		 }
	});

	function checkCurrentSlide (div, current) {
		var numberOf = $(div).parents("div.user").find(".anythingWindow ul li").size();
		if ( current == numberOf ) {
			$(div).parents("div.user").find('.rightArrowCar').css("background-position", "0 -11px");
			$(div).parents("div.user").find('.leftArrowCar').css("background-position", "0 0");
			setTimeout("$('"+div+"').anythingSlider(0)",3500);
		} else if (current==1) {
			$(div).parents("div.user").find('.leftArrowCar').css("background-position", "0 -11px");
			$(div).parents("div.user").find('.rightArrowCar').css("background-position", "0 0");
		} else {
			$(div).parents("div.user").find('.rightArrowCar').css("background-position", "0 0");
			$(div).parents("div.user").find('.leftArrowCar').css("background-position", "0 0");
		}
	}

	$('.maxSl').each(function(index) {
		$(this).text($(this).parents("div.user").find(".anythingWindow ul li").size());
	});

	$('.leftArrowCar').click(function() {
		var idTmp = $(this).parents("div.user").find(".anythingWindow ul").attr("id");
		$('#'+ idTmp +'').data('AnythingSlider').goBack();
		$('#'+ idTmp +'').data('AnythingSlider').startStop(false);
		/*setTimeout(function(){
			$('#'+ idTmp +'').data('AnythingSlider').startStop(true);
		},4000);*/
		return false;
	});

	$('.rightArrowCar').click(function() {
		var idTmp = $(this).parents("div.user").find(".anythingWindow ul").attr("id");
		$('#'+ idTmp +'').data('AnythingSlider').goForward();
		$('#'+ idTmp +'').data('AnythingSlider').startStop(false);
		/*setTimeout(function(){
			$('#'+ idTmp +'').data('AnythingSlider').startStop(true);
		},4000);*/
		return false;
	});

	$("#menu div ul li a:contains('Investments')").parent().find("ul").hide(); 
	$("#menu div ul li a:contains('Our team')").parent().find("ul").hide(); 

	$('.selDrop a').click(function(event) {
		event.preventDefault(); 
		var inputTmp = $(this).attr('href');
		if ( inputTmp.search("&") == -1 ) {
			$('#filterForm input').val("");
		}
		inputTmp = inputTmp.replace("?", "");
		queryString = new Array();
		var pairs = inputTmp.split("&");
		for (var i = 0; i < pairs.length; i++)
		{
				var tmpPAir = pairs[i];
				var keyval = tmpPAir.split( "=" );
				$('input[name='+keyval[0]+']').val(keyval[1]);
		}
		$('#filterForm').submit();
	});

	$('.leftConSmallCol .contactSmall:first').css('border-top', '1px dotted #999999');
	$('.rightConSmallCol .contactSmall:first').css('border-top', '1px dotted #999999');

	$('.innnerContactSm').hide();
	$('.conSmTitle').addClass('closedContSmall');

	$('.conSmTitle').click(function(event) {
		event.preventDefault();
		$(this).parent().find('.innnerContactSm').slideToggle('slow');
		if ( $(this).parent().css('background-color') == 'transparent' ) {
			$(this).parent().css('background-color', '#D8EBF6');
			$(this).removeClass('closedContSmall').addClass('openedContSmall');
		} else {
			$(this).parent().css('background-color', 'transparent');
			$(this).removeClass('openedContSmall').addClass('closedContSmall');
		}
	});

	$('.quoteBigContainerHidden').hide();
	$('.quoteBigContainer').children('br').remove(); 
	$('.quoteBigContainer').children('p').each(function() {     
		var $this = $(this);     
		if($this.html().replace(/\s|&nbsp;/g, '').length == 0) {
			$this.remove();
		}
	}); 

	$('.quoteBigContainerTitle').click(function(event) {
		event.preventDefault();
		$(this).parent().find('.quoteBigContainerHidden').slideToggle('slow');
		if ( !$(this).hasClass('aktPlusBig')) {
			$(this).parent().find('.noMargin').css('margin-bottom', '10px');
			$(this).parent().css('background-color', '#D8EBF6');
			$(this).css('margin-bottom', '10px');
			//$(this).parent().css('border-top', '4px solid #D8EBF6');
			$(this).addClass('aktPlusBig');
		} else {
			$(this).parent().find('.noMargin').css('margin-bottom', '0px');
			$(this).css('margin-bottom', '0px');
			$(this).parent().css('background-color', '#D8EBF6');
			//$(this).parent().css('border-top', '4px solid #fff');
			$(this).removeClass('aktPlusBig');
		}
	});

	$(".team_member_outer1").each(function(){ 
		$(this).append($("<span class=\"bl\"></span>"));
		$(this).find("img").one("load",function(){
			grayscale(this);
		})
		.each(function(){
			if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
			$(this).trigger("load");
		}); 
  }); 

	$(".team_member_outer2").each(function(){ 
		$(this).append($("<span class=\"bl\"></span>"));
  	$(this).find("img").one("load",function(){
			grayscale(this);
		})
		.each(function(){
			if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
			$(this).trigger("load");
		}); 
  }); 

	$(".team_member_outer1").hover(
		function () {
			$(this).find("span.bl").remove(); 
			grayscale.reset( $(this).find('img') );
		}, 
		function () {
			$(this).append($("<span class=\"bl\"></span>"));
			image = $(this).find('img');
			grayscale(image);
		}
	);

	$(".team_member_outer2").mouseenter(function() { 
    $(this).find("span.bl").remove(); 
		grayscale.reset( $(this).find('img') );
  }).mouseleave(function() { 
		$(this).append($("<span class=\"bl\"></span>"));
		image = $(this).find('img');
		grayscale(image);
  });

	$(".pagination").children(".page-numbers:last-child").css("background-image", "none");
	$(".contactBox").addClass("clearfix");
	$("#main_content .newsItem").last().css("border-bottom", "0");
	$(".st_sharethis").hide();
	$("#menu a").removeAttr("title");
	$("#menu > div > ul").children("li.page_item:last-child").css("background-image", "none");

	$(".innnerContactSm").each(function(){ 
		$(this).find(".innnerContactSm").removeClass("innnerContactSm").show();
	}); 

	$(".iicon").hover(
		function () {
			$(this).find(".iPopup").show(); 
		}, 
		function () {
			$(this).find(".iPopup").hide(); 
		}
	);

	$(".user_grey .link_box2").last().css('border-bottom','0');

	$("#mc_signup_submit").click(function() {
		$("#mc_message").css('zoom', '1');
	});	

});
