﻿var izh = 390;
var izw = 390;
var navi = navigator.userAgent.toString();

function ShowLoggedInForm()
{
	$("#new-cust-form, #shipping-as-billing, #credit-card-form, #divButtons").slideDown();
}

$(document).ready(function() {
    fixTrans();
    $(".product-container").mouseover(function(){
        $(this).addClass("hover");
    }).mouseout(function(){
        $(this).removeClass("hover");
    });
    // zoom
    $(".plus").click(function(){showBigImage();});
    // effects for button of delete good from basket
    $(".delete").mouseover(function(){
        $(this).css("background-position", "0 0");
    }).mousedown(function(){
        $(this).css("background-position", "0 -22px");
    }).mouseout(function(){
        $(this).css("background-position", "0 -11px");
    }).click(function(){
        c = confirm("Är du säker på att ta bort?");
        if (c) {
			eval($(this).next().attr("href"));
			/*
            p = $(this).parent().parent();
            p_c = p.attr("class");
            if (p_c == "first") {
                p.parent().find(".other:first").each(function(){
                    $(this).addClass("first");
                    $(this).removeClass("other");
                });
            }
            p.remove();
            */
        }
    });
    // fix for Safari and Google Chrome
    if (navi.indexOf("Chrome") != -1 || navi.indexOf("Safari") != -1) {
        $(".help-icon").css("margin-top", "-23px"); 
    }
    // New customer
    $("#btn_create_cust").click(function(){
		$("#cust-login").slideUp();
		$("#new-cust-form, #shipping-as-billing, #credit-card-form, #divButtons").slideDown();
    });
    
    $("#btn_login").click(function(){
		$("#new-cust-form, #shipping-as-billing, #divButtons, #credit-card-form").slideUp();
		$("#cust-login").slideDown();
    });
    
    // fix z-index for select fir IE6
    if ($("#fb") != null && $("#fb").height() != null) $(".hie6").height($("#fb").height());
    if ($("#goods") != null && $("#goods").height() != null) $(".ghie6").height($("#goods").height() + 40);
    // Show/hide content of basket
    $("#blue_btn_1").click(function() {
        v = $('#blue_btn_1').val();
        if (v == 'Dölj varukorg') {
            hideGoods();
        }
        else {
            $('#blue_btn_1').val('Dölj varukorg');
            $("#goods").slideDown("slow");
        }
        /*setTimeout('hideGoods()', 5000);*/
    });
    // Effects for buttons
    $(".green-btn, .blue-btn-zoom, .blue-btn-help, .blue-btn-arrow").mouseover(function(){
        $(this).css("background-position", "0 -21px");
    }).mousedown(function(){
        $(this).css("background-position", "0 -42px");
    }).mouseout(function(){
        $(this).css("background-position", "0 0");
    });
    $(".green-btn-big").mouseover(function(){
        $(this).css("background-position", "0 -26px");
    }).mousedown(function(){
        $(this).css("background-position", "0 -52px");
    }).mouseout(function(){
        $(this).css("background-position", "0 0");
    });
    // Effects for arrows
    $(".slider-navi-box .to-left").mouseover(function(){
        $(this).removeClass("to-left-down");
        $(this).addClass("to-left-hover");
    }).mousedown(function(){
        $(this).removeClass("to-left-hover");
        $(this).addClass("to-left-down");
    }).mouseout(function(){
        $(this).removeClass("to-left-hover");
        $(this).removeClass("to-left-down");
    }); 
    $(".slider-navi-box .to-right").mouseover(function(){
        $(this).removeClass("to-right-down");
        $(this).addClass("to-right-hover");
    }).mousedown(function(){
        $(this).removeClass("to-right-hover");
        $(this).addClass("to-right-down");
    }).mouseout(function(){
        $(this).removeClass("to-right-hover");
        $(this).removeClass("to-right-down");
    }); 
    // Effects for zoom-buttons
    $(".zoom .plus").mouseover(function(){
        $(this).removeClass("plus-down");
        $(this).addClass("plus-hover");
    }).mousedown(function(){
        $(this).removeClass("plus-hover");
        $(this).addClass("plus-down");
    }).mouseout(function(){
        $(this).removeClass("plus-hover");
        $(this).removeClass("plus-down");
    }).click(function(){
        
    });  
    // Show/hide submenus in left column
    $(".f-level a").click(function() {
        click_node_accordion(this);
    });
    // Change preview-image 
    /* path for image save in hidden fields in box for image */
    $(".img-83px").click(function(){
        $(".img-83px").find("img").animate({ 
            opacity: 1
        }, 1 );
        collection = $(this).find("input[type=hidden]");
        len = collection.length; 
        if (len != 1)
            return false;
        document.getElementById(id_zoom_image).src = collection[0].value;
        $(this).find("img").animate({ 
            opacity: 0.4
        }, 1000 );
    });
    var id_zoom_image = "zoom_img";
    // init first preview
    collection = $(".img-83px:first").find("input[type=hidden]");
    len = collection.length; 
    if (len == 1) {
        document.getElementById(id_zoom_image).src = collection[0].value;
        $(".img-83px:first").find("img").animate({ 
            opacity: 0.4
        }, 1 );    
    }
    /* init functions */
    slider();
    accordion();
    if (document.getElementById("slider-img") != null)
    $("#slider-img").easySlider({
        prevId: 		'prev',
        prevText: 		'',
        nextId: 		'next',	
        nextText: 		'' 
	});
    /* end init functions */
});

/** slider for scrolling new goods **/
var count = 1;
var c_all = 0;
/* init */
function slider() {
    id_container = "slider";
    if (document.getElementById(id_container) == null)
        return false;
    li_list = $("#" + id_container).find("li");
    len = li_list.length;
    if (len < 3)
    {
		li_list.css("display", "block");
        return false;
    }
    c_all = len;
    cc = 1;
    $("#" + id_container).find("li").each(function() {
        if (cc == 1 || cc == 2)
            $(this).css("display", "block");
        else
            $(this).css("display", "none");
        cc++;
    });
    setInterval('showNewGoods()', 3000);
}
/* sliding goods */
function showNewGoods() {
    id_container = "slider"
    good1 = count + 1;
    good2 = count;
    cc = 1;
    $("#" + id_container).find("li").each(function() {
        if (cc == good1 || cc == good2)
            $(this).fadeIn("slow");
        else
            $(this).css("display", "none");
        cc++;
    });
    /*
    if (count >= c_all)
        count = 1;
    else
        count += 2;
    */
    
    count += 2;
    
    if (count >= c_all)
		count = 1;
    
    //console.debug('good1=' + good1 + ' good2=' + good2 + ' cc=' + cc + ' count=' + count + ' c_all=' + c_all);
}
/** end slider for scrolling new goods **/

/** hide content of bascket **/
function hideGoods() {
    if ($("#goods").css('display') == "none")
        return false;
    $("#goods").slideUp("slow");
    $('#blue_btn_1').val('Visa varukorg');
}
/** end hide content of bascket **/

/** accordeon for tree of categories **/
function accordion() {
    $(".first-level").find(".f-level").each(function() {
        $(this).parent().find("ul").each(function() {
            $(this).css("display", "none");
        });
    });
}
function click_node_accordion(obj) {
    $(".first-level").find(".f-level").each(function() {
        $(this).parent().find("ul").each(function() {
            $(this).hide("slow");
        });
    });
    $(obj).parent().parent().find("ul").each(function() {
        $(this).toggle("slow");
    });
}
/** end accordeon for tree of categories **/

/** show big image **/
var w = 200;
var h = 200;
var firstLoad = false;
function clearBoxImg() {
    $(".box-for-fb img").css("display", "none");
    $(".box-close-img").css("display", "none");
    $(".box-for-fb").css("width", "200px");
    $(".box-img").css("height", "auto");
    $(".box-for-fb img").attr({src: ""});
}
function showBigImage() {
    firstLoad = true;
    clearBoxImg();
    ShowDivAsPopup('box-for-fb');
      
    /* get image url, num*/
    vsrc = document.getElementById("zoom_img").src;
    current_num = 1;
    total_num = 20;
    /* get image url, num */
    
    $(".current_num").html(current_num);
    $(".total_num").html(total_num);
    $(".box-for-fb img").attr({src: vsrc, height: vsrc.height, width: vsrc.width});
}
function checkLoadImg(obj) {
    if (obj != null && firstLoad == true) {
        /*w = $(obj).width();
        h = $(obj).height();*/
        h = 600;
        w = 600;
        $(".box-for-fb").css("width", w + "px");
        $(".box-close-img").css("width", w + "px");
        $(".box-img").css("height", h + "px");
        $(".box-for-fb img").css("display", "block");
        if (navigator.userAgent.indexOf("MSIE 6") != -1) {
            $(".box-for-fb iframe").css("width", w + 20 + "px");
            $(".box-for-fb iframe").css("height", h + "px");
        }
        $("#big-img").attr({width: w, height: h});
        ShowDivAsPopup('box-for-fb');
        $(".box-close-img").slideDown("slow");
    }
}
/** end show big image **/
function hProduct(obj){
   $(obj).addClass("hover");
}
function oProduct(obj){
   $(obj).removeClass("hover");
}