/*!
 *
 * Copyright 2010, Eduardo Daniel Sada
 * You need to buy a license if you want use this script.
 * http://codecanyon.net/wiki/buying/howto-buying/licensing/
 *
 * Date: Jun 13 2010
*/

Cufon.replace('h1, h2, h3, h4, h5, h6', { hover: 'true' });

(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'); } });
    });
    
    if ($.prettyPhoto) {
      $("a[rel^='lightbox']").prettyPhoto({theme: 'ff_rounded'});
    }

    if ($.isFunction($.fn.cycle)) {
      $('#gallery').cycle({
        speed   : '500',
        timeout : 0,
        pager   : '#thumbs',
        pagerAnchorBuilder: function(idx, slide) {
          return '#thumbs ul li:eq(' + idx + ') a';
        }
      });
    }

    
    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);
