$(document).ready(function () {
	changeStorePic();
	focusItem('.store_small_pic a');
	$(".home_shoplist").mouseenter(function(){
		$("a.browse").fadeIn();
	});
	$(".home_shoplist").mouseleave(function(){
		$("a.browse").fadeOut();
	});

    $('.event_image img').reflect({ opacity: 0.4,height: 0.2 });

	$("#tagContent").find(".story_body:visible").jScrollPane();
	$(".store_description,.stores_list,.event_wrap").jScrollPane();
	$('.title_pop a,.event_items_wrap a.imagecache').each(function(){var href=$(this).attr('href');$(this).attr('href',href+'?iframe=true&full=false');});
	$('.title_pop a,.newspop,.event_items_wrap a.imagecache').prettyPhoto({animationSpeed:'slow',theme:'light_square', opacity:0.5,show_title:false,default_width: 866,default_height:600});
	$('a.store_map').prettyPhoto({animationSpeed:'slow',theme:'light_square', opacity:0.7,show_title:false,default_width:900,default_height:600});
	$(".map1_wrap .viewport").mapbox({
		mousewheel: true,
		doubleClickZoom: true,
		layerSplit:1
	});
	$(".map2_wrap .viewport").mapbox({
		mousewheel: true,
		doubleClickZoom: true,
		defaultY: -245,
		defaultX: -115,
		layerSplit:1
	});

	
	var sliderIndex = 1;
	$(".slideshowWrap").click(function(){
		var index = $('.slideshowWrap').index($(this));
		sliderIndex = index+1;
		$(".slideshowWrap .slideshowPic").stop().animate({
			width: 0
		},500);
		$(".slideshowWrap").stop().animate({
			width: 35
		},500);
		$(".slideshowWrap").removeClass("active");
		$(this).addClass("active");
		$(".slideshowDescription").animate({bottom: -150},400);
		
		$(this).stop().animate({
			width: "771"
		},600);
		$(this).find('.slideshowPic').stop().animate({
			width: "736px",
			opacity: "1"
		},600, function(){
			$(this).find(".slideshowDescription").animate({bottom:0,opacity:1},500);
			
		});
	});
	
	$('.stores_list .store_item,.hot_stores .store_item,.home_shoplist .store_item,.home_shoplist .store_item').mouseenter(function()
	{
		var height = $(this).find('.store_title').height();
		$(this).find('.store_image').stop().animate({'top':-height},230);
	});
	
	$('.stores_list .store_item,.hot_stores .store_item,.home_shoplist .store_item,.home_shoplist .store_item').mouseleave(function()
	{
		$(this).find('.store_image').stop().animate({'top':0},230);
	});
	
	$('.event_item').mouseenter(function()
	{
		var height = $(this).find('.title_pop').height();
		$(this).find('.event_image').stop().animate({'top':height},230);
	});
	
	$('.event_item').mouseleave(function()
	{
		$(this).find('.event_image').stop().animate({'top':0},230);
	});
	
	function switchSlider(){
		$('.slideshowWrap').eq(sliderIndex).click();
		sliderIndex ++;
		if(sliderIndex > 4)
			sliderIndex = 0;
	}
	
	sliderTime = setInterval(switchSlider,4000);
	
	$('.homeSlideshow').mouseout(function(){
		sliderTime = setInterval(switchSlider,4000);
	});
	$('.homeSlideshow').mouseover(function(){
		clearInterval(sliderTime);
	});
	

	
	$('.search_wrap a').attr('target','_blank');
	
	$(".slideshowWrap").mouseover(function(){
		if($(this)[0].clientWidth < 30)
		{
			$(this).addClass('active');
		}
	});
	
	$(".slideshowWrap").mouseout(function(){
		if($(this)[0].clientWidth < 30)
		{
			$(this).removeClass('active');
		}		   
	});
	
	$("#wheeled").scrollable({circular: true}).autoscroll({ autoplay: true , steps: 4, interval:5000});

});

function closeStoreInfo(){
	$('.homeStoreInfoWrap').stop().animate({opacity:0},500);
	$('.homeSlideshow').css({display:'block',opacity:0}).stop().animate({opacity:1},500);
}

function changeStorePic(){
	var list = $('.store_small_pic a');
	var containers = $('.store_big_pic');
	//containers.eq(0).css({'z-index':999,'opacity':1});
	list.click(function(){
		var index = list.index(this);
		var containers = $('.store_big_pic');
		var offsetLeft = containers.eq(index)[0].offsetLeft;
		//containers.animate({'opacity':1});
		//containers.fadeOut();
		$('.store_big_pic_list_wrap').animate({'margin-left':-offsetLeft});
		return false;
	});
}

function focusItem(itemId){
	items = $(itemId);
	items.mouseenter(function() {
        $(this).addClass('active');
        var worksList = $(itemId + ':not(.active)');
        worksList.stop().animate({ opacity: 0.6 }, 300);
        $(this).removeClass('active');
        $(this).stop().animate({ opacity: 1.0 }, 300);
    });
	$(itemId).mouseleave(function() {
		$(itemId).stop().animate({ opacity: 1.0 }, 300);
    });
}

function change3DMap(){
	var list = $('.map1_nav a');
	list.click(function(){
		list.removeClass('active');
		var index = list.index(this);
		var containers = $('.map1_wrap_wide .viewport');
		var offsetLeft = containers.eq(index)[0].offsetLeft;
		$('.map1_wrap_wide').animate({'margin-left':-offsetLeft});
		$(this).addClass('active');
		$(".viewport").mapbox('back',2);
		return false;
	});
}

