/*@cc_on 

	@if (@_win32)

	try {document.execCommand('BackgroundImageCache', false, true);}catch(e){}

	@end

	@if (@_jscript_version >= 5.5 && @_jscript_version <= 5.6)

			var clear="/images/clear.gif";//move this line into the page between some conditional comments if using script with CMS that is rewriting URL's. don't forget to wrap script tags around it too.

			pngfix=function(){var els=document.getElementsByTagName("*");var ip=/\.png/i;var i=els.length;while(i-->0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=="no-repeat")?"crop":"scale";es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+"px";es.backgroundImage="none";var elkids=el.getElementsByTagName("*");if(elkids){var j=elkids.length}}}}};

			//$(function(){pngfix();});//use with jQuery

			window.attachEvent('onload',pngfix);//or use this for normal cases. Or call from your own events.

	@end

@*/



var fcFunctions = {	

	furtherInfo: function(o){

		if($('.further').length){

			//add some links and make them clickable

			$('.further').css('display', 'none');

			$('.further').after('<div class="furtherLink padding"><a href="#" class="more">More details</a></div>');

			$('.furtherLink .more').toggle(

				function(e){

					$(this).parent().prev().slideDown('slow');

					$(this).removeClass('more');

					$(this).addClass('less');

					$(this).text('Less details');

			  		return false;

				},

				function(e){

					$(this).parent().prev().slideUp('slow');

					$(this).removeClass('less');

					$(this).addClass('more');

					$(this).text('More details');

			  		return false;

				});



		}	

	},

	

	questions: function(o){

		if($('.questions').length){

			$('.questions .answer').css('display', 'none');

			$('.questions .question').toggle(

				function(e){

					$(this).next().slideDown('normal');

					$(this).removeClass('more');

					$(this).addClass('less');

			  		return false;

				},

				function(e){

					$(this).next().slideUp('normal');

					$(this).removeClass('less');

					$(this).addClass('more');

			  		return false;

				});



		}	

	},

	

	tooltip : function(o){

		if ($.browser.safari && $.browser.version < 523) {

   			//do nothing because the jquery tooltip crashes older versions of safari that should be supported

		} else {

			/*

			if($('a.helpbutton').length){

				$('a.helpbutton').tooltip({ 

					track: true, 

					delay: 0, 

					showURL: false, 

					showBody: " - ",

					top: -16,

					left: 9,

					fixPNG: true

				});

			}*/

		}

	},

	changeGenericAddress: function(o){

		if($('.changeGenericAddress').length > 0){

			//add some links and make them clickable

			$('.changeGenericAddress').css('display', 'none');

			$('.changeGenericAddress').prev().find('.text').html("<p><strong>Can't see your address?</strong</p><a rel='internal' class='green-arrow'><span>Enter your address</span></a>");

			$('.changeGenericAddress').prev().find('.text a').click(

				function(e){

					$('.changeGenericAddress').show('slow');

					$(this).parent().html("<p>If one of the addresses listed above is almost right, select it and edit the details below:</p>")

			  		return false;

				});

		}	

	},	

	changeServiceAddress: function(o){

		if($('.changeServiceAddress').length > 0){

			//add some links and make them clickable

			$('.changeServiceAddress').css('display', 'none');

			$('.changeServiceAddress').prev().find('.text').html("<p>Can't see your address?</p><a rel='internal' class='green-arrow'><span>Enter your service address</span></a>");

			$('.changeServiceAddress').prev().find('.text a').click(

				function(e){

					$('.changeServiceAddress').show('slow');

					$(this).parent().html("<p>If one of the addresses listed above is almost right, select it and edit the details below:</p>")

			  		return false;

				});

		}	

	},

	

	changeBillingAddress: function(o){

		if($('.changeBillingAddress').length > 0){

			//add some links and make them clickable

			$('.changeBillingAddress').css('display', 'none');

			$('.changeBillingAddress').prev().find('.text').html("<p>Can't see your address?</p><a rel='internal' class='green-arrow'><span>Enter your billing address</span></a>");

			$('.changeBillingAddress').prev().find('.text a').click(

				function(e){

					$('.changeBillingAddress').show('slow');

					$(this).parent().html("<p>If one of the addresses listed above is almost right, select it and edit the details below:</p>")

			  		return false;

				});

		}	

	},

	tabs: function() {

 		if ($('.quote-box').length) {

 			$('.quote-box').each(function() {

 				var tabContainers = $('div.quote-tab', this);

				$('ul.quote-tab-nav a', this).click(function() {

					tabContainers.hide().filter(this.hash).show();

					$('ul.quote-tab-nav a').removeClass('selected');

					$(this).addClass('selected');

					return false;

 				}).filter(':first').click();

 			});

 		}

 	},

	buttonChange_helper: {

		checkedCount: 0,

		originalButtonText: ''

	},

	buttonChange: function() {

		// Assumes checkboxes are all blank to begin with

		if ($('form.togglesButton')) {

			fcFunctions.buttonChange_helper.originalButtonText = $('#toggleButton').text();



			$('form.togglesButton input[type=checkbox]').bind("click", function() {

				if (this.checked) {

					fcFunctions.buttonChange_helper.checkedCount++;



					$('#toggleButton').text('Add to call');

				}

				else {

					fcFunctions.buttonChange_helper.checkedCount--;



					if(fcFunctions.buttonChange_helper.checkedCount == 0) {

						$('#toggleButton').text(fcFunctions.buttonChange_helper.originalButtonText);

					}

				}

			});

		}

	},

	openMovieWindow: function() {

		if(document.getElementById("flash-links")) {

			var flashLinks = document.getElementById("flash-links");

			var links = flashLinks.getElementsByTagName("a");

		

			for (i=0; i<links.length; i++) {

				links[i].onclick = function(){

					//alert('Clicked.');

					//window.open(this.href);

					window.open(this.href, "product_movie", "width=514,height=384,top=100,left=100,location=no,menubar=no,resizable=yes,status=no,toolbar=no");

					return false;

				}

			}

		}

	},

	

	hideFormElements: function() {

		//hide the elements 

		var gas= $("fieldset.gas");

		var electricity= $("fieldset.electricity");

		var gasSupplierYes= $("#gas-supplier-yes");

		var gasSupplierNo= $("#gas-supplier-no");			 

		var electricitySupplierYes= $("#electricity-supplier-yes");

		var electricitySupplierNo= $("#electricity-supplier-no");

		

		$(gas).addClass("hide");

		$(electricity).addClass("hide");

		

		//bind click events to the radio buttons for gas and electricty

		$(gasSupplierYes).bind("click", function(){

			$(gas).slideDown();

		});

		

		$(gasSupplierNo).bind("click", function(){

			$(gas).slideUp();

		});

		

		$(electricitySupplierYes).bind("click", function(){

			$(electricity).slideDown();

		});

		

		$(electricitySupplierNo).bind("click", function(){

			$(electricity).slideUp();

		});

	},

	tableColor: function() {

		//if the last row of the table is grey, then the background on .bottom of the div the table is inside needs to be grey as well

		var table= $(".tabs table");

		

		if($(table)) {

			if($(table).find("tr:last").hasClass("alt-row")){

				$(table).parents(".bottom").addClass("grey");

			}

		}

	},

	

	// TABS PANELS 

	tabFunction :  function(){

		

		$('div.tabs').hide(); 

		$('.dual').show();

	

	

		var __links = $("ul.tabs li");

		

		__links.bind("click", function(){



			var __class = $(this).attr("class");

			__class = __class.split(" ");

			$("div.tabs").hide(); 

			$("."+__class[0]).show();

			

			// remove the -selected class

			$.each(__links, function() {

				if($(this).attr("class").match("-selected")){

       			 	var __selectedClass = $(this).attr("class").split(" ");

					$(this).removeClass(__selectedClass[1]);

				}									  

    		});



			$(this).addClass(__class[0] + "-selected");



			return false;

			

		})

		

	

	},

	// CALLED IN THE moreLink FUNCTION 

	doToggle : function (ths) {



		// find the parent class name to target specifically that class

		var __parentclass = $(ths).parents('.tabs');

		var __parentclassName = $(__parentclass).attr("class");

		

		// this if statement is so the code can be used on other pages, as well as inside tabs with specific names

		if(__parentclassName){

			__parentclassName = __parentclassName.split(" ");

			// the unique classname of the parent for the is the first class in the list, so it's in the array at [0] - 

			//DO NOT ADD MORE CLASSES before this class

			__parentclassName = "." + __parentclassName[0];

		} else{

			__parentclassName = ".main-content";

		}

		

		

		// do the toggle

		if (ths.className.indexOf('less') != -1) {

			$( __parentclassName + ' .extra-content').slideUp('normal');

			$(ths).removeClass('less');

			$(ths).addClass('more');

			return false;

		} else {

			$(__parentclassName + ' .extra-content').slideDown('normal');

			$(ths).removeClass('more');

			$(ths).addClass('less');

			return false;

		}

	},

	

	// FOR THE MORE LINKS

	moreLink :  function(){

		if($('.extra-content').length){

			$('.extra-content').hide(); 

			$('.more-link').bind('click', function(e){

				fcFunctions.doToggle(this);

				return false;

			})

		}



	},

// TABS PANELS NEW

	tabFunctionNew :  function(){

		

		$('div.tabs-bg').hide(); 

		$('.dual').show();

	

	

		var __links = $("ul.tabs-bg li");

		

		__links.bind("click", function(){



			var __class = $(this).attr("class");

			__class = __class.split(" ");

			$("div.tabs-bg").hide(); 

			$("."+__class[0]).show();

			

			// remove the -selected class

			$.each(__links, function() {

				if($(this).attr("class").match("-selected")){

       			 	var __selectedClass = $(this).attr("class").split(" ");

					$(this).removeClass(__selectedClass[1]);

				}									  

    		});



			$(this).addClass(__class[0] + "-selected");



			return false;

			

		})

		

	

	},
	
	
	tabFunctionNewCO :  function(){
	
			
	
			$('div.c-tabs').hide(); 
	
			$('.carbon1').show();
	
		
	
		
	
			var __links = $("ul.c-tabs li");
	
			
	
			__links.bind("click", function(){
	
	
	
				var __class = $(this).attr("class");
	
				__class = __class.split(" ");
	
				$("div.c-tabs").hide(); 
	
				$("."+__class[0]).show();
	
				
	
				// remove the -selected class
	
				$.each(__links, function() {
	
					if($(this).attr("class").match("-selected")){
	
	       			 	var __selectedClass = $(this).attr("class").split(" ");
	
						$(this).removeClass(__selectedClass[1]);
	
					}									  
	
	    		});
	
	
	
				$(this).addClass(__class[0] + "-selected");
	
	
	
				return false;
	
				
	
			})
	
			
	
		
	
		},
		
		
		
		//Market Condition
		
		
		tabFunctionNewEn :  function(){
			
					
			
					$('div.c-tabs5').hide(); 
			
					$('.energy1').show();
			
				
			
				
			
					var __links = $("ul.c-tabs5 li");
			
					
			
					__links.bind("click", function(){
			
			
			
						var __class = $(this).attr("class");
			
						__class = __class.split(" ");
			
						$("div.c-tabs5").hide(); 
			
						$("."+__class[0]).show();
			
						
			
						// remove the -selected class
			
						$.each(__links, function() {
			
							if($(this).attr("class").match("-selected")){
			
			       			 	var __selectedClass = $(this).attr("class").split(" ");
			
								$(this).removeClass(__selectedClass[1]);
			
							}									  
			
			    		});
			
			
			
						$(this).addClass(__class[0] + "-selected");
			
			
			
						return false;
			
						
			
					})
			
					
			
				
			
		},



	

	// TERMS AND CONDITIONS LINK - SHOW HIDING THE TABLE ROW

	termsConditionsLink: function(){

		if($('.terms-conditions').length){

			$('.terms-conditions').hide(); 

			$('.more-link').toggle(

				function(e){

					

					$(this).parents('tr').next('.terms-conditions').show();

					$(this).removeClass('more');

					$(this).addClass('less');

			  		return false;

				},

				function(e){

					$(this).parents('tr').next('.terms-conditions').hide();

					$(this).removeClass('less');

					$(this).addClass('more');

			  		return false;

				});

		}	

	}

}



$(function() {



	fcFunctions.furtherInfo();

	fcFunctions.changeGenericAddress();

	fcFunctions.changeServiceAddress();

	fcFunctions.changeBillingAddress();

	fcFunctions.questions();

	fcFunctions.tooltip();

	fcFunctions.tabs();

	fcFunctions.buttonChange();

	fcFunctions.openMovieWindow();

	fcFunctions.hideFormElements();

	fcFunctions.tableColor();

	fcFunctions.tabFunction();

	fcFunctions.tabFunctionNew();
	
	fcFunctions.tabFunctionNewEn();
	
	fcFunctions.tabFunctionNewCO();

	fcFunctions.moreLink();

	fcFunctions.termsConditionsLink();



});