﻿// JScript File

var carouselContainer;
var carouselContents;
var btScrollRightButton1;
var btScrollLeftButton1;
var carouselScroller;
var isInitCarousel = false;
var isRightActive1 = false;
var isLeftActive1 = false;
var carouselContainerWidth = 0; 
var carouselContentWidth = 0;
var aCoOrdinates = [0,0];
var iCarouselItemWidth = 104;

function initCarousel()
{
    carouselContainer = document.getElementById('divCarouselContentHolder');
    carouselContents = document.getElementById('divCarouselItems');
    carouselScroller = document.getElementById('divCarouselScroller');

    btScrollRightButton1 = document.getElementById('imgScrollRight');
    btScrollLeftButton1 = document.getElementById('imgScrollLeft');
    isInitCarousel = true;
    CheckScrollButtons1();
}
function CheckScrollLeftButton1()
{
    var blEnableScroll = EnableScrollLeftButton1();
    if (blEnableScroll && !isLeftActive1)
    {
        if (btScrollLeftButton1.addEventListener) {
        btScrollLeftButton1.addEventListener ("mouseover",ScrollLeftButtonOver1,false);
        btScrollLeftButton1.addEventListener ("mouseout",ScrollLeftButtonOut1,false);
        btScrollLeftButton1.addEventListener ("click",ScrollLeftButtonClick1,false);
        } else if (btScrollLeftButton1.attachEvent) {
        btScrollLeftButton1.attachEvent ("onmouseover",ScrollLeftButtonOver1);
        btScrollLeftButton1.attachEvent ("onmouseout",ScrollLeftButtonOut1);
        btScrollLeftButton1.attachEvent ("onclick",ScrollLeftButtonClick1);
        } else {
        btScrollLeftButton1.onmouseover = ScrollLeftButtonOver1;
        btScrollLeftButton1.onmouseout = ScrollLeftButtonOut1;
        btScrollLeftButton1.onclick = ScrollLeftButtonClick1;
        } 
        btScrollLeftButton1.src = 'images/button_left_active.gif';
        btScrollLeftButton1.style.cursor = 'pointer';
        isLeftActive1 = true;
        return;
    }
    if (!blEnableScroll && isLeftActive1)
    {
        if (btScrollLeftButton1.addEventListener) {
        btScrollLeftButton1.removeEventListener ("mouseover",ScrollLeftButtonOver1,false);
        btScrollLeftButton1.removeEventListener ("mouseout",ScrollLeftButtonOut1,false);
        btScrollLeftButton1.removeEventListener ("click",ScrollLeftButtonClick1,false);
        } else if (btScrollLeftButton1.attachEvent) {
        btScrollLeftButton1.detachEvent ("onmouseover",ScrollLeftButtonOver1);
        btScrollLeftButton1.detachEvent ("onmouseout",ScrollLeftButtonOut1);
        btScrollLeftButton1.detachEvent ("onclick",ScrollLeftButtonClick1);
        } else {
        btScrollLeftButton1.onmouseover = null;
        btScrollLeftButton1.onmouseout = null;
        btScrollLeftButton1.onclick = null
        } 
        btScrollLeftButton1.src = 'images/button_left_inactive.gif';
        btScrollLeftButton1.style.cursor = 'default';
        isLeftActive1 = false;
    }
}

function ScrollLeftButtonOver1()
{
        btScrollLeftButton1.src='http://assets.play.it/images/button_left_hover.gif';
}
function ScrollLeftButtonOut1()
{
        btScrollLeftButton1.src='http://assets.play.it/images/button_left_active.gif';
}
function ScrollLeftButtonClick1()
{
        scrollCarouselContents('divCarouselScroller', 'Right', iCarouselItemWidth, FindMeContentWidth1);
}

function CheckScrollRightButton1()
{
   var blEnableScroll = EnableScrollRightButton1();
   if (blEnableScroll && !isRightActive1)
    {
        if (btScrollRightButton1.addEventListener) {
        btScrollRightButton1.addEventListener ("mouseover",ScrollRightButtonOver1,false);
        btScrollRightButton1.addEventListener ("mouseout",ScrollRightButtonOut1,false);
        btScrollRightButton1.addEventListener ("click",ScrollRightButtonClick1,false);
        } else if (btScrollRightButton1.attachEvent) {
        btScrollRightButton1.attachEvent ("onmouseover",ScrollRightButtonOver1);
        btScrollRightButton1.attachEvent ("onmouseout",ScrollRightButtonOut1);
        btScrollRightButton1.attachEvent ("onclick",ScrollRightButtonClick1);
        } else {
        btScrollRightButton1.onmouseover = ScrollRightButtonOver1;
        btScrollRightButton1.onmouseout = ScrollRightButtonOut1;
        btScrollRightButton1.onclick = ScrollRightButtonClick1;
        } 
        btScrollRightButton1.src = 'images/button_right_active.gif';
        btScrollRightButton1.style.cursor = 'pointer';
        isRightActive1 = true;
        return;
    }
    if(!blEnableScroll && isRightActive1)
    {
        if (btScrollRightButton1.addEventListener) {
        btScrollRightButton1.removeEventListener ("mouseover",ScrollRightButtonOver1,false);
        btScrollRightButton1.removeEventListener ("mouseout",ScrollRightButtonOut1,false);
        btScrollRightButton1.removeEventListener ("click",ScrollRightButtonClick1,false);
        } else if (btScrollRightButton1.attachEvent) {
        btScrollRightButton1.detachEvent ("onmouseover",ScrollRightButtonOver1);
        btScrollRightButton1.detachEvent ("onmouseout",ScrollRightButtonOut1);
        btScrollRightButton1.detachEvent ("onclick",ScrollRightButtonClick1);
        } else {
        btScrollRightButton1.onmouseover = null;
        btScrollRightButton1.onmouseout = null;
        btScrollRightButton1.onclick = null;
        } 
        btScrollRightButton1.style.cursor = 'default';
        btScrollRightButton1.src = 'images/button_right_inactive.gif';
        isRightActive1 = false;
    }
}

function ScrollRightButtonOver1()
{
        btScrollRightButton1.src='http://assets.play.it/images/button_right_hover.gif';
}
function ScrollRightButtonOut1()
{
        btScrollRightButton1.src='http://assets.play.it/images/button_right_active.gif';
}
function ScrollRightButtonClick1()
{
        scrollCarouselContents('divCarouselScroller','Left',iCarouselItemWidth ,FindMeContentWidth1);
}

function EnableScrollRightButton1()
{    
    if (carouselContainerWidth < FindMeContentWidth1 && (FindMeContentWidth1 + Number(carouselScroller.style.left.replace("px","")) > carouselContainerWidth))
    {
        return true;
    }
    return false;
}

function EnableScrollLeftButton1()
{
    if (carouselContainerWidth < FindMeContentWidth1 && (Number(carouselScroller.style.left.replace("px","")) < 0))
    {
        return true;
    }
    return false;
}
function CheckScrollButtons1()
{
    if(!isInitCarousel)
    {
        initCarousel();
    }
    if(carouselContainer != null)
    {
        carouselContainerWidth = carouselContainer.offsetWidth;
        FindMeContentWidth1 = carouselContents.offsetWidth;
        CheckScrollRightButton1();
        CheckScrollLeftButton1();
    }
}
function scrollCarouselContents(ElementID,Direction,Pixels,MaxScroll)
{
        var Element = document.getElementById(ElementID);
        
        switch (Direction.toLowerCase())
            {
            case 'up':
                aCoOrdinates[1] = aCoOrdinates[1] + Pixels;
	            Element.style.top = aCoOrdinates[1] + 'px';
                break;
            case 'right':
                if(aCoOrdinates[0] < 0)
                {
                    aCoOrdinates[0] =  aCoOrdinates[0] + Pixels;
	                Element.style.left = aCoOrdinates[0] + 'px';
	            }
	            else
	            {
	            }
                break;
            case 'down':
                aCoOrdinates[1] = aCoOrdinates[1] - Pixels;
	            Element.style.top = aCoOrdinates[1] + 'px';
                break;
            case 'left':
                if(aCoOrdinates[0] > MaxScroll * -1)
                {
                    aCoOrdinates[0] =  aCoOrdinates[0] - Pixels;
	                Element.style.left = aCoOrdinates[0] + 'px';
	            }
	            else
	            {
	            }
                break;
             }
             if(carouselContainer != null)
             {
                CheckScrollButtons1();
             }
}