﻿function BannerEcommerceClick() {
	document.location.href = "/Negozio/eshop.aspx";
}

$(document).ready(function () {

	var textBoxSearch = $("#TdHeaderSearch input[title!='']");
	//var oldTextValue = textBoxSearch.val();
	textBoxSearch.hint();
	//textBoxSearch.restoreHint();
	//if (oldTextValue.length > 0) textBoxSearch.val(oldTextValue);

	$("#TdHeaderSearch input[title!='']").tagSuggest({
		url: "/tag-suggestion.aspx",
		tagContainer: "div",
		tagWrap: "div",
		elContainer: $("#DivSuggestContainer"),
		takeFirstOnEnter: false,
		getAdditionalParameter: function () {
			var rbMoto = $("#TdHeaderSearch input[value=RbMoto]").attr("checked");
			var rbScooter = $("#TdHeaderSearch input[value=RbScooter]").attr("checked");
			var rbNuovo = $("#TdHeaderSearch input[value=RbNuovo]").attr("checked");
			var rbUsato = $("#TdHeaderSearch input[value=RbUsato]").attr("checked");
			var param = {
				moto: rbMoto,
				scooter: rbScooter,
				nuovo: rbNuovo,
				usato: rbUsato
			};
			return param;
		},
		overridePressEnter: function () {
			var goButton = $(window.GlbJqueryFilterGoButton);
			window.location.href = goButton.attr("href");
			goButton.click();
		}
	});
	//disabling autocompletition of firefox:
	textBoxSearch.attr('autocomplete', 'off');
	//al click del pulsante di ricerca testuale nascondo le suggestions...
	$(window.GlbJqueryFilterGoButton).click(function () {
		$.TagSuggester("#TdHeaderSearch input[title!='']").hideSuggestions();
	});
	//SetPromo();
	window.timerPromoId = setInterval(SetPromo, 10000);

	$("#LayerBannerEcommerce2012").click(function () {
		document.location.href = "/Negozio/eshop.aspx";
	});

});

$(document).unload(function () { clearInterval(window.timerPromoId); });

function SetPromo() {
    //moto:
    var link = $("#BoxPromoMoto a:eq(0)");
    var imgLink = link.find("img").filter("eq(0)");
    var linkText = link.find("span").filter("eq(0)");
    //var json = { items: [ {id: '', Modello: '', urlFoto: ''}
    //alert(GlbCurrentOfferteMotoIndex + "_" + (GlbOfferteMoto.items.length -1));
    if (window.GlbCurrentOfferteMotoIndex > window.GlbOfferteMoto.items.length - 1) {
    	window.GlbCurrentOfferteMotoIndex = -1;
    }
	var justDoIt = false;
    $.each(window.GlbOfferteMoto.items, function(i, item) {
        if (i > window.GlbCurrentOfferteMotoIndex && !justDoIt) {
            imgLink.attr("alt", item.Modello);
            imgLink.attr("src", item.urlFoto);
            linkText.text(item.Modello);
            link.attr("url", "/moto/detailsL.aspx?marca=" + item.Marca + "&modello=" + item.Modello);
            window.GlbCurrentOfferteMotoIndex++;
            justDoIt = true;
        }
    });
    //scooter:
    link = $("#BoxPromoScooter a:eq(0)");
    imgLink = link.find("img").filter("eq(0)");
    linkText = link.find("span").filter("eq(0)");
    //var json = { items: [ {id: '', Modello: '', urlFoto: ''}
    //alert(GlbCurrentOfferteMotoIndex + "_" + (GlbOfferteMoto.items.length -1));
    if (window.GlbCurrentOfferteScooterIndex > window.GlbOfferteScooter.items.length - 1) {
    	window.GlbCurrentOfferteScooterIndex = -1;
    }
	justDoIt = false;
    $.each(window.GlbOfferteScooter.items, function(i, item) {
        if (i > window.GlbCurrentOfferteScooterIndex && !justDoIt) {
            imgLink.attr("alt", item.Modello);
            imgLink.attr("src", item.urlFoto);
            linkText.text(item.Modello);
            link.attr("url", "/scooter/detailsL.aspx?marca=" + item.Marca + "&modello=" + item.Modello);
            window.GlbCurrentOfferteScooterIndex++;
            justDoIt = true;
        }
    });
}
