function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}



/*overstate*/
$(document).ready(function () {
    $(".menuoverstate").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".jpg", "_o.jpg");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.jpg") == -1) {
                    this.src = this.src.replace(".jpg", "_o.jpg");
                }

            },

            function () {
                if(!$(this).hasClass('current'))
                this.src = this.src.replace("_o.jpg", ".jpg");

            });

    });
    $(".menuoverstate-png").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".png", "_o.png");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.png") == -1) {
                    this.src = this.src.replace(".png", "_o.png");
                }

            },

            function () {
                this.src = this.src.replace("_o.png", ".png");

            });

    });
    var toggleStatus = [];
    var contents = [];
    $("#tab-wrapper").children().each(function (i) {
        contents[i] = $(this);
    });

    $(".tab-top-wrapper").children().each(function (i) {
        toggleStatus[i] = false;
        jQuery(this).click(function () {
            if (toggleStatus[i] == false) {
                for (j = 0; j < toggleStatus.length; j++) {
                    toggleStatus[j] = false;
                    $(contents[j]).hide();
                    $(".tab-top-wrapper").children().removeClass("current");
                    $(".about-link").children('a').removeClass("current");
                }
                $(this).children('a').addClass("current");
                toggleStatus[i] = true;
                $(contents[i]).show();
            }
        });
    });

    /*login section*/

    $('#customer-login').click(
		function () {
		    $('#login-wrapper').slideToggle(300);
		},
		function () {
		    $('#login-wrapper').slideToggle(300);
		}
	);

    /*slideshow*/
    $('#slideshow').cycle();

    /*fancybox*/
    $(".fancybox").fancybox({
        'titleShow': false
    });
    $(".iframe-fancybox").fancybox({
        'type': 'iframe'
    });
    /*fancybox accessories
    $("a[rel=group]").fancybox({
    'titleShow'		: false
    });*/

    $('.switch-image').each(function () {
        $(this).click(function () {
            if (this.src.indexOf("_o.jpg") == -1) {
                this.src = this.src.replace(".jpg", "_o.jpg");
            }
            else {
                this.src = this.src.replace("_o.jpg", ".jpg");
            }
        });
    });

    //Set the date picker up for all elements
    $('.date-picker').datepicker({
        showOn: 'button',
        buttonImage: '/_assets/images/calendar.png',
        buttonImageOnly: true,
        minDate: '-100y',
        dateFormat: 'dd/mm/yy',
        showOtherMonths: true,
        selectOtherMonths: true
    });
});


function calculateTopPosition(id)
{
    return $(id).offset().top - parseFloat($(id).css('margin-top').replace(/auto/, 0));
}

function animateBasketAdd(sender) {
    var topPos = $(sender).offset().top - parseFloat($(sender).css('margin-top').replace(/auto/, 0));
    var wrapperPos = $('.content-account').offset().top - parseFloat($('.content-account').css('margin-top').replace(/auto/, 0));
    $('#addBasketVan').stop();
    $('#addBasketVan').css('left', '280px');
    $('#addBasketVan').css('top', topPos - wrapperPos);
    
    $('#addBasketVan').show();
    $('#addBasketVan').animate(
    {
        left: "780px"
    },
    3000,
    function () {
        $('#addBasketVan').hide();
        $('#addBasketVan').css('left', '280px');
    });

    return false;
}

function serverCall(params, callback) {
    jQuery.post("/AjaxHandler.ashx", params, callback);
}

function removeBasketItem(itemID) {
    serverCall({ "method": "RemoveBasketItem", "itemID": itemID
    }, function (data, status) {
        if (data.substring(0, 4) == "<tr>") {
            //$('#framesError').hide();
            $('#basket-items').html(data);
        }
        else {
            //$('#doorsError').html("<ul>" + data + "</ul>").show();
        }
    });
}
