

Cufon.replace('h1, h2, h3, h4, h5, h6', { hover: 'true' });

function dofancy(abc) {
$.fancybox(abc, {
        'overlayShow' : false,
        'titleShow' : false,
        'autoScale' : true,
        
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
});

}

(function($) {

  $(document).ready(function(){

    $('form a.submit').click(function(evt){
      $(this).parents('form').get(0).submit();
      evt.preventDefault();
    });

    $("#menu ul li").has("ul").hover(function(){
      $(this).addClass('hover');    
    }, function(){
      $(this).removeClass('hover');
    }).addClass("submenu").children("a").wrapInner("<span></span>");
    
    $("#menu ul li ul li ul").parent("li").addClass("submenu");
    
    $(".widget a.hide").click(function(ev){
      $(this).parents(".widget").find("div.hide").slideToggle();
      ev.preventDefault();
    });
    
    $('#portfolio .one_third').hover(function() {
      $('#portfolio .one_third').not(this).stop().animate({opacity: 0.4}, 300);
    }, function() {
      $('#portfolio .one_third').stop().animate({opacity: 1}, 200, function() { if (jQuery.browser.msie) { $(this).get(0).style.removeAttribute('filter'); } });
    });
    
    
      $("a[rel^='lightbox']").fancybox();
    

    if ($.isFunction($.fn.cycle)) {
      $('#gallery').cycle({
        speed   : '500',
        timeout : 0,
        pager   : '#thumbs',
        pagerAnchorBuilder: function(idx, slide) {
          return '#thumbs ul li:eq(' + idx + ') a';
        }
      });
    }
    
    var swap = function(id, what, delay) {
        var ci = $(id);
        delay *= 7000;
        /*ci.animate({opacity:1},*/
        window.setTimeout(function() {
            ci.animate({opacity:0}, 500, function() {
                ci.attr('src', what);
                ci.animate({opacity:1}, 500);
            });
    
        }, delay);

    };
    
    swap('#ci1', 'clients/ontario.png', 2);
    swap('#ci2', 'clients/harley.png', .8);
    swap('#ci3', 'clients/thermogenics.png', 4);
    swap('#ci4', 'clients/ldj.png', 3);
    swap('#ci5', 'clients/essay.png', 6);

    swap('#ci6', 'clients/adidas.png', 5);
    swap('#ci7', 'clients/loreal.png', 8);
    swap('#ci8', 'clients/olg.png', 7);
    
    
    swap('#ci1', 'clients/pg.png', 10);
    swap('#ci2', 'clients/hyundai.png', 9);
    swap('#ci3', 'clients/baush.png', 11);
    swap('#ci4', 'clients/olympics.png', 12);
    swap('#ci5', 'clients/lindt.png', 13);

    
    var maxHeight=0;var maxElement=null;var eles=new Array();var i=0;
    var tres = $('.sidebar').length?3:4;
    $('.product').each(function(i) {
      eles.push(this);
      if (($(this).height()+parseInt($(this).css("padding-bottom"))+parseInt($(this).css("padding-top")))>maxHeight) {
        maxHeight=$(this).height()+parseInt($(this).css("padding-top"))+parseInt($(this).css("padding-bottom"));
        maxElement=this;
      }
      $(eles).each(function() {$(this).height(maxHeight-parseInt($(this).css("padding-top"))-parseInt($(this).css("padding-bottom")))})
      if (((i+1)%tres)==0) {
        i=0;
        maxHeight=0;
        maxElement=null;
        eles=new Array();
      }
      i=i+1;
      
      $(this).find('.thumb').hover(function(){
        boton = $(this).find('.viewmore');
        boton.fadeTo(200, (jQuery.browser.msie?0.7:1), function() { if (jQuery.browser.msie) { $(this).addClass('viewmoreie'); $(this).get(0).style.removeAttribute('filter'); } });
      }, function() {
        boton = $(this).find('.viewmore');
        boton.removeClass('viewmoreie');
        boton.fadeOut(200);
      });
    });

  });
  
})(jQuery);
