﻿
(function($) {
  $.sliderMain = function() {
  
    var curItem = 1;
	var maxPage = 0;
	var timeoutVar;
  
	function loadNewBanner() {
      clearTimeout(timeoutVar);
	  doTimeout();
	  var oldPage = curItem;
      if (curItem < 1) {
        curItem = 1;
      } else if (curItem > maxPage) {
        curItem = maxPage;
      }
	  
	  $('.mainSoeMod .triggers a').removeClass('bigBtnOn');
	  $('.mainSoeMod .triggers a[rel="'+curItem+'"]').addClass('bigBtnOn');
	  $('ul.gallery li .txt').hide();
	  $('ul.gallery li .lblName').show();
	  $('ul.gallery li.item'+curItem+' .txt').show();
	  $('ul.gallery li.item'+curItem+' .lblName').hide();
	  
	  $('ul.gallery li.item'+curItem).animate({marginLeft: '600px'}, 500, function(){
			if (curItem == 1){
				$('ul.gallery li:nth-child(1)').css("z-index","3");
				$('ul.gallery li:nth-child(2)').css("z-index","1");
				$('ul.gallery li:nth-child(3)').css("z-index","2");
			}
			if (curItem == 2){
				$('ul.gallery li:nth-child(1)').css("z-index","2");
				$('ul.gallery li:nth-child(2)').css("z-index","3");
				$('ul.gallery li:nth-child(3)').css("z-index","1");
			}
			if (curItem == 3){
				$('ul.gallery li:nth-child(1)').css("z-index","1");
				$('ul.gallery li:nth-child(2)').css("z-index","2");
				$('ul.gallery li:nth-child(3)').css("z-index","3");
			}
		}).animate({marginLeft: '0px'});
	}

	function runNext() {
      curItem++;
      if (curItem > maxPage) {
        curItem = 1;
      }
      loadNewBanner();
    }
	
	function quickSwap() {
      $('.mainSoeMod .triggers a').removeClass('bigBtnOn');
	  $('.mainSoeMod .triggers a[rel="'+curItem+'"]').addClass('bigBtnOn');
	  $('ul.gallery li .txt').hide();
	  $('ul.gallery li .lblName').show();
	  $('ul.gallery li.item'+curItem+' .txt').show();
	  $('ul.gallery li.item'+curItem+' .lblName').hide();
	  $('ul.gallery li').css("z-index","2");
	  $('ul.gallery li.item'+curItem).css("z-index","5");
		doTimeout();
    }

    maxPage = $('ul.gallery li').size();

	$(".mainSoeMod .triggers a").hover(function() {
	  curItem = $(this).attr('rel');
	  clearTimeout(timeoutVar);
	  quickSwap();
      return false;
    });
	
	$('ul.gallery li img').click(function() {
	  curItem = $(this).parent().attr('id');
	  clearTimeout(timeoutVar);
	  quickSwap();
      return false;
    });

    //$("ul.gallery li").hover(function() {
	  //clearTimeout(timeoutVar);
    //}, function() {
//      doTimeout();
  //  });
	
	doTimeout();
	
	function doTimeout() {
	  timeoutVar = setTimeout(function() {
        runNext();
      }, 5000);
	}
	
	return this;
  }
})(jQuery);

$( function() {
	$.sliderMain();
});



// Satffordhouse Twitter Feed
getTwitters('twitter', { 
  id: 'staffordhouse', 
  count: 1, 
  enableLinks: true, 
  ignoreReplies: true, 
  clearContents: true,
  template: '%text% - <a class="time" href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'
});


