﻿///<reference path="jquery-1.4.1-vsdoc.js"/>
/*Disable Javascript Alerts - remove when obsolete*/
//function alert() { }

// Colorbox functions for on-demand store selector

// Shows inline content (can be lifted from the same page)
function openColorBoxInline(href, width, height) {
	$.fn.colorbox({ width: "50%",
		href: href,
		open: true,
		width: width,
		height: height,
		iframe: true,
		inline: true,
		overlayClose: false,
		escKey: false,
		onClosed: function () {
			location.reload(true);
		},
		onLoad: function () {
			$('#cboxClose').remove();
		}
	});

}
// Shows another page content in an iframe
function openColorBoxLink(href, width, height) {
	$.fn.colorbox({ width: "50%",
		href: href,
		open: true,
		width: width,
		height: height,
		iframe: true,
		inline: false,
		overlayClose: false,
		escKey: false,
		onClosed: function () {
			location.reload(true);
		},
		onLoad: function () {
			$('#cboxClose').remove();
		}
	});
}

//$(".productDetail img").bind("load", function () { $(this).hide().fadeIn("slow"); });

$(document).ready(function () {
    $(".navigation ul li").length
    //add first to first navi item
    $(".navigation ul li:first").addClass("first");
    //also the last of the content highlights on the front page must have class last
    $(".contentLiftup div:last").addClass("last");

    //also the last of the product highlights on the front page must have class last
    if ($(".products li").length > 6) {
        $(".products li:nth-child(6)").addClass("last");
    }
    else $(".products li:last").addClass("last");

    $('#navigation').accordion({
        active: false,
        header: '.head',
        navigation: true,
        animated: 'slide',
        autoHeight: false,
        collapsible: true
    });

    $('.print a').click(function () {
        window.print();
        return false;
    });

    $(".searchResult img").lazyload({
        placeholder: "/images/spinner.gif",
        effect: "fadeIn",
        failurelimit: 90
    });

    //$(".searchResult img").hide();
    //$(".searchResult img").fadeIn("slow");

    //	$(".searchResult img").one("appear", function () {
    //		//$(this).css("opacity", "100");
    //		$(this).fadeIn("slow");
    //	})


    //	$(".productDetail img").load( function () {
    //		$(this).fadeIn("slow");
    //	})

    $('#ddlStoreAvailability').change(function () {
        $("#prodAvailability span").hide();
        $("#prodAvailability #litAvailabilitySearching").show();
        $.ajax({
            url: "/Services/ProductAvailabilityService.svc/GetAvailability",
            data: {
                storeID: $('#ddlStoreAvailability').val(), 
                productID: $("#litProductID").text()
            },
            success: function (data) {
                var a = data.d;
                switch (a) {
                    case 1: 
                        $("#prodAvailability #litAvailabilitySearching").hide();
                        $("#prodAvailability #litAvailabilityAvailable").show(); 
                        break;
                    case 0: 
                        $("#prodAvailability #litAvailabilitySearching").hide();
                        $("#prodAvailability #litAvailabilityNotAvailable").show(); 
                        break;
                    default: 
                        $("#prodAvailability #litAvailabilitySearching").hide();
                        $("#prodAvailability #litAvailabilityNotWorking").show(); 
                        break;
                }
            },
            error: function () {
                $("#prodAvailability #litAvailabilityNotWorking").show();
            }
        });
    });
});


