﻿/* Script Slider */

var up = false;
var down = false;

$(document).ready(function(){
        
    if ($('#cidades-turisticas #slider ul').css('margin-top').replace('px', '') == 0)
    {
        habilitaBtnCT(false, true);    
    }
    
    //Se existir somente um grupo de Li's
    if ($('#cidades-turisticas #slider ul li').length == 1)
    {
         habilitaBtnCT(false, false);
    }
    
    $('#cidades-turisticas #slider .up').click(function(){
    
        $(this).attr('disabled', 'disabled');
        
        if (up == false)
        {
            up = true;
            
            if ( $('#cidades-turisticas #slider ul').css('margin-top').replace('px', '') >  ( -($('#cidades-turisticas #slider ul li').length - 1) * 250))
            {
                upDownSlide('-=' + 270);   
            }
        }
        
    }); 
    
    $('#cidades-turisticas #slider .down').click(function(){
    
        $(this).attr('disabled', 'disabled');
        
        if (down == false)
        {
            down = true;
        
            if ($('#cidades-turisticas #slider ul').css('margin-top').replace('px', '') != 0)
            {
                upDownSlide('+=' + 270);  
            } 
        }
    });  
      
});

function upDownSlide(valor)
{      
    if ($('#cidades-turisticas #slider ul').css('margin-top').replace('px', '') == 0)
    {
        habilitaBtnCT(false, null); 
    }  
        
    if (valor.indexOf('-') != -1)
    {
        habilitaBtnCT(true, null);
        
        if( $('#cidades-turisticas #slider ul').css('margin-top').replace('px', '')  == (-(($('#cidades-turisticas #slider ul li').length - 2) * 250)))
        {
            habilitaBtnCT(true, false); 
        }        
    
        $('#cidades-turisticas #slider ul').animate({'marginTop': '+=20'}, function(){
            $('#cidades-turisticas #slider ul').animate({'marginTop': valor}, function(){
                $('#cidades-turisticas #slider .btn').children('div').removeAttr('disabled');
                up = false;
                down = false;
            });
        });   
    }
    else
    {
        habilitaBtnCT(null, true);
        
        if ((parseInt($('#cidades-turisticas #slider ul').css('margin-top').replace('px', '')) + 250) == 0)
        {
            habilitaBtnCT(false, null);
        }
    
        $('#cidades-turisticas #slider ul').animate({'marginTop': '-=20'}, function(){
            $('#cidades-turisticas #slider ul').animate({'marginTop': valor}, function(){
                $('#cidades-turisticas #slider .btn').children('div').removeAttr('disabled');
                down = false;
                up = false;
            });
        }); 
    }
}

function habilitaBtnCT(down, up)
{
    if (down != null)
    {
        if (down == true ) {
            $('#cidades-turisticas #slider .down').parent('div').attr('class', 'btn ativo');
        } else {
            $('#cidades-turisticas #slider .down').parent('div').attr('class', 'btn inativo');
        }
    }
    
    if (up != null)
    {
        if (up == true) {
            $('#cidades-turisticas #slider .up').parent('div').attr('class', 'btn ativo');
        } else {
            $('#cidades-turisticas #slider .up').parent('div').attr('class', 'btn inativo');
        }
    }
}
