function mycarousel_initCallback(carousel){
    carousel.buttonNext.bind('click', function() {carousel.startAuto(0);});
    carousel.buttonPrev.bind('click', function() {carousel.startAuto(0);});
    carousel.clip.hover(function() {carousel.stopAuto();},function() {carousel.startAuto();});
};
function box_lojas_novas_callback(carousel,litem){
	$('#box_lojas_novas_alt').text($(litem).find('img').attr('alt'));
}
jQuery(document).ready(function($) {
//$(document).ready(function(){
    $('#videos').youTubeChannel({ 
		loadingText		: 'Carregando',
		userName		: 'riopretoshopping',
		lastVideo		: true,
		width			: 250,
		height			: 200
	});
    $('#cinema ul').jcarousel({
        auto: 1,
        wrap: 'both',
		animation: 'slow',
		scroll: 1,
        initCallback: mycarousel_initCallback
    });
	$('#fotos ul').jcarousel({
		auto: 3,
        wrap: 'both',
		animation: 'slow',
		scroll: 1,
        initCallback: mycarousel_initCallback
    });
	$('#novidades ul').jcarousel({
		auto: 3,
        wrap: 'both',
		animation: 'slow',
		scroll: 1,
        initCallback: mycarousel_initCallback
    });
	$('#box_ingressos ul').jcarousel({
		auto: 3,
        wrap: 'both',
		animation: 'slow',
		scroll: 1,
        initCallback: mycarousel_initCallback
    });
	$('#box_lojas_novas ul').jcarousel({
        wrap: 'both',
		auto:3,
		animation: 'slow',
		scroll: 1,
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: box_lojas_novas_callback
    });
	$('div.lista_horarios a.detalhe,#detalhe_filme').fancybox({
		'type'			: 'iframe',
		'padding'       : 25,
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'width'			: 720,
		'height'		: '80%'
	});
	$("#valores_cinema").fancybox({
		'padding'       :25,
		'titleShow'		: false,
		'autoScale'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	$("#myFotos a.banner_camp,#fotos a,a.fancybox").fancybox({
		'padding'       :10,
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	$('#flash_cinema').flash({
		swf			: 'swf/carousel.swf',
		id			: 'movie-carousel',
		wmode		: 'transparent',
		width		: 960,
		height		: 294
	});
	if($('#map_canvas').val() != undefined){
		initialize();
	}
	$('#flash_cinema').css({'margin':'auto','position':'relative','width':'960px'})
	$(".lista_outrosfilmes").find('a').each(function(){
		$(this).click(
			function(){
				//var app = 
				MovieID = $(this).attr('id').replace('movie_list_id_','')
				//alert($($('#movie-carousel')[0]).attr('id'));
				$('#movie-carousel')[0].SelectMovie(MovieID);
				return false;
			}
		);
	});
	$("#twitter_updates").getTwitter({
		userName: "riopshopping",
		numTweets: 5,
		loaderText: "Carregando tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: true,
		headingText: "Últimos Tweets",
		showProfileLink: true,
		showTimestamp: true
	});
	
	//=======================================================
	//------------Troca banner topo inicial------------------
	var imgc = $('.banners ul li');
		if(imgc.length){ fadeSlideshow(imgc,7000,1000);	
	}
	
	//=======================================================
	$('#search_term').autocomplete('ajax_search.asp');
	
	/*
	var url=window.location; //if you need to take the current url of the window use: var url=window.location;
	var anchor=url.hash; //anchor with the # character
	var anchor2=url.hash.substring(1); //anchor without the # character
	if(anchor2 != ''){
		alert($('#movie-carousel'));
		var app = $('#movie-carousel').SelectMovie(anchor2);
	}*/
	//getMovieInfo(1);
});
function getMovieInfo(id){
	if(id > 0){
		var MovieInfo = $('#MovieInfo').val();
		if(MovieInfo != undefined){
			Ids = MovieInfo.split(',');		
			$('.lista_horarios').hide().load('cinema.html.asp?id='+Ids[id]).slideDown(function(){
				$('#info_filme').fadeIn();
				$('div.lista_horarios a.detalhe,#detalhe_filme').fancybox({
					'type'			: 'iframe',
					'padding'       : 25,
					'titleShow'		: false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'width'			: 720,
					'height'		: '80%'
				});
			});	
			$('#detalhe_filme').attr('href','cinema_detalhe.asp?id='+Ids[id]);
		}	
	}
	//$('#MovieInfo').val(id);
}
//	GOOGLE MAPS
var map;
var geocoder;
function initialize() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_canvas"));
	var point = new GLatLng(-20.83492873614112, -49.39859747886658);
	map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
	map.setCenter(point, 15);
	map.addOverlay(new GMarker(point));
	map.openInfoWindow(map.getCenter(),"<div class='gmapinfowindow'><p><b>Riopreto Shopping Center</b><br />Av. Brig. Faria Lima, 6363<br /> Bairro: Jardim Morumbi<br />São José do Rio Preto, SP</p></div>");
  }
}
function fadeSlideshow(el,duration,speed,current){
	var listSize = el.length;
	$(el).css('z-index',0);
	if (!current || current >= listSize){
		current = 0;
	}
	$(el[current+1]).css('z-index',1001).show();
	$(el[current]).css('z-index',2002).fadeOut(speed,function(){
		window.setTimeout(function(){
			fadeSlideshow(el,duration,speed,current+1);
			if (!current || current >= listSize-1){
				$(el[0]).show();
			}
		},duration);
	});
}
