
if (!IE6) {

var navItemDropDownHeights = {
    "home":null,
    "about":100, /*130 with 'News' */
    "portfolio":150,
    "blog":130,
    "contact":null,
    "search":65
}
if (IE) {
  navItemDropDownHeights['search'] = 80;
}
jQuery(function($) {

  //
  // Main nav mouseover
  //

  
  $("#nav > ul > li").filter(".home").hover(
      
    function() { // over
      
      var overColor = '#00ccff';
      
      $(this).children("a").css({"height":"25px", "color":"#ffffff"});
      
      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','visible');
      }
      
      var newHeight = navItemDropDownHeights["home"];      
      if (null == newHeight) {
        newHeight = $(this).css('height');
      } else {
        newHeight = newHeight + 'px';
      }
      
        $(this).stop().animate({
            height: newHeight,
            borderBottomColor: overColor,
            borderLeftColor: overColor,
            borderRightColor: overColor,
            borderTopColor: overColor,
            backgroundColor: overColor }, 
            {
              queue:false, 
              duration:500, 
              easing: 'easeOutBack',             
              complete: function () { 
                if (!$(this).hasClass("current")) {              
                  $(this).css('background-image','none'); 
                }
              }
            }
          );
        
      
        
    },
    
    function() { // out

      var outHeight = 30;
      var outColor = '#262626';
      var overColor = '#00CCFF';
      
      if ($(this).hasClass("current")) {
        outColor = overColor;
        //  extra 10px needed to show small triangle graphic beneath current tab
        outHeight = 40;
      }

      if (!$(this).hasClass("current") && !IE) {              
        $(this).css('background-image','url(/wordpress/wp-content/themes/jonnymccauley-01/images/white-15-trans.png)'); 
      }      
      
      $(this).children("a").css({"height":(outHeight-15)+"px","color":"#262626"});

      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','hidden');
      }      
      
      $(this).stop().animate({
          height:outHeight + 'px',
          borderBottomColor: outColor,
          borderLeftColor: outColor,
          borderRightColor: outColor,
          borderTopColor: outColor,
          backgroundColor: outColor }, 
          { 
            queue:false, 
            duration:500, 
            easing: 'easeOutQuint', 
            complete: function () { 
              if (!$(this).hasClass("current")) {    
                if (IE) {
                  $(this).css('background-color','#262626'); 
                } else {
                  $(this).css('background-color','transparent'); 
                }
              }
            } 
          }
        );     
    }
  );
  
  
  $("#nav > ul > li").filter(".about").hover(
      
    function() { // over
      
      var overColor = '#00ccff';
      
      $(this).children("a").css({"height":"25px", "color":"#ffffff"});
      
      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','visible');
      }
      
      var newHeight = navItemDropDownHeights["about"];      
      if (null == newHeight) {
        newHeight = $(this).css('height');
      } else {
        newHeight = newHeight + 'px';
      }
      
        $(this).stop().animate({
            height: newHeight,
            borderBottomColor: overColor,
            borderLeftColor: overColor,
            borderRightColor: overColor,
            borderTopColor: overColor,
            backgroundColor: overColor }, 
            {
              queue:false, 
              duration:500, 
              easing: 'easeOutBack',             
              complete: function () { 
                if (!$(this).hasClass("current")) {              
                  $(this).css('background-image','none'); 
                }
              }
            }
          );
        
      
        
    },
    
    function() { // out

      var outHeight = 30;
      var outColor = '#262626';
      var overColor = '#00CCFF';
      
      if ($(this).hasClass("current")) {
        outColor = overColor;
        //  extra 10px needed to show small triangle graphic beneath current tab
        outHeight = 40;
      }

      if (!$(this).hasClass("current") && !IE) {              
        $(this).css('background-image','url(/wordpress/wp-content/themes/jonnymccauley-01/images/white-15-trans.png)'); 
      }      
      
      $(this).children("a").css({"height":(outHeight-15)+"px","color":"#262626"});

      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','hidden');
      }      
      
      $(this).stop().animate({
          height:outHeight + 'px',
          borderBottomColor: outColor,
          borderLeftColor: outColor,
          borderRightColor: outColor,
          borderTopColor: outColor,
          backgroundColor: outColor }, 
          { 
            queue:false, 
            duration:500, 
            easing: 'easeOutQuint', 
            complete: function () { 
              if (!$(this).hasClass("current")) {    
                if (IE) {
                  $(this).css('background-color','#262626'); 
                } else {
                  $(this).css('background-color','transparent'); 
                }
              }
            } 
          }
        );     
    }
  );
  
  
  $("#nav > ul > li").filter(".portfolio").hover(
      
    function() { // over
      
      var overColor = '#00ccff';
      
      $(this).children("a").css({"height":"25px", "color":"#ffffff"});
      
      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','visible');
      }
      
      var newHeight = navItemDropDownHeights["portfolio"];      
      if (null == newHeight) {
        newHeight = $(this).css('height');
      } else {
        newHeight = newHeight + 'px';
      }
      
        $(this).stop().animate({
            height: newHeight,
            borderBottomColor: overColor,
            borderLeftColor: overColor,
            borderRightColor: overColor,
            borderTopColor: overColor,
            backgroundColor: overColor }, 
            {
              queue:false, 
              duration:500, 
              easing: 'easeOutBack',             
              complete: function () { 
                if (!$(this).hasClass("current")) {              
                  $(this).css('background-image','none'); 
                }
              }
            }
          );
        
      
        
    },
    
    function() { // out

      var outHeight = 30;
      var outColor = '#262626';
      var overColor = '#00CCFF';
      
      if ($(this).hasClass("current")) {
        outColor = overColor;
        //  extra 10px needed to show small triangle graphic beneath current tab
        outHeight = 40;
      }

      if (!$(this).hasClass("current") && !IE) {              
        $(this).css('background-image','url(/wordpress/wp-content/themes/jonnymccauley-01/images/white-15-trans.png)'); 
      }      
      
      $(this).children("a").css({"height":(outHeight-15)+"px","color":"#262626"});

      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','hidden');
      }      
      
      $(this).stop().animate({
          height:outHeight + 'px',
          borderBottomColor: outColor,
          borderLeftColor: outColor,
          borderRightColor: outColor,
          borderTopColor: outColor,
          backgroundColor: outColor }, 
          { 
            queue:false, 
            duration:500, 
            easing: 'easeOutQuint', 
            complete: function () { 
              if (!$(this).hasClass("current")) {    
                if (IE) {
                  $(this).css('background-color','#262626'); 
                } else {
                  $(this).css('background-color','transparent'); 
                }
              }
            } 
          }
        );     
    }
  );
  
  
  $("#nav > ul > li").filter(".blog").hover(
      
    function() { // over
      
      var overColor = '#00ccff';
      
      $(this).children("a").css({"height":"25px", "color":"#ffffff"});
      
      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','visible');
      }
      
      var newHeight = navItemDropDownHeights["blog"];      
      if (null == newHeight) {
        newHeight = $(this).css('height');
      } else {
        newHeight = newHeight + 'px';
      }
      
        $(this).stop().animate({
            height: newHeight,
            borderBottomColor: overColor,
            borderLeftColor: overColor,
            borderRightColor: overColor,
            borderTopColor: overColor,
            backgroundColor: overColor }, 
            {
              queue:false, 
              duration:500, 
              easing: 'easeOutBack',             
              complete: function () { 
                if (!$(this).hasClass("current")) {              
                  $(this).css('background-image','none'); 
                }
              }
            }
          );
        
      
        
    },
    
    function() { // out

      var outHeight = 30;
      var outColor = '#262626';
      var overColor = '#00CCFF';
      
      if ($(this).hasClass("current")) {
        outColor = overColor;
        //  extra 10px needed to show small triangle graphic beneath current tab
        outHeight = 40;
      }

      if (!$(this).hasClass("current") && !IE) {              
        $(this).css('background-image','url(/wordpress/wp-content/themes/jonnymccauley-01/images/white-15-trans.png)'); 
      }      
      
      $(this).children("a").css({"height":(outHeight-15)+"px","color":"#262626"});

      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','hidden');
      }      
      
      $(this).stop().animate({
          height:outHeight + 'px',
          borderBottomColor: outColor,
          borderLeftColor: outColor,
          borderRightColor: outColor,
          borderTopColor: outColor,
          backgroundColor: outColor }, 
          { 
            queue:false, 
            duration:500, 
            easing: 'easeOutQuint', 
            complete: function () { 
              if (!$(this).hasClass("current")) {    
                if (IE) {
                  $(this).css('background-color','#262626'); 
                } else {
                  $(this).css('background-color','transparent'); 
                }
              }
            } 
          }
        );     
    }
  );
  
  
  $("#nav > ul > li").filter(".contact").hover(
      
    function() { // over
      
      var overColor = '#00ccff';
      
      $(this).children("a").css({"height":"25px", "color":"#ffffff"});
      
      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','visible');
      }
      
      var newHeight = navItemDropDownHeights["contact"];      
      if (null == newHeight) {
        newHeight = $(this).css('height');
      } else {
        newHeight = newHeight + 'px';
      }
      
        $(this).stop().animate({
            height: newHeight,
            borderBottomColor: overColor,
            borderLeftColor: overColor,
            borderRightColor: overColor,
            borderTopColor: overColor,
            backgroundColor: overColor }, 
            {
              queue:false, 
              duration:500, 
              easing: 'easeOutBack',             
              complete: function () { 
                if (!$(this).hasClass("current")) {              
                  $(this).css('background-image','none'); 
                }
              }
            }
          );
        
      
        
    },
    
    function() { // out

      var outHeight = 30;
      var outColor = '#262626';
      var overColor = '#00CCFF';
      
      if ($(this).hasClass("current")) {
        outColor = overColor;
        //  extra 10px needed to show small triangle graphic beneath current tab
        outHeight = 40;
      }

      if (!$(this).hasClass("current") && !IE) {              
        $(this).css('background-image','url(/wordpress/wp-content/themes/jonnymccauley-01/images/white-15-trans.png)'); 
      }      
      
      $(this).children("a").css({"height":(outHeight-15)+"px","color":"#262626"});

      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','hidden');
      }      
      
      $(this).stop().animate({
          height:outHeight + 'px',
          borderBottomColor: outColor,
          borderLeftColor: outColor,
          borderRightColor: outColor,
          borderTopColor: outColor,
          backgroundColor: outColor }, 
          { 
            queue:false, 
            duration:500, 
            easing: 'easeOutQuint', 
            complete: function () { 
              if (!$(this).hasClass("current")) {    
                if (IE) {
                  $(this).css('background-color','#262626'); 
                } else {
                  $(this).css('background-color','transparent'); 
                }
              }
            } 
          }
        );     
    }
  );
  
  
  $("#nav > ul > li").filter(".search").hover(
      
    function() { // over
      
      var overColor = '#00ccff';
      
      $(this).children("a").css({"height":"25px", "color":"#ffffff"});
      
      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','visible');
      }
      
      var newHeight = navItemDropDownHeights["search"];      
      if (null == newHeight) {
        newHeight = $(this).css('height');
      } else {
        newHeight = newHeight + 'px';
      }
      
        $(this).stop().animate({
            height: newHeight,
            borderBottomColor: overColor,
            borderLeftColor: overColor,
            borderRightColor: overColor,
            borderTopColor: overColor,
            backgroundColor: overColor }, 
            {
              queue:false, 
              duration:500, 
              easing: 'easeOutBack',             
              complete: function () { 
                if (!$(this).hasClass("current")) {              
                  $(this).css('background-image','none'); 
                }
              }
            }
          );
        
      
        
    },
    
    function() { // out

      var outHeight = 30;
      var outColor = '#262626';
      var overColor = '#00CCFF';
      
      if ($(this).hasClass("current")) {
        outColor = overColor;
        //  extra 10px needed to show small triangle graphic beneath current tab
        outHeight = 40;
      }

      if (!$(this).hasClass("current") && !IE) {              
        $(this).css('background-image','url(/wordpress/wp-content/themes/jonnymccauley-01/images/white-15-trans.png)'); 
      }      
      
      $(this).children("a").css({"height":(outHeight-15)+"px","color":"#262626"});

      if ($(this).hasClass('search')) {
        $(this).find('form').css('visibility','hidden');
      }      
      
      $(this).stop().animate({
          height:outHeight + 'px',
          borderBottomColor: outColor,
          borderLeftColor: outColor,
          borderRightColor: outColor,
          borderTopColor: outColor,
          backgroundColor: outColor }, 
          { 
            queue:false, 
            duration:500, 
            easing: 'easeOutQuint', 
            complete: function () { 
              if (!$(this).hasClass("current")) {    
                if (IE) {
                  $(this).css('background-color','#262626'); 
                } else {
                  $(this).css('background-color','transparent'); 
                }
              }
            } 
          }
        );     
    }
  );
  
    

  //
  // Post image mouseover border colours
  //
  
  $(".post .image").hover(
      function() { borderOver($(this), "#ffffff", 200); }, 
      function() { borderOut($(this), "#262626", 200); }
  );  

  //
  // Sidebar 'Share' box accordion
  //
    
  $("a#sb-share-btn").toggle(
      function() { 
        $(this).parent().stop().animate(
          { height:'107px' },
          { queue:false, duration:400, easing: 'easeOutBack' }); 
      }, 
      function() { 
        $(this).parent().stop().animate(
          { height:'20px' },
          { queue:false, duration:300, easing: 'easeOutQuint' }); 
      }
  );    
  if (!IE) {
    jQuery("#footer > div").hover(
      function () {
        $(this).stop().animate(
          {top:'0px'},
          {queue:false, duration:750,easing:'easeOutQuint'}
        );
      },
      function () {
        $(this).stop().animate(
          {top:'215px'},
          {queue:false, duration:1000,easing:'easeOutBack'}
        );
      }
    );
  } else {
    jQuery("#footer > div").css({'top':'0px'}); 
  }
  
}); // end jQuery(function)


function borderOver(obj, overColor, speed) {
  $(obj).animate({ 
    borderBottomColor: overColor, 
    borderLeftColor: overColor,
    borderRightColor: overColor,
    borderTopColor: overColor }, speed);
}

function borderOut(obj, outColor, speed) {
  $(obj).animate({  
    borderBottomColor: outColor,
    borderLeftColor: outColor,
    borderRightColor: outColor,
    borderTopColor: outColor }, speed);
}

function mycarousel_initCallback(carousel) {
    jQuery('#carousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    jQuery('#carousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
};

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}


var IE = (typeof(IE) !== "undefined" && IE === true);

if (IE) {
  // Modify setTimeout and setInterval to allow argument passing
  // Credit: http://url.ie/1mwu
  (function(f) {
      window.setTimeout = f(window.setTimeout);
      window.setInterval = f(window.setInterval);
  })(function(f) {
      return function(c, t) {
          var a = [].slice.call(arguments, 2);
          return f(function() {
              c.apply(this, a);
          }, t);
      };
  });
}

// Carousel stuff.
var carouselCurrent = 0;
var carouselCount;
var shift = 610;

$(document).ready(function () {

  var ulwidth = 0;
  carouselCount = $("#carousel li").length;
  
  $("#carousel ul img").each(function (i) {
    ulwidth += $(this).outerWidth(true);// + 4;
  });
  
  $("#carousel ul").css("width", ulwidth);
  
  $("#carousel-right").click(function () {
    carouselMove(1);
  });
  
  $("#carousel-left").click(function () {
    carouselMove(-1);
  });

  // Carousel auto-cycle / hover
  var cycleDur = 12000;
  var moveDur = 500;
  var cycleCarousel = setInterval(carouselMove, cycleDur, 1); // last parameter is an argument to carouselMove
  $("#carousel").hover(
    function() {
      $("div.info", this).stop().animate({ top:"260px"}, moveDur, "easeOutExpo");
      clearInterval(cycleCarousel);
      cycleCarousel = null;
    }, 
    function() {
      $("div.info", this).stop().animate({ top:"300px"}, moveDur, "easeInExpo");
      if (!cycleCarousel) {
        cycleCarousel = setInterval(carouselMove, cycleDur, 1);
      }
    });
  
  // RSS animation
  var pulseDur = 6000;
  $("#rss-icon").css("display","block");
  if (!IE) {
    var rssPulsing = setInterval(pulseRSS, pulseDur, pulseDur);
  }
  
  $("#rss-icon").hover(
    function () {
      if (!IE) {
        clearInterval(rssPulsing);
        $(this).stop().animate({ opacity:1 }, 200, "easeOutQuad");
      } 
    },
    function () {
      if (!IE) {
        $(this).stop().animate({ opacity:0 }, 1200, "easeOutQuad", function () 
        { rssPulsing = setInterval("pulseRSS("+pulseDur+")", pulseDur); });
      } 
    });
    
  
  // FancyBox stuff
  jQuery("div#fancy_close").hover(function () {
      $(this).css("background-position", "-50px -1px");
    }, function () {
      $(this).css("background-position", "0px -1px");
    });
    
  
  // Post listings rollovers
  
  var post_listing_detail_bg_hover ='url(/wordpress/wp-content/themes/jonnymccauley-01/images/post-listing-detail-bg-trans.png)';
  jQuery("div.post-listing div.image").hover(
    function () {
      var post_listing_image_bg = jQuery(this).css("background-image");
      $(this).css({"background-color": "#00CCFF"});
    }, 
    function () {
      if (IE) {
        $(this).css({"background-color": "#262626"});
      } else {
        $(this).css({"background-color": "transparent"});
      }
    });
  
  // CSS resize for images that are not already 610px wide
  $(".post a img.size-full").each(function () {
    w1 = this.width;
    h1 = this.height;
    w2 = 610;
    h2 = Math.round(w2*h1/w1);
    this.width=w2;
    this.height=h2;
  });
  
  // equal height columns
  heightL = $("#primary").height();
  heightR = $("#secondary").height();
  
  if (heightL < heightR) {
    // resize left col
    $("#primary").height(heightR);
  } else {
    // resize right col
    $("#secondary").height(heightL);
  }
  
  // search form field text replacement
  textReplacement($('#nav > ul > li.search form #s')); 
  
  
});



// Carousel animation
function carouselMove(direction) {
  
  //console.log("move carousel " + direction);
  
  var dur = 700;
  var easing = "easeOutExpo";
  var wrap = false;
  
  if (direction == -1) {
    if (carouselCurrent > 0) {
      carouselCurrent--;
    } else {
      carouselCurrent = carouselCount - 1;
      wrap = true;
    }
  } else if (direction == 1) {
    if (carouselCurrent < carouselCount - 1) {
      carouselCurrent++;
    } else {
      carouselCurrent = 0;
      wrap = true;
    }
  }
  
  if (wrap) {
      dur *= carouselCount/3;
      easing = "easeInSine";      
  }
  
  var newPos = -shift*(carouselCurrent);
  $("#carousel ul").stop().animate({ left:newPos+"px"}, dur, easing);      
}    

function pulseRSS(pulseDur) {
  $("#rss-icon").animate({ opacity:1 }, pulseDur*0.2, "easeOutQuad", function () {
      $("#rss-icon").animate({ opacity:0 }, pulseDur*0.133, "easeOutQuad");
    });
}


function textReplacement(input){
 var originalvalue = input.val();
 input.focus( function(){
  if( $.trim(input.val()) == originalvalue ){ input.val(''); }
 });
 input.blur( function(){
  if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
 });
}




function addLoadEvent(fn) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = fn;
  } else {
    window.onload = function() {
      oldonload();
      fn();
    }
  }
}

addLoadEvent(externalLinks);

}

