/*@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;
				}
			}
		}
	},
	
	openMovieWindow1: function() {
				if(document.getElementById("flash-links1")) {
					var flashLinks1 = document.getElementById("flash-links1");
					var links1 = flashLinks1.getElementsByTagName("a");
				
					for (i=0; i<links1.length; i++) {
						links1[i].onclick = function(){
							//alert('Clicked1.');
							//window.open(this.href);
							window.open(this.href, "product_movie", "width=900,height=520,top=100,left=100,location=no,menubar=no,resizable=yes,status=no,toolbar=no");
							return false;
						}
					}
				}
	},

openMovieWindow2: function() {

				if(document.getElementById("flash-links2")) {

					var flashLinks2 = document.getElementById("flash-links2");

					var links1 = flashLinks2.getElementsByTagName("a");

				

					for (i=0; i<links1.length; i++) {

						links1[i].onclick = function(){

							//alert('Clicked1.');

							//window.open(this.href);

							window.open(this.href, "product_movie", "width=514,height=325,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");
			}
		}
	}
}

$(function() {
    fcFunctions.furtherInfo();
	fcFunctions.changeGenericAddress();
	fcFunctions.changeServiceAddress();
	fcFunctions.changeBillingAddress();
	fcFunctions.questions();
	fcFunctions.tooltip();
	fcFunctions.tabs();
	fcFunctions.buttonChange();
	fcFunctions.openMovieWindow();
	fcFunctions.openMovieWindow1();
	fcFunctions.openMovieWindow2();
	fcFunctions.hideFormElements();
	fcFunctions.tableColor();
});

