Advertisement
Guest User

Untitled

a guest
Apr 27th, 2011
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. // JavaScript Document
  2. (function( $ ){
  3.  
  4. var homeFunc = {
  5.  
  6. /* Direction of carousel */
  7. direction : 'next',
  8.  
  9. counter : 0,
  10.  
  11. /* Initialise values and functions for home page */
  12. init : function( options ){
  13.  
  14. var settings = {};
  15.  
  16. return this.each(function() {
  17. // If options exist, lets merge them
  18. // with our default settings
  19.  
  20. if ( options ) {
  21. $.extend( settings, options );
  22. }
  23.  
  24. $(document.getElementById('contentSliderControls')).css('visibility','visible');
  25.  
  26. var $prev = document.getElementById('prevSlide'),
  27. $pause = document.getElementById('pauseSlide'),
  28. $next = document.getElementById('nextSlide'),
  29. $lis = $('#contentSlider ul li'),
  30. $tabLinks = $('#verticalTabs ul li');
  31.  
  32. $lis.each(function(i, el) {
  33.  
  34. $(el).css('z-index', i).addClass('slide'+i);
  35.  
  36. });
  37.  
  38.  
  39. /* Run Carousel
  40. ****************************************************************/
  41. homeFunc.timer();
  42.  
  43.  
  44. /* Setup Tabbed area by calling tabbed section
  45. ****************************************************************/
  46. homeFunc.tabbedSection($tabLinks);
  47.  
  48.  
  49. /* The pause Click handler
  50. ****************************************************************/
  51. $pause.onclick = function(e){
  52. e.preventDefault();
  53.  
  54. if ($('#pauseSlide').length){
  55.  
  56. $('#pauseSlide').find('img').attr('src', 'images/icon_home_content_slider_play.gif');
  57.  
  58. $(this).attr('id','playSlide');
  59.  
  60. var intervalID = null;
  61.  
  62. clearInterval(intervalID);
  63.  
  64. } else {
  65.  
  66. $('#playSlide').find('img').attr('src', 'images/icon_home_content_slider_pause.gif');
  67.  
  68. $(this).attr('id','pauseSlide');
  69.  
  70. homeFunc.timer('next');
  71. }
  72.  
  73. }
  74.  
  75. /* The next Click handler
  76. ****************************************************************/
  77. $next.onclick = function(e){
  78. e.preventDefault();
  79. homeFunc.direction = 'next';
  80. if( $('#contentSlider ul li.top').is(':animated') ) {
  81.  
  82. homeFunc.animateCarousel('next', 100);
  83.  
  84. }else {
  85. homeFunc.animateCarousel('next');
  86.  
  87. }
  88.  
  89. }
  90.  
  91. /* The previous Click handler
  92. ****************************************************************/
  93. $prev.onclick = function(e){
  94.  
  95. homeFunc.direction = 'prev';
  96. e.preventDefault();
  97.  
  98. if( $('#contentSlider ul li.top').is(':animated') ) {
  99.  
  100. homeFunc.animateCarousel('prev', 100);
  101.  
  102. }else {
  103. homeFunc.animateCarousel('prev');
  104.  
  105. }
  106.  
  107. }
  108.  
  109.  
  110. }); //End of each function();
  111.  
  112. },
  113.  
  114.  
  115. /* Carousel Timer function
  116. *********************************************************************************************************************************************************************************/
  117.  
  118. timer : function(direction){
  119. setInterval(function() {
  120. homeFunc.animateCarousel(direction);
  121. }, 4000, 1);
  122. },
  123.  
  124. /* Vertical Tabbed area functionality
  125. *********************************************************************************************************************************************************************************/
  126. tabbedSection : function($tabLinks){
  127.  
  128.  
  129. $tabLinks.click(function(e){
  130. // On Click remove the current panel class from the previous Panel
  131. $(".currentP").removeClass("currentP");
  132. // Find the current tab with the current tab image and remove it
  133. //$(".currentTab").find('img').remove();
  134. // On click remove the current tab class from the previous tab
  135. $(".current").removeClass("current");
  136. // On click add current tab class to current tab
  137. $(this).addClass("current");
  138. // On click add the current tab image to the current tab
  139.  
  140. // Store the index of the clicked list item in a variable "href"
  141. var index = $(this).index() + 1;
  142.  
  143. // onClick find the panel with the id of #panel plus the number stored in the "index" variable
  144. $('#tabPanels').find('#panel' + index).addClass("currentP");
  145.  
  146. // prevent the original click event from happening
  147. e.preventDefault();
  148.  
  149. });
  150.  
  151. },
  152.  
  153.  
  154. /* Carousel Functionality */
  155. animateCarousel : function(direction, slideDuration){
  156.  
  157. if(homeFunc.counter >= 3){
  158.  
  159. homeFunc.counter = 0;
  160.  
  161. }else if(homeFunc.counter < 0){
  162.  
  163. homeFunc.counter = 3;
  164.  
  165. }
  166.  
  167. var $top = $('.top'),
  168. $middle = $('.middle'),
  169. $bottom = $('.bottom');
  170.  
  171. if (slideDuration !== undefined){
  172. slideDuration = 100;
  173. }
  174.  
  175. if(homeFunc.direction == 'next' || homeFunc.direction === undefined){
  176.  
  177. homeFunc.counter ++;
  178.  
  179. $('.top, #contentSliderStrap'+homeFunc.counter).animate({opacity: 0}, slideDuration, function() {
  180.  
  181. if(homeFunc.counter == 3){
  182.  
  183. $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap');
  184.  
  185. $('#contentSliderStrap1').addClass('currentStrap').animate({opacity: 1}, slideDuration);
  186.  
  187. }else {
  188.  
  189. $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap').next().addClass('currentStrap').animate({opacity: 1}, slideDuration, function() {});
  190.  
  191. }
  192.  
  193. $top.css({zIndex : 0, opacity: 1});
  194.  
  195. $top.removeClass('top').addClass('bottom');
  196.  
  197. $middle.css('z-index',2).addClass('top').removeClass('middle');
  198.  
  199. $bottom.css('z-index',1).addClass('middle').removeClass('bottom');
  200.  
  201. });
  202.  
  203. } else if(homeFunc.direction == 'prev'){
  204.  
  205. console.log(homeFunc.counter);
  206.  
  207. homeFunc.counter --;
  208.  
  209. if(homeFunc.counter == 0){
  210.  
  211. console.log(homeFunc.counter);
  212.  
  213. $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap');
  214.  
  215. $('#contentSliderStrap3').addClass('currentStrap').animate({opacity: 1}, slideDuration);
  216.  
  217. }else {
  218.  
  219. $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap').prev().addClass('currentStrap').animate({opacity: 1}, slideDuration, function() {});
  220.  
  221. }
  222.  
  223. $top.animate({ opacity: 0}, slideDuration, function() {
  224.  
  225. $top.css({zIndex : 0, opacity: 1});
  226.  
  227. $top.removeClass('top').addClass('bottom');
  228.  
  229. $middle.css('z-index',2).addClass('top').removeClass('middle');
  230.  
  231. $bottom.css('z-index',1).addClass('middle').removeClass('bottom');
  232.  
  233. });
  234.  
  235. }
  236. },
  237. }
  238.  
  239. $.fn.homeFunc = function( method ) {
  240.  
  241. // Method calling logic
  242. if ( homeFunc[method] ) {
  243. return homeFunc[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  244. } else if ( typeof method === 'object' || ! method ) {
  245. return homeFunc.init.apply( this, arguments );
  246. } else {
  247. $.error( 'Method ' + method + ' does not exist on jQuery.quizMethods' );
  248. }
  249.  
  250. };
  251.  
  252.  
  253. })( jQuery );
  254.  
  255. $('html').homeFunc();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement