

var defEasing = "easeOutQuad";


$(document).ready(function(){
	
	var currInfo = $("#ProShowInfoBox");
	var targetContentDiv = $("#ProShowInfoBox1");
	
	$(currInfo).find(".proShowName").html($(targetContentDiv).find(".proShowName").html());
	$(currInfo).find(".proShowSpot").html($(targetContentDiv).find(".proShowSpot").html());
	$(currInfo).find(".proShowText").html($(targetContentDiv).find(".proShowText").html());
	
	$("#ProShowScrollRight").bind('mouseup', function(){
	
		
		if($(".horizontalScrollWrapper").not(':animated') && $(".active").index()+1<$(".proShowItem").length)
		{
			$(".horizontalScrollWrapper").animate({
				left:'-=240px'
			},500, defEasing);
			
			var activeEle = $(".active");
			
			//$(activeEle).children(".proShowItemImgWrapper").children(".imgBw").fadeIn(800);
			$(activeEle).removeClass('active');
			//$(activeEle).next().children(".proShowItemImgWrapper").children(".imgBw").fadeOut(800);
			$(activeEle).next().addClass('active');

			/*
$(activeEle).animate({
				opacity: '0.5'
			},400).removeClass('active');
			$(activeEle).next().animate({
				opacity: '1'
			},400).addClass('active');
*/
			
			var currInfo = $("#ProShowInfoBox");
			var order = $(activeEle).next().index();
			var targetContentDiv = $("#ProShowInfoBox"+(order+1)+"");
			
			$(currInfo).find(".proShowName").html($(targetContentDiv).find(".proShowName").html());
			$(currInfo).find(".proShowSpot").html($(targetContentDiv).find(".proShowSpot").html());
			$(currInfo).find(".proShowText").html($(targetContentDiv).find(".proShowText").html());
			//$(currInfo).mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
		}
	});
	
	$("#ProShowScrollLeft").bind('mouseup', function(){
		if($(".horizontalScrollWrapper").not(':animated') && $(".active").index()!=0)
		{
			$(".horizontalScrollWrapper").animate({
				left:'+=240px'
			},500, defEasing);
			
			var activeEle = $(".active");
			
			//$(activeEle).children(".proShowItemImgWrapper").children(".imgBw").fadeIn(800);
			$(activeEle).removeClass('active');
			//$(activeEle).prev().children(".proShowItemImgWrapper").children(".imgBw").fadeOut(800);
			$(activeEle).prev().addClass('active');
			
			var currInfo = $("#ProShowInfoBox");
			var order = $(activeEle).prev().index();
			var targetContentDiv = $("#ProShowInfoBox"+(order+1)+"");
			
			$(currInfo).find(".proShowName").html($(targetContentDiv).find(".proShowName").html());
			$(currInfo).find(".proShowSpot").html($(targetContentDiv).find(".proShowSpot").html());
			$(currInfo).find(".proShowText").html($(targetContentDiv).find(".proShowText").html());
			//$(currInfo).mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
		}
	});
	
	$(".proShowItem .proShowItemImgWrapper a").click(function(e){
		if($(this).parent().parent().hasClass('active'))
		{
			window.location($(this).attr('href'));
		}
		else
		{
			e.preventDefault();
			var parent = $(this).parent().parent();
			var order = $(parent).index();
			var activeIndex = $(".active").index();
			if(activeIndex<order)
			{
				$(".horizontalScrollWrapper").animate({
					left:'-=240px'
				},500, defEasing);
				
				var activeEle = $(".active");
				
				//$(activeEle).children(".proShowItemImgWrapper").children(".imgBw").fadeIn(800);
				$(activeEle).removeClass('active');
				//$(this).children(".proShowItemImgWrapper").children(".imgBw").fadeOut(800);
				$(parent).addClass('active');
				
				var currInfo = $("#ProShowInfoBox");
				var order = $(parent).index();
				var targetContentDiv = $("#ProShowInfoBox"+(order+1)+"");
				
				$(currInfo).find(".proShowName").html($(targetContentDiv).find(".proShowName").html());
				$(currInfo).find(".proShowSpot").html($(targetContentDiv).find(".proShowSpot").html());
				$(currInfo).find(".proShowText").html($(targetContentDiv).find(".proShowText").html());
				//$(currInfo).mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
			}
			else
			{
				$(".horizontalScrollWrapper").animate({
					left:'+=240px'
				},500, defEasing);
				
				var activeEle = $(".active");
				
				//$(activeEle).children(".proShowItemImgWrapper").children(".imgBw").fadeIn(800);
				$(activeEle).removeClass('active');
				//$(this).children(".proShowItemImgWrapper").children(".imgBw").fadeOut(800);
				$(parent).addClass('active');
				
				var currInfo = $("#ProShowInfoBox");
				var order = $(parent).index();
				var targetContentDiv = $("#ProShowInfoBox"+(order+1)+"");
				
				$(currInfo).find(".proShowName").html($(targetContentDiv).find(".proShowName").html());
				$(currInfo).find(".proShowSpot").html($(targetContentDiv).find(".proShowSpot").html());
				$(currInfo).find(".proShowText").html($(targetContentDiv).find(".proShowText").html());
				//$(currInfo).mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
			}
		}
	});
	
	$("#ATCButton").bind('mouseup', function(){
		//var product_no = $("#ProductDetNo").html();
		//var quantity = $("#ATCQuantity option:selected").val();
		
		if(!$("#CartBox .loading").is(":visible"))
		{
			var pro_no = $(".proSizes:checked").attr('pro_no');
			var quantity = $(".proSizes:checked").next().children(".ATCQuantity").children("option:selected").val();
			AddToCart(pro_no, quantity);
		}
		
		
		/*
$.ajax({
			url: 'action.php?do=add-to-cart',
			type: 'POST',
			data: 'pro_no='+product_no+'&qnt='+quantity+'',
			success: function(res){
				var json = res;
				var jsonObj = JSON.parse(res);
				if( jsonObj['success'] == 1 )
				{
					$("#BtCart div a").html("SEPET ("+jsonObj['count']+")");
				}
				else
				{
					
				
				}
			}
		});
*/
	});
	
	$("#ProShowAddToCart").bind("mouseup", function(){
		if(!$("#CartBox .loading").is(":visible"))
		{
			AddToCart($(".active").attr('product_no'), 1);
		}
	});
	
	
	$(".proTextSelectItem").bind('mouseup', function(){
		if($(this).css('color')!='black')
		{
			var type = $(this).attr("texttype");
			$("#ProductText div").css('display', 'none');
			$(".proTextSelectItem").css('color', 'gray');
			var selector = ".proText"+type+"In";
			$(""+selector+"").fadeIn();
			$(this).css('color', 'black');
			
			
		}
	});
	
	
	
	//$("#sliderdeneme").slider();
	
	
});

function AddToCart(proID, quantity)
{
	$("#CartBox .loading").css('display', 'block');
	
	var product_no = proID;
	$.ajax({
		url: '/action.php?do=add-to-cart',
		type: 'POST',
		data: 'pro_no='+product_no+'&qnt='+quantity+'',
		success: function(res){
			var jsonObj = JSON.parse(res);
			if( jsonObj['success'] == 1 )
			{
				DoneLogin();
			}
			else
			{
				//LoginModal("Lütfen giriş yapınız");
				new tor.modal({
					title: 'Uyarı',
					content: 'Lütfen giriş yapınız'
				});
			}
		}
	});
	
}

$(window).load(function() {

	/*
var currInfo = $("#ProShowInfoBox");
	var targetContentDiv = $("#ProShowInfoBox1");
	
	$(currInfo).find(".proShowName").html($(targetContentDiv).find(".proShowName").html());
	$(currInfo).find(".proShowSpot").html($(targetContentDiv).find(".proShowSpot").html());
	$(currInfo).find(".proShowText").html($(targetContentDiv).find(".proShowText").html());
*/
	
	//$("#ProShowInfoBox").mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
	
	//$("#ProductWrapper").mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
	
	//fleXenv.initByClass("content");
	
	if($(".contentScroll").length>0)
	{
		$('.contentScroll').tinyscrollbar({
			sizethumb: 34
		});
	}
	
	if($("#ScrollbarLeft").length>0)
	{
		$('#ScrollbarLeft').tinyscrollbar({
			sizethumb: 34
		});
	}
	$("#ScrollbarCenterHorizontal .overview").css('width', ($(".proShowItem").length*240)+'px');
	if($("#ScrollbarCenterHorizontal").length>0)
	{
		$('#ScrollbarCenterHorizontal').tinyscrollbar({
			axis: 'x',
			sizethumb: 34
		});
		
		$("#ScrollbarCenterHorizontal .scrollbar .track .thumb").css('left', '0px');
	}
	
	//non-working
	/*
$("#ScrollbarCenterHorizontal .scrollbar .track .thumb").bind('mouseup', function(){
		if($(this).css('left').replace("px", "")>30)
		{
			$(this).trigger('mousedown');
			$(this).stop().animate({
				left: ''+(240*($(this).css('left').replace("px", "")/30))+'px'
			});
		}
	});
*/
	
});



















