﻿/*(function ($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }

})(jQuery)

jQuery.preLoadImages(

	    );

function ToggleColorList() {

    var id = "#ColorList";
    if ($(id).css("display") == "none") {
        $(id).css("display", "block");
        $("#ColorListDropDown").css("background", "url(/files/images/smartydropdowncolor_active.png)");

        $("#BrandList").css("display", "none");
        $("#BrandListDropDown").css("background", "url(/files/images/smartydropdownbrand.png)");

    } else {
        $(id).css("display", "none");
        $("#ColorListDropDown").css("background", "url(/files/images/smartydropdowncolor.png)");
    }

}

function ToggleBrandList() {

    var id = "#BrandList";
    if ($(id).css("display") == "none") {
        $(id).css("display", "block");
        $("#BrandListDropDown").css("background", "url(/files/images/smartydropdownbrand_active.png)");

        $("#ColorList").css("display", "none");
        $("#ColorListDropDown").css("background", "url(/files/images/smartydropdowncolor.png)");

    } else {
        $(id).css("display", "none");
        $("#BrandListDropDown").css("background", "url(/files/images/smartydropdownbrand.png)");
    }

}*/

function KillFSPopup() {

    var today = new Date();
    today.setTime(today.getTime());
    var expires_date = new Date(today.getTime() + (1000* (1000 * 60 * 60 * 24)));
    document.cookie = "KillFSPopup=True;expires="+expires_date.toGMTString();
	$("#fsDiv").css("display", "none");

}

function is_child_of(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent) {
                return true;
            }
        }
    }
    return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
    var current_mouse_target = null;
    if (event.toElement) {
        current_mouse_target = event.toElement;
    } else if (event.relatedTarget) {
        current_mouse_target = event.relatedTarget;
    }
    if (!is_child_of(element, current_mouse_target) && element != current_mouse_target) {
        eval(JavaScript_code);
    }
}

function ShowFilters(type) {

	jQuery.facebox({ ajax: '/Filters.aspx?type=' + type });
	$("#facebox").draggable({ containment: "document" });

}

function ShowMiniCart() {

	jQuery.facebox({ ajax: '/CartMini.aspx' });
	$("#facebox").draggable({ containment: "document" });

}


function ShowCardPhoneInfo() {

	jQuery.facebox({ ajax: '/CardPhoneInfo.aspx' });
	$("#facebox").draggable({ containment: "document" });

}

function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function deleteCookie(name) {
    setCookie(name,"",-1);
}

function calcTime(offset) {

    // create Date object for current location
    d = new Date();

    // convert to msec
    // add local time zone offset 
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    return new Date(utc + (3600000*offset));

}
