jQuery.noConflict();
var currentMargin = '';
jQuery(document).ready(function() {

  jQuery('.footer .widget h2').each(function(){
  jQuery(this).html('<span>' + jQuery(this).html() + '</span>');
  });

  jQuery('.footer #menu-footer-links').prepend(jQuery('<li class="empty"></li>'));

  // HOVER THAT LOGO
  jQuery('.logo a').hover(function() {
    jQuery(this).stop().animate({ 'top':'-5px' }, 300);
  },function() {
    jQuery(this).stop().animate({ 'top':'0' }, 300);
  });


  // Main Navigation

  jQuery('.navigation div > ul ul li:last-child').addClass('last');

  jQuery(".sub-menu").parent("li").addClass("parent");
  jQuery('.navigation ul.sub-menu li.parent').append('<span></span>');

  jQuery('.navigation ul.sub-menu li.parent').hover(function() {
    jQuery(this).find('span').css('backgroundPosition', '0 top');
  }, function() {
    jQuery(this).find('span').css('backgroundPosition', '0 bottom');
  });

  jQuery('.navigation ul li').hover(function() {
    jQuery(this).find('a').css('color','#fff');
  },function() {
    jQuery(this).find('a').css('color','#333');
    jQuery(this).find('.current-page-ancestor a').css('color','#fff');
  });

  jQuery('.navigation ul li.current-page-ancestor').hover(function() {
    jQuery(this).find('a').css('color','#fff');
  },function() {
    jQuery(this).find('a').css('color','#fff');
  });
  jQuery('.navigation ul li.current-menu-item').hover(function() {
    jQuery(this).find('a').css('color','#fff');
  },function() {
    jQuery(this).find('a').css('color','#fff');
  });



  // INDENT LINKS IN NAV
  jQuery('.sub-menu li a').hover(function() {
    jQuery(this).stop().animate({ "paddingLeft" : "20px"}, 200);
  },function() {
    jQuery(this).stop().animate({"paddingLeft" : "10px"});
  });


  // INDENT LINKS THE READ MORE LINK
  jQuery('.read-more').hover(function() {
    jQuery(this).stop().animate({ "paddingLeft" : "5px"}, 200);
  },function() {
    jQuery(this).stop().animate({"paddingLeft" : "0"});
  });

  // INDENT LINKS IN FOOTER SECTION
  jQuery('.footer .widget_themeteam_footer_links li a').hover(function() {
    jQuery(this).stop().animate({ "paddingLeft" : "10px"}, 200);
  },function() {
    jQuery(this).stop().animate({"paddingLeft" : "0"});
  });


  jQuery('.page .small-image-listing .post .thumbnail').hover(function() {
    jQuery(this).stop().animate({
      "top" : "-15px",
      "height" : "235px" }, 300);
  }, function() {
    jQuery(this).stop().animate({
      "top" : "0",
      "height" : "220px" }, 300);
  });


  // MOAR SPAN - sidebar navigation
  jQuery('.col-side.common-sidebar .nav .subnav li').append('<span></span>');

  jQuery('.col-side.common-sidebar .nav .subnav li').hover(function() {
    jQuery(this).find('span').css('backgroundPosition', 'left bottom');
  }, function() {
    jQuery(this).find('span').css('backgroundPosition', 'left top');
  });

  jQuery('.col-side.common-sidebar .nav .subnav li:last-child').addClass('last');


  /*TABS ELEMENTS PAGE*/
  if(jQuery().tabs) {
    jQuery(".tabs").tabs({
      fx: { opacity: 'toggle', duration: 200}
    });

  }


  /* TOGGLE CONTENT BOXES */
  jQuery('.toggle h4').each(
    function () {

      var iHeight = jQuery(this).closest('.toggle').find('.inner').height();
      var ipaddingTop = jQuery(this).closest('.toggle').find('.inner').css('padding-top');
      var ipaddingBottom = jQuery(this).closest('.toggle').find('.inner').css('padding-bottom');

      jQuery(this).toggle(
        function () {

          imageURL = '/wp-content/themes/graffiti';
          jQuery(this).find('span').attr('class');

          jQuery(this)
          .closest('.toggle')
          .find('.inner')
          .animate({height: 0, paddingTop: 0, paddingBottom: 0, opacity: 0 }, 200, 'jswing');
          jQuery(this)
          .find('span')
          .css('background', 'url('+ imageURL +'/images/tab-toggle.png) left top');
        },
        function () {

          jQuery(this)
          .closest('.toggle')
          .find('.inner')
          .animate({height: iHeight, paddingTop: ipaddingTop, paddingBottom: ipaddingBottom, opacity: 1}, 200, 'jswing');

          jQuery(this)
          .find('span')
          .css('background', 'url('+ imageURL +'/images/tab-toggle.png) left bottom');
        }
      );
    }
  );

  /*PORTFOLIO FILTER*/
  jQuery('ol.skills a').click(function() {
    jQuery(this).css('outline','none');
    jQuery('ol.skills .current').removeClass('current');
    jQuery(this).parent().addClass('current');

    var filterVal = jQuery(this).text().toLowerCase().replace(' ','-');
    if(filterVal == 'all') {
      jQuery('ul#portfolio_list li.hidden').fadeIn('slow').removeClass('hidden');
    } else {

      jQuery('ul#portfolio_list li').each(function() {
        if(!jQuery(this).hasClass(filterVal)) {
          jQuery(this).fadeOut('normal').addClass('hidden');
        } else {
          jQuery(this).fadeIn('slow').removeClass('hidden');
        }
      });
    }

    return false;
  });

});

jQuery(window).load(function(){


  jQuery('.magnifier img').each(function(){
    imgW = jQuery(this).width();
    imgH = jQuery(this).height();
    magn = jQuery('<span class="thumb-magnifier" style="width:' + (imgW) + 'px; height:' + (imgH) + 'px; margin:0px 0px 0px 0px;"><span class="magnifier" style="width:' + (imgW) + 'px; height:' + (imgH) + 'px; margin-top:-' + (imgH) + 'px;"></span></span>');
    jQuery(this).parent().append(magn);
  });

  jQuery('.thumb-magnifier').hover(function() {
        inside = jQuery(this).find('.magnifier');
      currentMargin = inside.css('margin-top');
      inside.stop(true,true).animate({marginTop:'0'},500);
    }, function() {
      if(currentMargin === '' || currentMargin === '0') return;
      inside = jQuery(this).find('.magnifier');
      inside.stop(true,true).animate({marginTop:currentMargin},500);
    });

  jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook'});

});
