// doc ready
$(document).ready(function() {
    $(function() {
        $.ajaxSetup({
            // Disable caching of AJAX responses */ 
            cache: false
        });
    });
    $(".lightbox").lightBox();

    if ($.browser.msie | $.browser.safari | $.browser.opera | $.browser.mozilla) {
        twatchData = 'page=' + encodeURIComponent(window.location);
        if (typeof document.referrer != 'undefined' && document.referrer != '') {
            twatchData += '&ref=' + encodeURIComponent(document.referrer);
        }
        twatchData += '&website_id=' + encodeURIComponent('dsi');
        twatchData += '&no_cookies=true';
        twatchData += '&strip_page_params=true';
        if (typeof screen.width != 'undefined') {
            twatchData += '&resolution=' + screen.width + 'x' + screen.height;
        }
        $.get('/twatch3/remote/js_logger.php?' + twatchData);
    }
});

function loadPrices(type)
{
	$("#theprices").load('/php/pricestable.php?type=' + type);
}
function loadPricesXL(type) {
    $("#theprices").load('/php/pricestablexl.php?type=' + type);
}
function load3DSPrices(type) {
    $("#theprices").load('/php/pricestable3ds.php?type=' + type);
}

function showCountdown()
{
	$('#releasecountdown').countdown({until: new Date(2009, 3, 3, 01, 00, 00), layout: '<a href="/release-date">On sale in %H%n %l%H, %M%n %l%M and %S%n %l%S</a>'});
}

function rateProduct(id, retailerId) {
    var email = $("#reviewForm #email").val();
    var name = $("#reviewForm #author").val();
    var ui = $("#stars-wrapper2").data("stars");
    var rating = ui.options.value;
    var review = $("#reviewForm #review").val();
    var url = window.location.href.split('#')[0];

    var data = "id=" + id + "&email=" + email + "&name=" + name + "&rating=" + rating + "&review=" + escape(review) + "&retailerId=" + retailerId + "&url=" + url;
    if (email != "" & name != "") {
        $("#reviewForm").hide();
        $("#reviewFormMessage").hide();
        $("#reviewFormWait").show();

        $.ajax({
            url: "/php/rate.php",
            data: data,
            type: "POST",
            cache: false,
            success: function (html) {
                $("#reviewFormWait").hide();
                $("#reviewFormMessage").show();
                $("#reviewFormMessage").html(html);
                if (html.indexOf("Thank") == -1) $("#reviewForm").show();
            },
            error: function (x, e) {
                $("#reviewForm").show();
                $("#reviewFormWait").hide();
                $("#reviewFormMessage").show();
                $("#reviewFormMessage").html(e);
            }
        });
    }
    else {
        $("#reviewFormMessage").show();
        $("#reviewFormMessage").html("Name and Email are required.");
    }
}

