var contAnimation = false;
var marginValue = "-1000px";
var scrollPosition = 0;
var scrollProductCount = 8;

var init = function($) {
    $("#marquecontent").hover(stopAnimation, startAnimation);
    $("#scroll-right").css({"cursor": "pointer"}).click(scrollRight);
    $("#scroll-left").css({"cursor": "pointer"}).click(scrollLeft);
    startAnimation();
    $('#tabcontainer').tabs({ fxSlide: true, fxFade: true, fxSpeed: 'fast' });
    $('div[rel*=facebox]').facebox({
            loadingImage : 'js/facebox/loading.gif',
                opacity: .5,
                closeImage   : '/static/images/pencereyi-kapat.png',
                gotoCart: '/static/images/pencereyi-kapat.png',
                });
};

var scrollRight = function() {
    if (scrollPosition > (-1 * 138 * scrollProductCount / 2)) {
        scrollPosition -= 138;
        $("#content-scroll-big").animate({marginLeft: scrollPosition}, 1000);
    }
};

var scrollLeft = function() {
    if (scrollPosition < 0) {
        scrollPosition += 138;
        $("#content-scroll-big").animate({marginLeft: scrollPosition}, 1000);
    }
};

var startAnimation = function() {
    contAnimation = true;
    $("#marquecontent").animate({marginLeft: marginValue}, {duration: 10000, step: animationStep, complete: restartAnimation});
};

var animationStep = function() {
    if (!contAnimation) {
        $(this).stop();
    }
};

var stopAnimation = function() {
    contAnimation = false;
};

var restartAnimation = function() {
    if (marginValue == "-1000px") {
        marginValue = "0";
    } else {
        marginValue = "-1000px";
    }
    startAnimation();
};

function formatprice(e,f){
    if(f==""){
        e = parseInt(e) + "";
    }else{
        if(f==" "){
            e = parseInt(e.replace(/ /g,""))+"";
        }else{
            if(f=="."){
                e = parseInt(e.replace(/\./g,""))+"";
            }else{
                if(f==","){
                    e = parseInt(e.replace(/,/g,""))+"";
                }
            }
        }
    }
    var c = "";
    if(e.length>3){
        while(e.length>3){
            c = f+e.substr(e.length-3)+c;
            e = e.substr(0,e.length-3);
        }
        c = e+c;
    }else{
        c = e;
    }
    if(!c||c=="NaN"){
        c = "";
    }
    return c;
}
