// HOME PAGE

      (function ($) {
        $.fn.fadeTransition = function(options) {
          var options = $.extend({pauseTime: 5000, transitionTime: 2000}, options);
          var transitionObject;

          Trans = function(obj) {
            var timer = null;
            var current = 0;
            var els = $("> *", obj).css("display", "none").css("left", "0").css("top", "0").css("position", "absolute");
            $(obj).css("position", "relative");
            $(els[current]).css("display", "block");

            function transition(next) {
              $(els[current]).fadeOut(options.transitionTime);
              $(els[next]).fadeIn(options.transitionTime);
              current = next;
              cue();
            };

            function cue() {
              if ($("> *", obj).length < 2) return false;
              if (timer) clearTimeout(timer);
              timer = setTimeout(function() { transition((current + 1) % els.length | 0)} , options.pauseTime);
            };
            
            this.showItem = function(item) {
              if (timer) clearTimeout(timer);
              transition(item);
            };

            cue();
          }

          this.showItem = function(item) {
            transitionObject.showItem(item);
          };

          return this.each(function() {
            transitionObject = new Trans(this);
          });
        }

      })(jQuery);
    
      var page = {
        tr: null,
        init: function() {
          page.tr = $(".area").fadeTransition({pauseTime: 7000, transitionTime: 2000});
          $("div.navigation").each(function() {
            $(this).children().each( function(idx) {
              if ($(this).is("a"))
                $(this).click(function() { page.tr.showItem(idx); })
            });
          });
        },

        show: function(idx) {
          if (page.tr.timer) clearTimeout(page.tr.timer);
          page.tr.showItem(idx);
        }
      };

      $(document).ready(page.init);    

// CONTENT SLIDER TOGGLE

$(document).ready(function () {
	$('#contentslider li').click(function () {
		var text = $(this).children('.contentslider_content');
		if (text.is(':hidden')) {
			text.slideDown('200');
			$(this).children('span').html('-');
		} else {
			text.slideUp('200');
			$(this).children('span').html('+');
		}
	});
});


// TABS

$(document).ready(function() {

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first-last tab
	$(".tab_content:first").show(); //Show firstlast tab content

	//On Click Event
	$("ul.tabs li, div.xtratablink").click(function() {
		$("ul.tabs li, div.xtratablink").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});


// COLORBOX

$(document).ready(function(){
 $("a[rel='gallery']").colorbox({transition:"fade"});
 $("a[rel='rehearsalgallery']").colorbox({transition:"fade"});
 $(".video").colorbox({iframe:true, innerWidth:560, innerHeight:340});
 $(".innerpage").colorbox();
});

// TWITTER FEED

$(document).ready(function() {
	$("#twitter").getTwitter({
		userName: "TalawaTheatreCo",
		numTweets: 5,
		loaderText: "Loading tweets...",
		slideIn: false,
		slideDuration: 750,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true,
		showTimestamp: true
	});
});



