// JavaScript Document


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

var URL = window.location.href

function queryString(Deger) {
  if(Deger!=null) {
    var regEx = new RegExp("(\\?|&)("+Deger+"=)(.*?)(&|$|#)","i")
    var exec = regEx.exec(URL)
    var Sonuc = RegExp.$3
  } else {
    var regEx = new RegExp("(\\?)(.*?)($)","i")
    var exec = regEx.exec(URL)
    var Sonuc = RegExp.$2
  }

  return(Sonuc)
}

function add2chart(id) {
	var data ="id="+id;
	var url="ajax.php?op=10";
	
	$.post(url,data, function(success) { 
		if(success=="1"){
			var count=parseInt($("#sepetcnt").html())+1;
			$("#sepetcnt").html(count);
   
            var lang = queryString('lg');
            if(lang == 'tr')
			    alert("Ürün Sepetinize Eklendi!");
            else if(lang == 'en')
                alert("The item is in your basket!");
            else if(lang == 'de')
                alert("Die Ware ist in Ihrem Korb");
            else
                alert("Ürün Sepetinize Eklendi!");
            
		}else {
			alert(success);
		}
	});
}

function removeChart(index,id) {
    var div = "urun"+index+"_"+id;
    var data ="index="+index+"&id="+id;
    var url="ajax.php?op=11";
   
    var lang = queryString('lg');
    
    if(lang == 'tr')
        msj = "Ürünü Çıkartmak İstedinize Eminmisiniz?";
    else if(lang == 'en')
        msj = "Are you sure, that you want delete this item?";
    else  if(lang == 'de')
        msj = "Sind Sie sicher, dass Sie die Ware entfernen wollen?";
    else
        msj = "Ürünü Çıkartmak İstedinize Eminmisiniz?";
            

    if(confirm(msj)) {
        $.post(url,data, function(success) { 
            if(success=="1"){
                $("#"+div).fadeOut(500);
                window.location.reload();
            }else {
                alert(success);
            }
        });
    
    }
}
var mouseX = 0;
var mouseY = 0;


$().mousemove( function(e) {
   mouseX = e.pageX; 
   mouseY = e.pageY;
 });
function thumnailPre(id) {
    var obj=id;
    $("#lightbox_product_"+obj+" a").mouseover( function() {
        var title = $("#lightbox_product_"+obj+" a").attr('title'); 
        var href = $("#lightbox_product_"+obj+" a").attr('href'); 
        //showImg(title,href);
        $('embed, object, select').css({ 'visibility' : 'hidden' });
        var winWidth = $(window).width(); 
        var winHeight  = $(window).height(); 

        $("#thumbnail").css({
            'top':'50px',
            'left':((winWidth/2)-250)+'px',
            'display':'block'
        });
        
        $("#thumbnail").html("<span><img src='"+href+"' /></span><div>"+title+"</div>");
        $("#thumbnail").show();
    });

    $("#lightbox_product_"+obj+" a").mouseout( function() {
        $('embed, object, select').css({ 'visibility' : 'visible' });
        $("#thumbnail").hide();
    });
        
    $("#lightbox_product_"+obj+" a").unbind('click').click(function () {
        return false;
    });
}

$(document).ready(function() {
    $('#mycarousel').jcarousel({
        auto: 5,
        scroll:3,
        wrap: 'both',
        initCallback: mycarousel_initCallback
    });
});

$(document).ready(function() {

    $('#myspecialcarousel').jcarousel({
        auto: 5,
        scroll:3,
        wrap: 'both',
        initCallback: myspecialcarousel_initCallback
    });
});


function myspecialcarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function showCatTitle(id) {
    $("#catTitle-"+id+"").show();
}
function hideCatTitle(id) {
    $("#catTitle-"+id+"").hide();
}