// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var $j = jQuery.noConflict();

$j(document).ready(function() {

  $j('body').css('overflow-x', 'hidden');

	$j('#header-about-nav').mouseover(function() {
		$j(this).attr('src', '/images/spadeNavSelected.png');
	});
	$j('#header-about-nav').mouseout(function() {
		$j(this).attr('src', '/images/spadeNav.png');
	});
	$j('#header-blog-nav').mouseover(function() {
		$j(this).attr('src', '/images/heartNavSelected.png');
	});
	$j('#header-blog-nav').mouseout(function() {
		$j(this).attr('src', '/images/heartNav.png');
	});
	$j('#header-gamers-nav').mouseover(function() {
		$j(this).attr('src', '/images/diamondNavSelected.png');
	});
	$j('#header-gamers-nav').mouseout(function() {
		$j(this).attr('src', '/images/diamondNav.png');
	});
	$j('#header-leaderboards-nav').mouseover(function() {
		$j(this).attr('src', '/images/clubNavSelected.png');
	});
	$j('#header-leaderboards-nav').mouseout(function() {
		$j(this).attr('src', '/images/clubNav.png');
	});

	if(null != document.getElementById('username') && null != document.getElementById('password')) {
    // Adding functionality to clear username login field on click
    $j('#username').focus(function() {
      if (this.value == 'Username') {
        this.value = '';
      }
    }).blur(function() {
      if (this.value == '') {
        this.value = '';
      }
    });

    // Adding functionality to clear Password login field on click
    $j('#password').focus(function() {
      if (this.value == 'Password') {
        this.value = '';
      }
    }).blur(function() {
      if (this.value == '') {
        this.value = '';
      }
    });

    $j('#username, #password').keypress(function(event) {
		  if (event.which == 13) {
		    document.getElementById('login_form').submit();
		    return false;
		  }
		});
  }

	$j('#search').focus(function() {
		if(this.value == 'Search'){
			this.value = '';
		}
	}).blur(function() {
		if(this.value == '') {
			this.value = '';
		}
	});

  if ($j('body#about.index').length) {
		var fade_timer = 2000;
    var $screen_shots = $j('.screen_shot');
        $screen_shots.hide();
    var $current = $screen_shots.filter(':first');
        $current.show();
    var $next = $current.next();
    var rotator_interval = setInterval(function() {
      $current.fadeOut(fade_timer);
      $next.fadeIn(fade_timer);
      $current = $next;
      $next = $current.next()
      if (!$next.find('.screen_image').length)
        $next = $screen_shots.filter(':first');
    }, 7000);
	};
	
	if ($j('body#about.tutorial').length) {
		var image_index = 0;
    var $instruction_shots = $j('.instruction_shot');
        $instruction_shots.hide();
    var $current = $instruction_shots.filter(':first');
        $current.show();
		$j('.previous').hide();
		$j('.instruction_shot').each(function(idx) {
      $j(this).attr('idx', idx);
    });
		$j('.previous').click(function() {
			if(image_index != 0){
	    	$instruction_shots.hide();
				image_index = image_index - 1;
				if(image_index == 0){
		    	$j(".previous").hide();	
				}
				else if(image_index == 21){
			    $j(".next").show();
				}
		    $j(".instruction_shot[idx='" + image_index + "']").show();
			}
	    return false;
    });
		$j('.next').click(function() {
			if(image_index != 22){
	    	$instruction_shots.hide();
				image_index = image_index + 1;
				if(image_index == 22){
		    	$j(".next").hide();	
				}
				else if(image_index == 1){
			    $j(".previous").show();
				}
	    	$j(".instruction_shot[idx='" + image_index + "']").show();
			}
	    return false;
    });
	};

});