/*SCROLLBAR*/

$(window).ready(function(){
	window.setInterval( function () { 
		$('.scrollContent').jScrollPane();
	},100);
});

$(function() {
	//btn-xbox
	setTimeout(function(){ 
	$('.btn').attr('title', 'Clique aqui para expandir');
     $('#btn_xbox').animate({
		width: '140'
	}, 'slow', function(){
		$('.descubra').css('display','none');
	});
  }, 5000 ); 
	
    //dropitens
    $('.btnDropOptions').click(function() {
      $('#boxDropDownList').slideToggle();
    });

	//Ficha-Tecnica / Itens de Serie
	sheetShowHide = function () {
      $('.sheetContent').toggle();
	}

    FB.init({
        appId  : '213742852030867',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        oauth  : true, // enable OAuth 2.0
        xfbml  : true  // parse XFBML
    });

    var btn = document.getElementById('btnLiveStream' );
    var fb_stream = document.getElementById('fbLiveStream');
    if ( btn && fb_stream ) {
        fb_stream.style.display = 'none';
        btn.onclick = function () {
            if ( fb_stream.style.display == 'none' ) {
                fb_stream.style.display = 'inline-block';
                } else {
                fb_stream.style.display = 'none';
            }
            return false;
        }
    }

});

var F_HIDECOLUMN = function ( col , table ) {
        col = ( isNaN( parseInt(col) ) ? 0 : parseInt( col ) );
        table = table || '.tbl-compare';
        F_SHOWCOLUMNS(table);
        $('td:nth-child(' + col + ')', table ).hide();
        $('th:nth-child(' + col + ')', table + ' .cars' ).hide();
        $('th:nth-child(' + ( col+1 ) + ')', table + ' .models' ).hide();
    },
    F_SCROLLMOVE = function ( e ) {

        var sT = 0;
        if ( typeof this.y !== S_UNDEFINED ) {
            sT = ( this.y * -1 );
        } else if ( typeof e.y !== S_UNDEFINED ) {
            sT = (e.y * -1 );
        } else if ( typeof e.target !== S_UNDEFINED ) {
            sT = e.target.scrollTop;
        }

        if ( sT > 85 ) {
            if ( Fiat.modal.isOpen('.modal.compare') && $('#modalFake').is(':hidden') ) {
                $('.modal.compare table').clone( true, true ).appendTo('#modalFake');
                $('#modalFake').show();
            }
        } else {
            if ( Fiat.modal.isOpen('.modal.compare') && $('#modalFake').is(':visible')) {
                $('#modalFake').empty().hide();
            }
        }

    },
    F_SHOWCOLUMNS = function (table) {
        table = table || '.tbl-compare';
        $('td,th', table ).show();
    },
    F_OPENPRIVACIDADE = function() {
        Fiat.modal.open ( Fiat.O_$.modal.politica.wrap );
    },
    F_OPENCOMPARE = function () {
        Fiat.modal.open( Fiat.O_$.modal.compare.wrap );

        $(window).scrollTop(0);
        $('.modal.compare *').clone( true, true ).appendTo('#modalFake');
        $('#modalFake').show();
        $('body').addClass('ovf-hidden');

        /* Resize */
        F_RESIZECOMPARE();

        /* Fecha compare no click */
        Fiat.bind( Fiat.modal.close , Fiat.O_$.modal.compare.wrap , S_CLICK , $('#modalFake .btn.close'), B_FALSE );
        Fiat.bind( function(){
            $('body').removeClass('ovf-hidden');
            $('#modalFake').empty().hide();
        } , null , S_CLICK , Fiat.O_$.modal.compare.btn.close , B_FALSE );

        /* Fecha ficha tecnica no click */
        Fiat.bind( F_OPENCOMPARE , '' , S_CLICK , Fiat.O_$.modal.sheet.btn.close , B_FALSE );
    },
    F_OPENFICHATECNICA = function (cod) {
        Fiat.$('.sheet-' + cod).click();
        Fiat.bind( Fiat.modal.close , '' , S_CLICK , Fiat.O_$.modal.sheet.btn.close , B_FALSE );
        _gaq.push(['_trackPageview','palio-2011-compare-conheca-a-versao-tela-carro-'+cod]);
    },
    F_LIKEBUTTON = function ( who , top , left ) {
        var btn = $('.fb-like').hide();
        if ( typeof who !== S_UNDEFINED && $.trim( who ) != '' ) {
            btn.filter('[id^=btn_like_'+who+']').css({top:top,left:left}).show();
        }
    },
    F_RESIZECOMPARE = function () {
        if ( Fiat.modal.isOpen('.modal.compare') ) {
            if ( Fiat.$w.width() < 1200 ) {
                F_HIDECOLUMN(7);
                $('#nextCar,#prevCar').show();
                Fiat.bind( F_HIDECOLUMN , 2 , S_CLICK , $('#nextCar') , B_FALSE );
                Fiat.bind( F_HIDECOLUMN , 7 , S_CLICK , $('#prevCar') , B_FALSE );
                Fiat.O_$.modal.compare.wrap.add('#modalFake').removeClass('full');
            } else {
                Fiat.O_$.modal.compare.wrap.add('#modalFake').addClass('full');
                F_SHOWCOLUMNS();
                $('#nextCar,#prevCar').hide();
            }
        }
    };

/* Abre compare no click (usado no botao de ficha tecnica) */
Fiat.bind( F_OPENCOMPARE , '' , S_CLICK , Fiat.O_$.modal.compare.btn.open , B_FALSE );

/* Carrega compare no load */
Fiat.bind( Fiat.compare.get , '' , S_LOAD , Fiat.w , B_TRUE );

/* Abre politica no click */
Fiat.bind( Fiat.modal.open , Fiat.O_$.modal.politica.wrap , S_CLICK , Fiat.O_$.modal.politica.btn.open , B_FALSE );

/* Fecha politica no click */
Fiat.bind( Fiat.modal.close , Fiat.O_$.modal.politica.wrap , S_CLICK , Fiat.O_$.modal.politica.btn.close , B_FALSE );

/* Resize compare */
Fiat.bind( F_RESIZECOMPARE , '' , S_RESIZE , Fiat.w , B_TRUE );

/* SCROLL Compare */
//Fiat.O_$.modal.compare.wrap.scroll(F_SCROLLMOVE);
//Fiat.bind( F_SCROLLMOVE , Fiat.O_$.modal.compare.wrap , S_SCROLL , Fiat.O_$.modal.compare.wrap , B_TRUE );


// XBOX
$('.btn').toggle(
  function () {
	$('.btn').attr('title', 'Clique aqui para reduzir');
	$('#btn_xbox').animate({
		width: '601'
	}, 'slow', function(){
		$('.descubra').fadeIn();
	});
  },
  function () {
	$('.btn').attr('title', 'Clique aqui para expandir');
    $('#btn_xbox').animate({
		width: '140'
	}, 'slow', function(){
		$('.descubra').css('display','none');
	});
  }
);
/*
$('.descubra').toggle(
  function () {
	$('#gallery').animate({
		height: '427'
	}, 'slow', function(){
		$('#wrapper').animate({
			height:401
		}, 'slow');
		$('#btn_xbox').animate({
			top:100
		}, 'slow');
	});
  },
  function(){
	$('#wrapper').animate({
			height:861
	}, 'slow', function () {
    $('#gallery').animate({
		height: '0'
	}, 'slow');
	$('#btn_xbox').animate({
			top:475
		}, 'slow');
	});
  }
);
*/
