﻿
var IntervalID = 0;

var Stories;
var StoriesPosition;
var StoriesHeight;

var FeaturedGames;
var FeaturedGamesPosition;
var FeaturedGamesHeight;

var NewestGames;
var NewestGamesPosition;
var NewestGamesHeight;

var HighestRated;
var HighestRatedPosition;
var HighestRatedHeight;

$(document).ready(function() {

    Stories = $("#HomeLatestNews .Stories");
    StoriesPosition = 0;
    
    FeaturedGames = $("#HomeFeaturedGames .Games");
    FeaturedGamesPosition = 0;
    
    NewestGames = $("#HomeNewestGames .Games");
    NewestGamesPosition = 0;
    
    HighestRated = $("#HomeHighestRated .Games");
    HighestRatedPosition = 0;

    /* Latest News Buttons */
    
    $("#HomeLatestNews .Down").mousedown(function(){IntervalID = setInterval('LatestNewsDown()',1);});
    $("#HomeLatestNews .Down").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeLatestNews .Down").mouseout(function(){clearInterval(IntervalID);});
    $("#HomeLatestNews .Up").mousedown(function(){IntervalID = setInterval('LatestNewsUp()',1);});
    $("#HomeLatestNews .Up").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeLatestNews .Up").mouseout(function(){clearInterval(IntervalID);});
    
    /* Featured Games Buttons */
    
    $("#HomeFeaturedGames .Down").mousedown(function(){IntervalID = setInterval('FeaturedGamesDown()',1);});
    $("#HomeFeaturedGames .Down").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeFeaturedGames .Down").mouseout(function(){clearInterval(IntervalID);});
    $("#HomeFeaturedGames .Up").mousedown(function(){IntervalID = setInterval('FeaturedGamesUp()',1);});
    $("#HomeFeaturedGames .Up").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeFeaturedGames .Up").mouseout(function(){clearInterval(IntervalID);});
    
    /* Featured Games Buttons */
    
    $("#HomeNewestGames .Down").mousedown(function(){IntervalID = setInterval('NewestGamesDown()',1);});
    $("#HomeNewestGames .Down").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeNewestGames .Down").mouseout(function(){clearInterval(IntervalID);});
    $("#HomeNewestGames .Up").mousedown(function(){IntervalID = setInterval('NewestGamesUp()',1);});
    $("#HomeNewestGames .Up").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeNewestGames .Up").mouseout(function(){clearInterval(IntervalID);});
    
    /* Highest Rated Buttons */
    
    $("#HomeHighestRated .Down").mousedown(function(){IntervalID = setInterval('HighestRatedDown()',1);});
    $("#HomeHighestRated .Down").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeHighestRated .Down").mouseout(function(){clearInterval(IntervalID);});
    $("#HomeHighestRated .Up").mousedown(function(){IntervalID = setInterval('HighestRatedUp()',1);});
    $("#HomeHighestRated .Up").mouseup(function(){clearInterval(IntervalID);});
    $("#HomeHighestRated .Up").mouseout(function(){clearInterval(IntervalID);});
    
    /* Carousel up and down buttons */
    
    $(".HomeCarousel .Up, .HomeCarousel .Down").hover(
      function () {
        $(this).parent().removeClass().addClass("ArrowsHover");
      }, 
      function () {
        $(this).parent().removeClass().addClass("Arrows");
      }
    );


    /* Add hovers to home page carousels */
    
    $(".HomeGames .Game").hover(
      function () {
        $(this).addClass("GameHover");
        $(this).find(".Play").removeClass().addClass("PlayHover");
      }, 
      function () {
        $(this).removeClass("GameHover");
        $(this).find(".PlayHover").removeClass().addClass("Play");
      }
    );
    
        	    
});

/* Latest News Animations */

function LatestNewsDown(){
    StoriesHeight = Stories.height();
    StoriesPosition = parseInt(Stories.css("top"));
    if (StoriesPosition + StoriesHeight - 433 > 0){
        StoriesPosition = StoriesPosition -5;
        Stories.css("top", StoriesPosition +"px");
    }
}

function LatestNewsUp(){
    StoriesPosition = parseInt(Stories.css("top"));
    if (StoriesPosition < 0){
        StoriesPosition = StoriesPosition +5;
        Stories.css("top", StoriesPosition +"px");
    }
}

/* Featured Games Animations */

function FeaturedGamesDown(){
    FeaturedGamesHeight = FeaturedGames.height();
    FeaturedGamesPosition = parseInt(FeaturedGames.css("top"));
    if (FeaturedGamesPosition + FeaturedGamesHeight - 433 > 0){
        FeaturedGamesPosition = FeaturedGamesPosition -5;
        FeaturedGames.css("top", FeaturedGamesPosition +"px");
    }
}

function FeaturedGamesUp(){
    FeaturedGamesPosition = parseInt(FeaturedGames.css("top"));
    if (FeaturedGamesPosition < 0){
        FeaturedGamesPosition = FeaturedGamesPosition +5;
        FeaturedGames.css("top", FeaturedGamesPosition +"px");
    }
}

/* Newest Games Animations */

function NewestGamesDown(){
    NewestGamesHeight = NewestGames.height();
    NewestGamesPosition = parseInt(NewestGames.css("top"));
    if (NewestGamesPosition + NewestGamesHeight - 433 > 0){
        NewestGamesPosition = NewestGamesPosition -5;
        NewestGames.css("top", NewestGamesPosition +"px");
    }
}

function NewestGamesUp(){
    NewestGamesPosition = parseInt(NewestGames.css("top"));
    if (NewestGamesPosition < 0){
        NewestGamesPosition = NewestGamesPosition +5;
        NewestGames.css("top", NewestGamesPosition +"px");
    }
}

/* Highest RatedAnimations */

function HighestRatedDown(){
    HighestRatedHeight = HighestRated.height();
    HighestRatedPosition = parseInt(HighestRated.css("top"));
    if (HighestRatedPosition + HighestRatedHeight - 433 > 0){
        HighestRatedPosition = HighestRatedPosition -5;
        HighestRated.css("top", HighestRatedPosition +"px");
    }
}

function HighestRatedUp(){
    HighestRatedPosition = parseInt(HighestRated.css("top"));
    if (HighestRatedPosition < 0){
        HighestRatedPosition = HighestRatedPosition +5;
        HighestRated.css("top", HighestRatedPosition +"px");
    }
}