﻿var VitrineCount = 5;

$(document).ready(function(){
 $('#temporaryShowCase').hide();
 $('#showCase').show();
 
 $('#mycarousel').jcarousel({
 scroll: 1,
 itemVisibleInCallback: itemVisibleInHandler,
 itemVisibleOutCallback: itemVisibleOutHandler,
 initCallback: mycarousel_initCallback,
 buttonNextHTML: null,
 buttonPrevHTML: null,
 animation: 0,
 auto: 7
 });
});


function itemVisibleInHandler(carousel,item,pos) 
{ 
 $('.jcarousel-control a').css('background-color','transparent');
 $('#control' + (pos -1)).css('background-color','#FF0000');
 
 var imgId = $('.jcarousel-item[jcarouselindex='+pos+']')
 if (imgId)
 {
 if (!imgId[0].firstChild) 
 return;
 
 imgId = imgId[0].firstChild.firstChild.id;
 if (imgId) 
 getDescription(imgId.replace('newsBoxId',''));
 else
 getDescription(item.value);

 $('#' + imgId).hide();
 $(item).css('visibility', 'visible'); 
 $('#' + imgId).hide();
 
 //var time = 2500;//2500
 //if (pos == 5) time = 5000;
 
 $('#' + imgId).fadeIn(600, function(){
 if (pos == VitrineCount) 
 {
 $(this).delay(7000,function(){
 carousel.scroll(1); 
 }); 
 } 
 });
 
 /*$('#' + imgId).fadeIn(time, function(){
 $(this).delay(3000,function(){
 $('.description').html('');
 $('#' + imgId).fadeOut(2500);
 }); 
 
 if (pos == 5) carousel.scroll(1); 
 });*/
 }
} 

function getDescription(bannerId)
{
 var description = $('#description' + bannerId).html();
 var title = $('#title' + bannerId).html();
 $('.description').html(description);
 $('.title').html(title);

 
 /*$.ajax({
 url: ApplicationPath + "Home/GetBannerDescription",
 data: {
 bannerId: bannerId
 },
 type: "POST",
 dataType:"json",
 error: function(result, text)
 {
 $('.description').html('');
 $('.title').html('');
 },
 success: function(result, success)
 {
 
 $('.description').html(result[0].Description);
 $('.title').html(result[0].Title);
 }
 });*/
}

function itemVisibleOutHandler(carousel,item,pos) 
{ 
 $(item).css('visibility', 'hidden'); 
} 

function mycarousel_initCallback(carousel) {
 jQuery('.jcarousel-control a').bind('click', function() {
 var time = carousel.timer;
 var position = this.id.replace('control','');
 position = parseInt(position) + 1;
 //clearTimeout(carousel.timer);
 carousel.options.auto = 0;
 //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
 carousel.scroll(jQuery.jcarousel.intval(position));
 //carousel.startAuto();
 //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
 //carousel.startAuto();
 carousel.options.auto = 10;
 carousel.startAuto();
 
 return false;
 });
};

 
