// doc ready
$(document).ready(function() {
    $(function() {
        $(".lightbox").lightBox();
        $.ajaxSetup({
            // Disable caching of AJAX responses */ 
            cache: false
        });

        // defer addthis
        var element = document.createElement("script");
        element.src = "http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4df7d3603a7b5305";
        document.body.appendChild(element);

        // defer plusone
        var element = document.createElement("script");
        element.src = "http://apis.google.com/js/plusone.js";
        document.body.appendChild(element);

        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('console');
            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 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=" + review + "&retailerId=" + retailerId + "&url=" + url;
	if (email != "" & name != "") {
		$("#reviewForm").hide();
		$("#reviewFormMessage").hide();
		$("#reviewFormWait").show();

		$.ajax({
			url: "/wp-content/themes/consoletheme/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.");
	}
}

// colour switchers
function loadPSPGoPrices(type)
{
	$("#theprices").load('/wp-content/themes/consoletheme/pricestablepspgo.php?type=' + type);
}
function loadPSPPrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestablepsp3000.php?type=' + type);
}
function loadWiiPrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestablewii.php?type=' + type);
}
function loadWiiFitPlusPrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestablewiifitplus.php?type=' + type);
}
function loadXboxPrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestablexbox.php?type=' + type);
}
function loadPS3SlimPrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestableps3slim.php?type=' + type);
}
function loadPSMovePrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestableplaystationmove.php?type=' + type);
}
function loadXboxSlimPrices(type) {
    $("#theprices").load('/wp-content/themes/consoletheme/pricestablexbox360slim.php?type=' + type);
}
function load3DSPrices(type) {
	$("#theprices").load('/wp-content/themes/consoletheme/pricestable3ds.php?type=' + type);
}
function loadPricesTypes(type, siteId, pdesc) {
    $("#theprices").load('/wp-content/themes/consoletheme/showpricestypes.php?type=' + escape(type) + '&siteId=' + siteId + '&pdesc=' + escape(pdesc) + '&mode=prices');
}
function loadEXProdPrices(id) {
    $("#theprices").load('/wp-content/themes/consoletheme/exprodpricestable.php?id=' + id);
}

// format switcher
function loadConsolePrices(type) {
    var pathname = window.location.pathname;
    $("#theprices").load(pathname + '?mode=prices&type=' + type);
}

