Cufon.replace('#page > h1', { fontFamily: 'matricia-bold-regular', hover: true });
Cufon.replace('#content .menu > li > a, .side h2, .side h4', { fontFamily: 'matricia-bold', hover: true });
Cufon.replace('.menu > li > h2, .motto, #content #page .news a h2, #content #page .tabContent h3', { fontFamily: 'matricia-book', hover: true });

/*
 * jQuery tabToggle plugin

 * Date 6/8/2009
 * razvan.caliman(at)gmail(dot)com | http://github.com/oslego/tabToggle/tree/master
 * @author Razvan Caliman
 * @version 1.0
 */
(function(a){a.fn.tabToggle=function(b,c){return function(h,d,g){var l=function(){h.removeClass(config.selectedClass)};var j=function(){d.hide()};var f=function(m,n){l();j();a(m).addClass(config.selectedClass);a(n).show()};var e=function(){var o=parseInt(config.defaultSelectedIndex,10);var n=h.length-1;var m=(n<o||isNaN(o))?n:o;f(h[m],d[m])};var i=function(){h.each(function(m){$trigger=a(this);$target=a(d[m]);$trigger.bind("click",function(n,o){return function(){f(n,o)}}($trigger,$target))})};var k=function(){e();i()};config=a.extend({},a.fn.tabToggle.defaults,g);if(h&&d&&d.length==h.length&&d.length>0){k()}return h}(a(this),a(b),c)};a.fn.tabToggle.defaults={selectedClass:"selected",defaultSelectedIndex:0}})(jQuery);



function preload(arrayOfImages) {
  $(arrayOfImages).each(function(){
      (new Image()).src = this;
  });
}

// Javascript for pages start here!
(function ($, undefined) {
$('document').ready(function() {

  // notice effect
  $('.notice').delay(500).slideDown('fast');
  $('.close').click(function() {
    $('.notice').slideUp('fast');
  });


  // grab IE version, just because :)
  var isIE = (navigator.appName=="Microsoft Internet Explorer");
  var IEversion = navigator.appVersion;
  if(isIE) {
  	IEversion = parseInt(IEversion.substr(IEversion.indexOf("MSIE")+4));
  } else {
  	IEversion = 0;
  }

	// dropdown for solutions and resources
	$('#content .menu > li > a.parent').click(function() {
		return false;
	});
	$('#content .menu a.parent').click(function() {
		if (($(this).parent().parent().parent().hasClass('Solutions') || $(this).parent().parent().parent().hasClass('Solutii')) && $(this).parent().parent().parent().hasClass('first')) {
			//return false;
		}
    if ($(this).parent().parent().parent().hasClass('Industries') || $(this).parent().parent().parent().hasClass('Department') || $(this).parent().parent().parent().hasClass('Industrii') || $(this).parent().parent().parent().hasClass('departamentale')) {
      return;
    }
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
			$(this).next('ul').slideUp('fast');
		} else {
			$(this).addClass('open');
			$(this).next('ul').slideDown('fast');
		}
		$(this).parent().siblings().each(function() {
			if (!$(this).children().hasClass('active')) {
				$(this).children('a').removeClass('open');
				$(this).children('ul').slideUp('fast');
				Cufon.now();
			}
		});
	});
	$('#content .menu .Solutions.active.first > ul').show();
	$('#content .menu .Solutions.first ul li ul').show();

	$('#content .menu .Solutii.active.first > ul').show();
	$('#content .menu .Solutii.first ul li ul').show();

	// carousel for solutions
	if($('.carousel > ul > li').length > 0) {
		textPrev = 'Previous';
		textNext = 'Next';
		if (lang == 'ro') {
			textPrev = 'Anterior';
			textNext = 'Urmator';
		}
		var w = 468;
		var count = $('.carousel > ul > li').length;
		var lis = count*w;
		var ml = 0;
		var pagination = '.carousel > ul > li > h2 > span';
		$('.carousel > ul').css('width', lis+'px');
		$(pagination).html('1/'+count);
		var theLis = $('.carousel > ul > li > h2 > strong');
		var nextLi = theLis[1];
		$('.next').html(textNext+': <em>'+$(nextLi).html()+'</em> &gt;');
		$('.next').click(function() {
			ml += w;
			if (ml >= lis)
				ml = 0;
			var x = ml/w+1;
			$('.carousel > ul').animate({marginLeft: '-'+ml+'px'}, 1000, function() {$(pagination).html(x+'/'+count)});
			if (x == count) $('.next').hide();
			else $('.next').show();
			if (x == 1) $('.prev').hide();
			else $('.prev').show();
			var prevLi = theLis[x-2];
			var nextLi = theLis[x];
			$('.prev').html('&lt; '+textPrev+': <em>'+$(prevLi).html()+'</em>');
			$('.next').html(textNext+': <em>'+$(nextLi).html()+'</em> &gt;');
		});
		$('.prev').click(function() {
			ml -= w;
			if (ml <= 0)
				ml = 0;
			var x = ml/w+1;
			$('.carousel > ul').animate({marginLeft: '-'+ml+'px'}, 1000, function() {$(pagination).html(x+'/'+count)});
			if (x == count) $('.next').hide();
			else $('.next').show();
			if (x == 1) $('.prev').hide();
			else $('.prev').show();
			var prevLi = theLis[x-2];
			var nextLi = theLis[x];
			$('.prev').html('&lt; '+textPrev+': <em>'+$(prevLi).html()+'</em>');
			$('.next').html(textNext+': <em>'+$(nextLi).html()+'</em> &gt;');
		});
		$('.sprev').click(function() {$('.prev').click()});
		$('.snext').click(function() {$('.next').click()});
	} else {
		$('.carousel').hide();
	}

	// tab toggle for resources and case studies
	if ($('#tabs a').length) {
		$('#tabs a').tabToggle($('#tabsContent>div'));
		var hash = decodeURI(window.location.hash);
		hash = hash.substr(1,hash.length).split('|');
		var tab = hash[0];
		var content = hash[1];
		$('#tabs a').each(function() {
			if ($(this).attr('id') == 'menu-'+tab) {
				$(this).click();
			}
		});
		$('#tabsContent h3').each(function() {
			var title = '';
			$(this).children('cufon').each(function() {
				title += $(this).attr('alt');
			});
			if (title == content) {
				var top = $(this).offset();
				top = top.top-20;
				$('html, body').animate({scrollTop: top}, "slow");
			}
		});
	}

	// scroll videos for product demos
	var vids = $('.scroll div a').length;
	if (vids <= 3) {
		$('.videos .top, .videos .bottom').hide();
	} else {
		var sHeight = $('.scroll').css('height');
		sHeight = sHeight.substr(0, sHeight.length-2);
		var t = vids*500;
    if (isIE && IEversion == 7) {
      var pixels = vids*70 - sHeight;
    } else {
      var pixels = vids*70 - sHeight + 35;
    }
		$('.videos .top').mouseover(function() {
			$('.scroll > div').animate({marginTop: '0px'}, t);
		});
		$('.videos .bottom').mouseover(function() {
			$('.scroll > div').animate({marginTop: '-'+pixels+'px'}, t);
		});
		$('.videos .top, .videos .bottom').mouseout(function() {
			$('.scroll > div').stop();
		});
	}
	$("#slideshow2").jCarouselLite({
		btnNext: ".hNext",
		btnPrev: ".hPrev",
		speed: 500,
		auto: null,
		visible: 1,
		scroll: -1
	});
	$("#slideshow").jCarouselLite({
		btnNext: ".hNext",
		btnPrev: ".hPrev",
		vertical: true ,
		speed: 500,
		auto: null,
		visible: 1,
		scroll: -1
	});

  // tabs hash navigation
	if ($('#solution').length && $('#industry').length && window.location.hash) {
		var hash = decodeURI(window.location.hash);
		hash = decodehash.substr(1,hash.length);
		if (hash == 'Enterprise Resource Planning (ERP)')
			hash = 'Microsoft Dynamics AX';
		if (hash == 'Business Intelligence')
			hash = 'QlikView';
		$('#solution option').each(function() {
			if ($(this).val() == hash)
				$('#solution').val(hash);
		});
		$('#industry option').each(function() {
			if ($(this).val() == hash)
				$('#industry').val(hash);
		});
	}

  // colorbox
	$(".colorbox").colorbox({width:"80%", height:"80%", iframe:true});

  // search placeholder
  var search = document.getElementById('headSearchInput');
  if ('placeholder' in search) {
  } else {
    var text = $('#headSearchInput').attr('placeholder');
    $('#headSearchInput').val(text).css({'color': '#999'}).focus(function() {
      if ($(this).val() == text) {
        $(this).val('').css({'color': '#000'});
      } else if ($(this).val() == '') {
          $(this).val(text).css({'color': '#999'});
      }
    }).blur(function() {
      if ($(this).val() == '') {
        $(this).val(text).css({'color': '#999'});
      }
    });
  }

  // preload images
  preload([
    'assets/components/matricia/images/back-menu.png'
  ]);

  // alternative images
  $('#content #page .solindustries:nth-child(2n) img').each(function() {
		$(this).css({'float': 'right', 'margin-left': '10px'});
	});


	if (lang == 'ro') {
		$('.error').each(function() {
			if ($(this).html() == 'This field is required.') {
				$(this).html('Camp obligatoriu.');
			}
		});
	}
});
}(jQuery));
