﻿
var mouseX = 0;
var mouseY = 0;
var BoxStartX = 0;
var BoxEndX = 0;
var BoxStartY = 0;
var BoxEndY = 0;

$().mousemove( function(e) {
   mouseX = e.pageX; 
   mouseY = e.pageY;
});



function BoxHide(){
	if(BoxStartX < mouseX && BoxEndX > mouseX && BoxStartY < mouseY && BoxEndY > mouseY){
		//alert(mouseX)
	}else{
		$(".QuickBox").hide();
		clearInterval(Closer);
		//alert(mouseX)
	}
}

var Closer = Closer = setInterval("BoxHide()", 200);
var ProductID2 = 0;
function ShowBox(ProductID, Image, ModelName, ListPrice, Price, URLName, IsEnabledBasketButton) {
	ProductID2 = ProductID;
	$(".BoxImage").attr("src", $(Image).attr("src"));
	$(".BoxProductName").html(ModelName)
	$(".BoxPrice").html(Price + "<span style=\"font-size: 12px;\"> TL Kdv Dahil</span>")
	if (parseFloat(ListPrice) > parseFloat(Price)) {
		$(".BoxListPrice").html(ListPrice + "<span style=\"font-size: 12px; text-decoration: none;\"> TL Kdv Dahil</span>")
	} else {
		$(".BoxListPrice").html('')
	}
	if(IsEnabledBasketButton == 'True' || IsEnabledBasketButton == '1'){
		$(".BoxAddToBasket").html('<a href="javascript:AddToQuickCart(ProductID2, 0); //'+ IsEnabledBasketButton +';"><img src="/images/QuickBox/box_13.png" width="116" height="27" alt="" /></a>');
	}else{
		$(".BoxAddToBasket").html('');
	}
	$(".ImageLink").attr("href", "/urun/"+ URLName +".aspx");
	$(".QuickBox").show();
	var pos = $(Image).offset()
	$(".QuickBox").css("left", (pos.left - (parseFloat($(Image).css("width")) / 2)));
	$(".QuickBox").css("top", (pos.top - (parseFloat($(".QuickBox").height()) / 2) + 50));

	if((parseFloat($(".QuickBox").css("left")) + $(".QuickBox").width()) > parseFloat($(window).width())){
		//$(".QuickBox").hide();
		//$(".QuickBox").show();
		$(".QuickBox").css("left",(parseFloat($(window).width()) - $(".QuickBox").width()));
	}

	var BoxPos = $(".QuickBox").offset();
	BoxStartX = BoxPos.left;
	BoxEndX = BoxPos.left + $(".QuickBox").width();

	BoxStartY = BoxPos.top;
	BoxEndY = BoxPos.top + $(".QuickBox").height();

	clearInterval(Closer);
	Closer = setInterval("BoxHide()", 200);
}

function AddToQuickCart(ProductID, VariantID) {
	var Data = "Q=QuickAddToCart&ProductID="+ ProductID +"&VariantID="+ VariantID;
	$.ajax({
		type: "POST",
		url: "/Store/AddToQuickCart.aspx",
		timeout: 15000,
		cache: false,
		contentType: "application/x-www-form-urlencoded;charset=utf-8",
		data: Data,
		beforeSend: function() {
			$(".BoxAddToBasket").html('Lütfen bekleyin...');
		},
		success: function(msg) {
		if (parseFloat(msg) > 0) {
				$(".BoxAddToBasket").html('<img src="/images/QuickBox/box_15.png" width="116" height="27" alt="" />');
				$("#_CartTotal").html(msg);
			} else {
				$(".BoxAddToBasket").html('<a href="javascript:AddToQuickCart(ProductID2, 0);"><img src="/images/QuickBox/box_13.png" width="116" height="27" alt="" /></a>');
			}
		},
		error: function(xhr, textStatus, errorThrown) {
			alert(textStatus);
			$(".BoxAddToBasket").html('<a href="javascript:AddToQuickCart(ProductID2, 0);"><img src="/images/QuickBox/box_13.png" width="116" height="27" alt="" /></a>');
		}
	});
}




function GununFirsati(){
	$.ajax({
	  contentType: 'text/html; charset=utf-8',
	  url: '/OzelDetay/GununFirsati/GununFirsati.aspx',
	  success: function(data) {
		$('#GununFirsati').html(data);
	  }
	});
}





$(document).ready(function(){
		//$('#MenuControl').click(function(){  });
		$('#cats').click(function(){ $('#cats').hide(); });
		$('#cats').children().click(function(e){
			$('#MenuControl').html($(this).html());
			$('#MenuControl').attr('cat', ''+ $(this).attr('id') +'');
		});
		
		$(document).dblclick(function(){ $('#cats').slideUp('fast'); });
		//$("#aspnetForm").click(function(){ $('#cats').slideUp('fast'); });
		$("#MiddleOfSite").click(function(){ $('#cats').slideUp('fast'); });

		$("#TxtSearch").click(function(){ $('#cats').hide(); });
		
		$("#TxtSearch").autocomplete('http://www.vimjo.com/Suggestion/Search_CS.ashx');

	$(function()
	{
		var SearchText = $('#TxtSearch');
		var code =null;
		SearchText.keypress(function(e)
		{
			code= (e.keyCode ? e.keyCode : e.which);
			if (code == 13){
				window.location.href='http://www.vimjo.com/Suggestion/AramaYap.aspx?sKey='+ $('#TxtSearch').val().replace(/&/gi, '%26') +'&cat='+ $('#MenuControl').attr('cat').replace('div-', '') +'&pId='+ $('#productId').val();
				return false;
			}else{
				//e.preventDefault();
			}
		});

	});
});

function SendToSearch(){
	window.location.href='/Suggestion/AramaYap.aspx?sKey='+ $('#TxtSearch').val().replace(/&/gi, '%26') +'&cat='+ $('#MenuControl').attr('cat').replace('div-', '') +'&pId='+ $('#productId').val(); $('#cats').hide();
}




// VİTRİN PANEL vitrin panel

var s=0;
var Runner="";
var StepDelay = 6000;
function VitrinApp(){
	s++;
	if (s > 10){ s=1; }
	$('#ImgPlace').html('<a href=\''+ $('#ImgID'+ s).attr('clickurl') +'\' target=\''+ $('#ImgID'+ s).attr('target') +'\'><img src=\''+ $('#ImgID'+ s).attr('longdesc') +'\' width=578 height=245 border=0 /></a>');
	for(i=1;i<11;i++){ $('#ImgID'+ i).css('border-color', '#EDEDED');}
	$('#ImgID'+ s).css('border-color', '#FF6600');
}
function ChangeImg(id){
	$('#ImgPlace').html('<a href=\''+ $("#ImgID"+ id).attr('clickurl') +'\' target=\''+ $('#ImgID'+ id).attr('target') +'\'><img src=\''+ $("#ImgID"+ id).attr('longdesc') +'\' width=578 height=245 border=0 /></a>');
	for(i=1;i<11;i++){ $('#ImgID'+ i).css('border-color', '#EDEDED');}
	$("#ImgID"+ id).css('border-color', '#FF6600');
	clearInterval(Runner);
	s=id;
}		

