var lis = null;
var timeout = 0;

function initialize() {
    var latlng = new google.maps.LatLng(52.929077, -1.212101);
    var myOptions = {
        zoom: 15,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("gmap"), myOptions);
    var image = new google.maps.MarkerImage('/App_Themes/PropertyProtector/images/gmap-marker.png',
      // This marker is 102 pixels wide by 79 pixels tall.
      new google.maps.Size(102, 79),
      // The origin for this image is 0,0.
      new google.maps.Point(0, 0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(48, 75));

    var shadow = new google.maps.MarkerImage('/App_Themes/PropertyProtector/images/gmap-marker-shadow.png',
    // The shadow image is larger in the horizontal dimension
    // while the position and offset are the same as for the main image.
      new google.maps.Size(151, 79),
      new google.maps.Point(0, 0),
      new google.maps.Point(48, 75));

    var marker = new google.maps.Marker({
    position: latlng,
        icon:image,
        map: map,
        shadow: shadow,
        title: "Property Protector"
    });   
}
function triggerCycle() {
    var selectedIndex = 0;
    for (i = 0; i < lis.length; i++) {
        if (lis.eq(i).hasClass("selected")) {
            selectedIndex = i;
        }
    }
    var order = [selectedIndex, (selectedIndex + 1) % 4, (selectedIndex + 2) % 4, (selectedIndex + 3) % 4];
    var z = 10;
    for (i = 0; i < order.length; i++) {
        lis.eq(order[i]).find(".showcase").css("zIndex", z);
        z--;
    }
    var firstShowcase = lis.eq(order[0]).find(".showcase");
    firstShowcase.find(".strapline").animate({
        right: "-425px"
    }, 1000, function() { 
        firstShowcase.fadeOut("normal", function() {
            lis.removeClass("selected");
            lis.eq(order[1]).addClass("selected");
            lis.eq(order[1]).find(".strapline").animate({
                right:"0"
            },1000);
            firstShowcase.css("zIndex", 0);
            firstShowcase.show();
            clearTimeout(timeout);
            timeout = setTimeout(triggerCycle, 5000);
        });
    });
	
}

function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}


$(document).ready(function() {
    lis = $("#content-showcase li");
    lis.eq(0).find(".strapline").animate({
        right: "0"
    }, 1000, function() {
        timeout = setTimeout(triggerCycle, 10000);
    });

    if ($("#gmap").length > 0) {
        initialize();
    }

    $(".comparison-table .p:not(.prod-1,.prod-2,.prod-3,.prod-13,.prod-14,.prod-15)").css("display", "none");
$("#schemes").hide();
	$("#schemescompare").click(function(){
										$("#mainstream").hide();
										$("#schemes").show();
										return false;
										});
	$("#mainstreamcompare").click(function(){
										$("#mainstream").show();
										$("#schemes").hide();
										return false;
										});
    $(".product-buttons li input").click(function() {

        var classname = this.parentNode.id;
        var parent = $(this).parent();
        var numChecked = $(".product-buttons li input:checked").length;
        if (this.checked == true) {
            parent.addClass("selected");
            $("." + classname).fadeIn("normal", function() { $(this).css("display", ""); });
            if (numChecked == 4) {
                $(".product-buttons li input:not(:checked)").attr('disabled', true);
            }
        }
        else {
            parent.removeClass("selected");
            $("." + classname).fadeOut();
            if (numChecked == 3) {
                $(".product-buttons li input:not(:checked)").attr('disabled', false);
            }
        }
    });
	
	$("#cq1 a").click(function(){
		if(this.id=="residential-click"){
				$(this).addClass("selected");
				$("#commercial-click").removeClass("selected");
				$("#cq2").fadeIn();
				$(".contact-box").hide();
				$("#cq2 a").removeClass("selected");
		}
		else{
			$(this).addClass("selected");
			$("#residential-click").removeClass("selected");
			$("#cq2").hide();
			$("#cq2 a").removeClass("selected");
			$("#cunningham").fadeIn();
		}
			return false;
	});
	$("#cq2 a").click(function(){
		if(this.id=="premier-click"){
				$(this).addClass("selected");
				$("#lite-click").removeClass("selected");
				$("#cunningham").fadeIn();
				$("#towergate").hide();
		}
		else{
			$(this).addClass("selected");
			$("#premier-click").removeClass("selected");
			$("#cunningham").hide();
			$("#towergate").fadeIn();
		}
			return false;
	});
	
	var claimType = "";
	claimType = getParameterByName("type");
	if(claimType!="")
	{
		if(claimType=="cl"){
			$("#emailToSection :radio:eq(1)").click();
		}
		else if(claimType=="tg"){
			$("#emailToSection :radio:eq(2)").click();
		}
	}
	
	
});




