jQuery(document).ready(function() {
	// do something here

var selectedhalyardlength;
var halyardlengthselected = 1; 

// Hide all of these segments on page load
$(".stepperV1 ul li#st1 .wOLnk").hide();
$(".stepperV1 ul li#st1 .wLnk").show();
$("a:contains('Click here to choose from one of our recommended halyard lengths for your boat')").hide();
$("p:contains('Desired Custom Halyard Length')").hide();
$("#selectedhalyard2").hide();
$("#selectedhalyard3").hide();
$("#selectedhalyard4").hide();
$("a.selectanotherboat").hide();
$("div.hrdwrIFaceTitle").hide();
$("a.customlength").hide();
$("#priceblock").hide();
$("#finaldescription").hide();
$(".hPurchase").hide();
$(".sailingStyleSelection").attr("checked", false); 
// This next section is hidden only until we build the functionality
// that will allow user to select their own halyard size
$("#customhalyardlength").hide();
// See note above this hide statement

// End of initial page load segment hide

// Variable Declarations
var cumulativeprice;
var cumulativepartnumber;
var shackleselecteddescription;
var shackleselectiondescription;
var spliceselectiondescription;
var spliceselectionprice;
var shackleselectedprice;
var shackleselectedmfc;
var shackleselectionmfc;
var lineselectionprice;
var cruisingStyle;
var clubRacingStyle;
var grandPrixRacingStyle;
var sailingStyle = "";
var finalsku;
var finaldescription;
var spliceclass;
var halyardIdent;

// Variables required for status bar
var step = 1;
var stepname = 'Select Your Primary Sailing Style and Boat Model';


// Variables Required for Calculating Price
var shacklecomponentprice = 0;
var linecomponentprice = 0;
var splicecomponentprice = 0;
var cumulativetotalprice = 0;
// End of Price Variables

// End of Variable Declarations

function calculatehalyardprice()
	{
	shacklecomponentprice = shacklecomponentprice - 0; 
	linecomponentprice = linecomponentprice - 0;
	splicecomponentprice = splicecomponentprice - 0;
	cumulativetotalprice = shacklecomponentprice + linecomponentprice + splicecomponentprice;
	cumulativetotalprice = cumulativetotalprice.toFixed(2);
	}


function final()
        {
                $.ajax({
                url: "final.php",
                data: "mfc=Torresen+Rigging" + "&sku=10001CustomHalyard" + "&check=CustomHalyard08" + "&price=" + $('#cumulativetotalprice').html() + "&description=" + $('#finaldescription').html(),
                cache: false,
                success: function(html){
                        $("#spliceselection").hide();
                        $("#final").append(html);
                        $("#final").show();
        		$(".stepperV1 ul li#st5").removeClass("current");
        		$(".stepperV1 ul li#st5").addClass("done");
        		$(".stepperV1 ul li#st6").addClass("current");
			$(".stepperV1 ul li .wLnk").hide();
			$(".stepperV1 ul li .wOLnk").show();
			$(".stepperV1 ul li#st6 .wOLnk").hide();
			$(".stepperV1 ul li#st6 .wLnk").show();
                                        }
                        });
        }


function spliceselection()
        {

        $("#spliceselection").empty();

                $.ajax({
                url: "spliceselection.php",
                data: "boat_length=" + $('#loa').html() + "&spliceclass=" + spliceclass + "&boat_class=" + $('#boatclass').html(),
                cache: false,
                success: function(html){
			$("#lineselection").hide();
                        $("#spliceselection").append(html);
                        $("#spliceselection").show();
                        $("#lineLabel").hide();
        		$(".stepperV1 ul li#st4").removeClass("current");
        		$(".stepperV1 ul li#st4").addClass("done");
        		$(".stepperV1 ul li#st5").addClass("current");
			//$(".stepperV1 ul li#st5 .wOLnk").hide();
			//$(".stepperV1 ul li#st5 .wLnk").show();
                                        }
                        });
        }





function contactRigger()
        {

	$(".otherOps a:contains('Contact')").hide();
	$("#contactRiggerForm").empty();

                $.ajax({
                url: "contactRigger.html",
                data: "boat_length=" + $('#loa').html() + "&boat_class=" + $('#boatclass').html(),
                cache: false,
                success: function(html){
                        $("#contactRiggerForm").append(html);
			$("#contactRiggerForm").show();
                                        }
                        });
        }


function contactRiggerSubmit()
        {

        $(".otherOps a").hide();

                $.ajax({
                url: "confirmation.php",
                data: "Customer_name=Chrisnway" + $('#Customer_name').val() + "&Contact_email=" + $('#Contact_email').val() + "&comments=" + $('#comments').val() + "&Contact_phone=" + $('#Contact_phone').val(),
                cache: false,
                success: function(html){
                       // $("#contactRiggerForm").append(html);
        $("#contactRiggerForm").empty();
        $("#contactRiggerForm").hide();
        $(".otherOps a:contains('Contact')").show();

                                        }
                        });
        }





function lineselection()
        {

	stepfour();

        }


function shackleselection()
	{

stepthree();

	}

function shackleselecteddetails()
	{
var shackleSelected = $(".shacklenumberselected:checked").val();
$("#shackleselection").hide();
// Remove the text telling what type of halyard was selected
$("#selectedhalyard2").hide();
// Replace with text telling what type of halyard was seleced AND the shackle selected
$("#selectedhalyard3").show();
lineselection();
	}


// When a user selects a shackle they  
// will be moved to the next step in the process
$('.shacklenumberselected')
	.livequery('click', function(event)	{

		$("#feet3").empty();
		$("#feet3").append(halyardlengthselected);
                $("#boat3").replaceWith($("#selectedboat"));
		$("#halyardtype3").empty();
                $("#halyardtype3").append(halyardtype);      
		var $this = $(this);
		shackleselectionnumber = $(".shacklenumberselected:checked").val();

		shackleselectiondescription = $this.find('.shackledescription').eq(0).html();
		shackleselectionprice = $this.find('.shackleprice').eq(0).html();
		shackleselectionmfc = $this.find('.shacklemfc').eq(0).html();
		shackleselectionsku = $this.find('.shacklesku').eq(0).html();

		shacklecomponentprice = shackleselectionprice;

		calculatehalyardprice();	
		$("#shackleselected").empty();
		$("#shackleselected").append(shackleselectiondescription);
		$("#shackleselectedmfc").empty();
		$("#shackleselectedmfc").append(shackleselectionmfc);
                $("#shackleselectedsku").empty();		
		$("#shackleselectedsku").append(shackleselectionsku);
		$("#shacklecomponentprice").empty();
		$("#shacklecomponentprice").append(shackleselectionprice);
		$("#cumulativetotalprice").empty();
		$("#cumulativetotalprice").append(cumulativetotalprice);
		$("#priceblock").show();
		shackleselecteddetails();
		return false;
						});

// When a user selects a line type / size they will
// move on to the selection of a splice

$('.h3OptionSel li a.lineSelection')
        .livequery('click', function(event)     {

var $this = $(this);

		lineselectionprice = $this.find('.lineprice').eq(0).html();
		lineselectiondescription = $this.find('.linedescription').eq(0).html();
		lineselectionmfc = $this.find('.linemfc').eq(0).html();
		spliceclass = $this.find('.spliceclass').eq(0).html();
		linecost = lineselectionprice * halyardlengthselected;
		linecost = linecost.toFixed(2);
		$("#linedescription").empty();
		$("#linedescription").append(lineselectionmfc);
		$("#linedescription").append(' ');
		$("#linedescription").append(lineselectiondescription);
                $("#linedescription").append(' @ $');
                $("#linedescription").append(lineselectionprice);
                $("#linedescription").append(' per foot');
		linecost = linecost - 0;
		shackleselectionprice = shackleselectionprice - 0;
		linecost1 = linecost.toFixed(2);
		$("#linecomponentprice").empty();
                $("#linecomponentprice").append(linecost1);
		shackleselectionprice = shackleselectionprice - 0;
		cumulativehalyardprice = linecost + shackleselectionprice;
		cumulativehalyardprice = cumulativehalyardprice.toFixed(2);
	        linecomponentprice = linecost;	
		calculatehalyardprice();
		$("#cumulativetotalprice").empty();
                $("#cumulativetotalprice").append(cumulativetotalprice);
                spliceselection();
		return false;
                                                });



// When a user selects a splice they will be 
// moved on to the final halyard page

$('.spliceselection')
        .livequery('click', function(event)     {


var $this = $(this);

			$("#spliceselection").hide();
                        $("#spliceLabel").hide();
                        spliceselectionprice = $this.find('.spliceprice').eq(0).html();
                        splicecomponentprice = $this.find('.spliceprice').eq(0).html();
                        spliceselectiondescription = $this.find('.splicedescription').eq(0).html();
			$("#spliceDescription").append(spliceselectiondescription);
			$("#splicecomponentprice").empty();
			$("#splicecomponentprice").append(spliceselectionprice);
		        calculatehalyardprice();	
	                $("#cumulativetotalprice").empty();
	                $("#cumulativetotalprice").append(cumulativetotalprice);

			finaldescription = 'Custom Main Halyard for ' + $('#selectedboatmodel').html() + '. Comes with a ' + $('#shackleselectedmfc').html() + ' ' + $('#shackleselectedsku').html() + 'Shackle and ' + '-' + $('#feet3').html() + ' feet of ' + $('#linedescription').html() + ' . ' + $('#spliceDescription').html();

			$("#finaldescription").append(finaldescription);
			final();
			$(".hPurchase").show();
			return false;

                                                });


$(".otherOps a:contains('Contact')")
    .livequery('click', function(event) {
        contactRigger();
        return false;
                                    });

$('.closeForm')
    .livequery('click', function(event) {
	$(".otherOps a:contains('Contact')").show();
        $("#contactRiggerForm").hide();

        return false;
                                    });


$('.submitForm')
    .livequery('click', function(event) {
        $(".otherOps a:contains('Contact')").show();
        $("#contactRiggerForm").hide();
        contactRiggerSubmit();
        return false;
                                    });



// TODO We need to combine most the components of 
// the next two functions into one at this time I think
// all but one variable is the same in both of these functions

$('a.halyardtypemastbase') 
    .livequery('click', function(event) { 
	$("#halyardoptionslist").hide();	
        $("a:contains('Click here to specify your own custom length')").hide();
	$("#feet").empty();
	$("#feet").append($("#mastbaselength"));
	$("#halyardtype").replaceWith("mastbase terminating ");
	$("a.selectanotherboat").show();
	$("#selectedhalyard2").show();
	$("a.selectanotherboat").show();
        $("#customhalyardlength").hide();
	halyardlengthselected = $('#mastbaselength').html();
	halyardtype = 'mastbase terminating';
	shackleselection();
	return false; 
				    }); 

$('a.halyardtypecockpit')
    .livequery('click', function(event) {
	$("#halyardoptionslist").hide();
	$("a:contains('Click here to specify your own custom length')").hide();
	$("#feet").empty();
        $("#feet").append($("#cockpitlength"));
	$("#halyardtype").replaceWith("cockpit terminating ");
	$("a.selectanotherboat").show();
	$("#selectedhalyard2").show();
	$("a.selectanotherboat").show();
	$("#customhalyardlength").hide();
	halyardlengthselected = $('#cockpitlength').html();
	halyardtype = 'cockpit terminating';
	shackleselection();
        return false;
    });


/*

$(".stepperV1 ul li#st1 .wLnk")
        .livequery('click', function(event) {

stepone();
return false;

});


$('a.selectanotherboat')
    .livequery('click', function(event) {
        
stepone();
return false;

    });



// Use this function when ever someone wants to select another boat 
// 

function stepone()
        {
	$(".h3OptionSel").empty();
	$("#spliceselection").empty();
        $("#lineselection").empty();
	$("#priceblock").hide();
	$("#final").empty();
        $("#show").hide();
        $("#boatlist").show();
        $('p.customhalyardlength').show();
        $("a:contains('Click here to specify your own custom length')").hide();
        $("a.selectanotherboat").hide();
        $("#shackleselection").hide();
        $(".hrdwrIFaceTitle").hide();
        $("#selectedhalyard2").hide();
        $(".h1OptionSel li#boatSelectList").show();
        $("#sailingStyle").show();
        $(".sailingStyleTitle").show();
        $(".stepperV1 ul li#st1 .wOLnk").hide();
	$(".stepperV1 ul li#st1 .wLnk").show();
        $(".stepperV1 ul li").removeClass("current");
        $(".stepperV1 ul li#st1").removeClass("done");
        $(".stepperV1 ul li#st1").addClass("current");
        sailingStyle = "";

	}

//
// End of function to use when ever someone wants to select another boat


*/


/*

How to go to step TWO --- Select Halyard Length

*/

$(".stepperV1 ul li#st2 .wLnk")
        .livequery('click', function(event) {

steptwo();
return false;

});

// Use this function when ever someone wants to select the Halyard Length Again 
//

function steptwo()
        {

        $(".h3OptionSel").empty();
	$("#spliceselection").empty();
        $("#lineselection").empty();
        $("#priceblock").hide();
        $("#final").empty();
        $("#show").empty();
	$("#selectedhalyard2").hide();

$.ajax({
  url: "customhalyard.php",
  data: "boat_info=" + $('#boatname').val() + "&sailingStyle=" + sailingStyle + "&halyardIdent=" + halyardIdent,
  cache: false,
  success: function(html){
    $("#show").append(html);

	$("#shackleselection").hide();
	$("#show").show();
        $(".stepperV1 ul li#st1").removeClass("current");
	$(".stepperV1 ul li:gt(1)").removeClass("current");
        $(".stepperV1 ul li#st1").addClass("done");
        $(".stepperV1 ul li#st2").addClass("current");
        $(".stepperV1 ul li#st2 .wOLnk").hide();
        $(".stepperV1 ul li#st2 .wLnk").show();
        $("#boatlist").hide();
        $("a.selectanotherboat").show();
        $("a.customlength").hide();
        $("#boatclass").hide();
        $(".h1OptionSel li#boatSelectList").hide();
        $(".hrdwrIFaceTitle").show();
        $("#sailingStyle").hide();

  }

});
	}
//
// End of function to use when ever someone wants to select the Halyard Length Again

/*
How to go to step THREE --- Select Shackle 
*/

$(".stepperV1 ul li#st3 .wLnk")
        .livequery('click', function(event) {

stepthree();
return false;

});

// Use this function when ever someone wants to select the Halyard Length Again
//

function stepthree()
        {
        $(".h3OptionSel").empty();
        $("#spliceselection").empty();
        $("#lineselection").empty();
	// priceblock placeholder
        $("#final").empty();
        $(".h1OptionSel").hide();
	$(".hrdwrIFaceTitle:gt(0)").hide();
	$(".h1OptionSel:eq(1)").hide();
        $("#shackleselection").empty();
        $(".stepperV1 ul li").removeClass("current");

                $.ajax({
                url: "shackleselection.php",
                data: "boat_class=" + $('#boatclass').html() + "&sailingStyle=" + sailingStyle,
                cache: false,
                success: function(html){
                        $("#shackleselection").append(html);
                        $("#shackleselection").show();
		        $(".stepperV1 ul li#st2").removeClass("current");
        		$(".stepperV1 ul li#st2").addClass("done");
        		$(".stepperV1 ul li#st3").addClass("current");
        		$(".stepperV1 ul li#st3 .wOLnk").hide();
        		$(".stepperV1 ul li#st3 .wLnk").show();

                                        }

                        });




        }

//
// End of function to use when ever someone wants to select the Shackle Again



/*
How to go to step FOUR --- LINE SELECTION 
*/

$(".stepperV1 ul li#st4 .wLnk")
        .livequery('click', function(event) {

stepfour();
return false;

});

// Use this function when ever someone wants to select the Line Again
//


// Use this function when ever someone wants to select the Line Again
//

function stepfour()
        {
        $(".h3OptionSel").empty();
        $("#spliceselection").empty();
        $("#lineselection").empty();
        $("#final").empty();
        $(".h1OptionSel").hide();
        $(".hrdwrIFaceTitle:gt(0)").hide();
        $(".h1OptionSel:eq(1)").hide();
        $("#shackleselection").empty();
        $(".stepperV1 ul li").removeClass("current");



                $.ajax({
                url: "halyardlineselection.php",
                data: "boat_length=" + $('#loa').html() + "&boat_class=" + $('#boatclass').html() + "&sailingStyle=" + sailingStyle,
                cache: false,
                success: function(html){
                        $("#lineselection").append(html);
                        $("#lineselection").show();
                        $("#shackleLabel").hide();
                        $(".spliceclass").hide();
        $(".stepperV1 ul li#st3").removeClass("current");
        $(".stepperV1 ul li#st3").addClass("done");
        $(".stepperV1 ul li#st4").addClass("current");
$(".stepperV1 ul li#st4 .wOLnk").hide();
$(".stepperV1 ul li#st4 .wLnk").show();
                                        }
                        });






        }

//
// End of function to use when ever someone wants to select the Line Again









    $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";
              });
          $("#boatnameselected").text(str);
	  })
        .change();

$("select").change(function () {

// Use this section to record sailing style 

$(".sailingStyleSelection:checked").each( function () {
sailingStyle = sailingStyle + $(this).val() + " ";
});

$("p:contains('Select your boat from this list')").addClass("whatisit");

steptwo();

/*

$.ajax({
  url: "customhalyard.php",
  data: "boat_info=" + $('#boatname').val() + "&sailingStyle=" + sailingStyle,
  cache: false,
  success: function(html){
    $("#show").append(html);
        $("#show").show();

	$(".stepperV1 ul li#st1").removeClass("current");
        $(".stepperV1 ul li#st1").addClass("done");
	$(".stepperV1 ul li#st2").addClass("current");
	$(".stepperV1 ul li#st2 .wOLnk").hide();
	$(".stepperV1 ul li#st2 .wLnk").show();

	$("#boatlist").hide();
	$("a.selectanotherboat").show();
	$("a.customlength").hide();
	$("#boatclass").hide();	
	$(".h1OptionSel li#boatSelectList").hide();	
	$(".hrdwrIFaceTitle").show();
	$("#sailingStyle").hide();	
  }


});

*/



$(".hPurchase").click(function() {

$("#cumulativetotalprice").hide();
return false;

});


$("a:contains('Click here to specify your own custom length')").show();
$("p.customhalyardlength").hide();
$("a:contains('Click here to choose from one of our recommended halyard lengths for your boat')").hide();

$("a.halyardtypecockpit").click(function() {
	$("a.step2").show();
        return false;
});


$("a.customlength").click(function() {

	$("p.customhalyardlength").show();	
	$("a.customlength").hide();
	$("a.recommendedlength").show();
   	return false;

});

$("a.recommendedlength").click(function() {

        $("p.customhalyardlength").hide();
        $("a.customlength").show();
        $("a.recommendedlength").hide();
        return false;

});

	});

$("#boatselect select").bind("change", function() { 
     this.form.submit(); 
}); 

});
