/**
 * Globals
 */
var debugThis = 0;
function debug(s){if(debugThis)alert(s);}

/**
 * Onload
 */
var onSlide = 1;
jQuery(document).ready(function() {
  
  /*
   * Initialize tabs for slider/carousel
   */
  
  
  /*
   * Initialize for Portfolio
   */
  if( $(".portfolio").length ) {
    debug("portfolio.php");
    for(var i=1; i<cl+1; i++) {
      var client = "#client_"+i;
      $(client).bind( "mouseenter",function() {
        var num = this.id.split("_");
        $("#tab_"+num[1]).attr( "src", "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_"+num[1]+".png" );
      });
      $(client).bind( "mouseleave",function() {
        var num = this.id.split("_");
        $("#tab_"+num[1]).attr( "src", "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_"+num[1]+".png" );
      });
    }
  }
  
  /*
   * Initialize for Client page
   */
/*
  if( $(".tab-on").length ) {
    debug("client.php");
    var tabOn = $(".tab-on").attr("id");
    for(var i=1; i<cl+1; i++) {
      if(tabOn != "tab_"+i) {
        var client = "#tab_"+i;
        $(client).css( "background", "url('http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_"+i+".png')" );
        $(client).bind( "mouseenter",function() {
          var num = this.id.split("_");
          $(this).css( "background", "url('http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_"+num[1]+".png')" );
        });
        $(client).bind( "mouseleave",function() {
          var num = this.id.split("_");
          $(this).css( "background", "url('http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_"+num[1]+".png')" );
        });
      } else {
        var client = "#tab_"+i;
        $(client).css( "background", "url('http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_"+i+".png')" );
        $(client).unbind( "mouseenter" );
        $(client).unbind( "mouseleave" );
      }
    }
  }
  */
  /*
   * Initialize for Services page
   */
  if( $("#services-image").length ) {
    debug("services.php");
    $("#services-onlinemarketing").bind( "click", function() {
      $("#services-image").attr( "src", "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_onlinemarketing.jpg" );
      $(".services-text").css( "visibility", "hidden" );
      $("#text-onlinemarketing").css( "visibility", "visible" );
    });
    $("#services-socialmedia").bind( "click", function() {
      $("#services-image").attr( "src", "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_socialmedia.jpg" );
      $(".services-text").css( "visibility", "hidden" );
      $("#text-socialmedia").css( "visibility", "visible" );
    });
    $("#services-mobile").bind( "click", function() {
      $("#services-image").attr( "src", "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_mobile.jpg" );
      $(".services-text").css( "visibility", "hidden" );
      $("#text-mobile").css( "visibility", "visible" );
    });
    $("#services-webdevelopment").bind( "click", function() {
      $("#services-image").attr( "src", "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_webdevelopment.jpg" );
      $(".services-text").css( "visibility", "hidden" );
      $("#text-webdevelopment").css( "visibility", "visible" );
    });
  }
  
  
  
});

/**
 * Callback function for carousel
 */
function slider_initCallback(carousel) {
  jQuery('.slider-controls a').bind('click', function() {
    carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
    return false;
  });
};

/**
 * Image preload
 */
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);
jQuery.preLoadImages(
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_1.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_2.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_3.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_4.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_5.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_6.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_7.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_8.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_9.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_10.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_11.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_gray_12.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_1.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_2.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_3.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_4.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_5.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_6.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_7.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_8.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_9.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_10.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_11.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/tab_red_12.png",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_onlinemarketing.jpg",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_socialmedia.jpg",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_mobile.jpg",
  "http://xperienceinteractive.com/wp-content/themes/xperienceinteractive/images/services_webdevelopment.jpg"
);
