jQuery(function() {
	jQuery("div#panel4 p#terms span").hide();
	jQuery("div.mixContent").hide();
	jQuery("div.mixContent:eq(0)").show();
	
	

	// Add an onclick event to the mix cube options for the channel tab.
	// Clicking the mix option lists the channels included with that mix.
	jQuery("a.mixLink").mouseover(function() {
		jQuery("div.mixContent").hide();
		if (document.getElementById(this.href.split('#')[1])){
			document.getElementById(this.href.split('#')[1]).style.display='block';						
		}
	});
	jQuery("a.mixLink").mouseout(function() {
	    jQuery("div.mixContent").hide();
	    jQuery("div.mixContent:eq(0)").show();
	});	
	//Added onClick to stop jumping
	jQuery("a.mixLink").click(
	    function() {return false;}
	);
	
	// Add an onclick event to the Example costs tab to initialise the
	// costing options accordion effect.
	jQuery("ul#topNavigation > li > a[href='#panel3']").click(function() {
		jQuery("div#combos").accordion();
	});
	
	// Hide all the info boxes (on panel 4)
	jQuery("ul#topNavigation > li > a[href='#panel4']").click(function() {
        //Setting display to none seems to blow IE6 up
        jQuery("div.infoBox").css({left:"-100em"})
	});		       
    
    // Position an information box to its associated link
	jQuery("div#panel4 a.info").hover(
	    function() {
            var infoBox = jQuery(this).attr("href").split('#')[1];
            var infoBoxX = jQuery(this).offset().left;
            var infoBoxY = jQuery(this).offset().top;
            //console.log('infoBoxX :'+infoBoxX);
            //console.log('infoBoxY :'+infoBoxY);
            jQuery("div#"+infoBox).css({top:infoBoxY-70,left:infoBoxX-328});
        },
	    function() {
            var infoBox = jQuery(this).attr("href").split('#')[1];
            //Setting display to none seems to blow IE6 up
            jQuery("div#"+infoBox).css({left:"-100em"});
        }      
	);	
	//Added onClick to stop jumping
	jQuery("div#panel4 a.info").click(
	    function() {return false;}
		);
	// Position an information box to its associated link
	jQuery("div#panel4 a.help").hover(
	    function() {
            var infoBox = jQuery(this).attr("href").split('#')[1];
            var infoBoxX = jQuery(this).offset().left;
            var infoBoxY = jQuery(this).offset().top;
            //console.log('infoBoxX :'+infoBoxX);
            //console.log('infoBoxY :'+infoBoxY);
            jQuery("div#"+infoBox).css({top:infoBoxY-20,left:infoBoxX-328});
        },
	    function() {
            var infoBox = jQuery(this).attr("href").split('#')[1];
            //Setting display to none seems to blow IE6 up
            jQuery("div#"+infoBox).css({left:"-100em"});
        }      
	);	

	//Added onClick to stop jumping
	jQuery("div#panel4 a.help").click(
	function() {return false;}
	);

	// Prices 
	var setupCostStandard = 60;
	var setupCostSkyPlus = 30;
	var setupCostSkyPlusHD = 30;

	var standardBox = 0;
	var plusBox = 49.00;
	var hdBox = 49.00;

	var stdPrice = ['17.50','18.50','19.50','20.50','21.50','22.50'];
	var plusSports = ['35.50','36.50','37.50','38.50','39.50','40.50'];
	var plusMovies = ['33.50','34.50','35.50','36.50','37.50','38.50'];
	var plusBoth = ['42.50','43.50','44.50','45.50','46.50','47.50'];

	// check if boxes are selected and how many
	function doTally(el){
		var checkedCount = 0;
		var checkBoxes = document.getElementById(el).getElementsByTagName('input');
		var totalCount = checkBoxes.length;
		
		    for (var i=0; i<checkBoxes.length; i++)  {
		        if (checkBoxes[i].checked)  {
					checkedCount++;
		        }
		    }
		return checkedCount;
	}
	
	// check which boxes are ticked and get related prices	
	jQuery(":input").click (function(e) {
		var currentPriceMonthly = 0;
		var currentPriceEquipm = 0;
		
		var currSelMixes = doTally("entOptions");
		var currSelPremiT = doTally("premOptions");
		var currSelBox = doTally("equipOptions");
			
			if (currSelMixes > 0 || currSelPremiT > 0 || currSelBox > 0) {
				
				// set the various prices from the correct option
				if (currSelMixes > 0) {
					var optionsMix = currSelMixes - 1;					
					if (currSelPremiT > 0) {
						if (currSelPremiT == 2){currentPriceMonthly = plusBoth[optionsMix];}
						else if (currSelPremiT == 1) {
							if (document.getElementById("skyMoviesCB").checked == true) {currentPriceMonthly = plusMovies[optionsMix]}
							if (document.getElementById("skySportsCB").checked == true) {currentPriceMonthly = plusSports[optionsMix]}
						}
					} else {currentPriceMonthly = stdPrice[optionsMix]}
				} 
				else {currentPriceMonthly = 0;}
			
				if (currSelBox > 0) {
					// check which box option is selected then assign the correct price	
					var boxChoiceList = jQuery(":radio");
					var boxChoice = "";
					for (var i=0; i< boxChoiceList.length;i++) {
						if (boxChoiceList[i].checked == true) {
							boxChoice = boxChoiceList[i].value;
						}
						if (boxChoice == "standard") {
						    currentPriceEquipm = standardBox;
						    setupCost = setupCostStandard;};
						if (boxChoice == "skyPlus") {
						    currentPriceEquipm = plusBox;
						    var setupCost = setupCostSkyPlus;};
						if (boxChoice == "skyHD") {
						    currentPriceEquipm = hdBox;
						    var setupCost = setupCostSkyPlusHD;};
						if (boxChoice == "skyPlus" || boxChoice == "skyHD") {
                            jQuery("div#panel4 p#terms span").show();
						} else {
						    jQuery("div#panel4 p#terms span").hide();
						}
						if (boxChoice != "skyPlus" && boxChoice != "skyHD") {
						}
					}
				} else {currentPriceEquipm = 0; setupCost = 0;}
			} 
			else if (currSelMixes == 0 || currSelPremi == 0 || currSelBox == 0) {
				setupCost = 0;
				currentPriceEquipm = 0;
				currentPriceMonthly = 0;
			}
			
			// set prices	
			document.getElementById("monthlyCostPrice").innerHTML = currentPriceMonthly;			
			document.getElementById("equipmentCostPrice").innerHTML = currentPriceEquipm+".00";
			document.getElementById("setupCostPrice").innerHTML = setupCost+".00";
	})
	
});	

























