$(document).ready(function(){


	

	
	/* FOOTER AREA AND PARTICIPATION PAGE SHOW/HIDE FUNCTIONALITY */
		
		//first save the cookie to a var

		futureProductSelection = $.cookie("futureProduct");
		
		//check if there is a cookie, if not then dont run the cookie function	
		if(futureProductSelection == null){
			//DO NOTHING
		}else{
			//the second parameter of this function determines the fadeTime - setting the fade time to 0 for the cookie function... 
			//...gets round the issue of seeing the default product set
			productShowHide(futureProductSelection, 0);
		}
		
		/*below sets the cookie on click*/
		
		//get the name of the page you are on so you can disable the cookie show/hide for this page
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		if(sPage == "participating.aspx"){
			$('.footer .brand-logos li a').css('cursor', 'default');
		}
		
		$('.footer .brand-logos li a').click(function(){
			
			if(sPage != "participating.aspx"){
				//firstly clear any previous cookie data						   
				$.cookie("futureProduct", null);
				//find the info you want to store in the cookie and set to a var
				futureProductSelection = $(this).attr('rel');
				//now run the save cookie function to store the cookie data
				saveCookie(futureProductSelection);
			}else if(sPage == "participating.aspx"){
				//rewrite footer links when on the participating page so they dont refresh the page
				$('.footer .brand-logos li a').each(function(){
					$(this).attr("href", "#");
				});
			}
		});
		
		function saveCookie(futureProductSelection){
			//create and save a cookie to the browser
			$.cookie("futureProduct", futureProductSelection);
		}
		
		function productShowHide(getAttr, fadeTime){
			$('.content .pod2').find('.current').fadeOut(fadeTime, function(){
				$(this).removeClass('current');
				$('#'+getAttr+'').fadeIn(fadeTime).addClass('current');
			});
		}
		
		$('.product-selection li a').click(function(){
			var getAttr = $(this).attr("rel");
			productShowHide(getAttr, 'normal');
			return false;
		});
		
	/* FOOTER AREA AND PARTICIPATION PAGE SHOW/HIDE FUNCTIONALITY */
	
	
	/* BAG SELECTION FORM ACTION REWRITE*/
	/* ORDER OF ARRAY = Green, Light Green, Blue, Light blue, Grey, Pink, Purple, Red */
	var urlEsampleRewrite = [
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=35DEFC59-7496-4179-B992-A814945C35C2',
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=24e58a09-1eb2-4e81-ab01-ab5c803c2816',	
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=4FB7008A-D716-45FB-8A61-0183406C5E02',
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=FA7E2286-5B53-40A5-9D7E-54CF289153EA',
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=D647BA4B-C172-48AA-8577-57E19B6CDF99',
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=89affccb-f1bc-4c6d-bb3e-97a9d60b2a7e',
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=896df3c7-944e-47c3-8541-31617c1410ea',
	'http://www.supersavvyme.com/futurefriendly/sample.aspx?CampaignId=8bb1a73b-05d0-4ceb-8518-e475826f8c88',
	];
	var findIndex = $('#bagDropDown option:selected').index();
	$('#aspnetForm').attr('action', urlEsampleRewrite[findIndex]);
	$('#bagDropDown').change(function(){
		var findIndex = $('#bagDropDown option:selected').index();
		$('#aspnetForm').attr('action', urlEsampleRewrite[findIndex]);
		
		var getSelectedBag = $('#bagDropDown option:selected').attr('name');
		$('#bagsforlife .bagimageswap').fadeOut(function(){$(this).attr('src', '../ITGCFiles/BrandSite/FutureFriendly/selected-bag-'+getSelectedBag+'.jpg')}).fadeIn();
	});
	
	/* BAG SELECTION FORM ACTION REWRITE*/
	
	/* REGISTER PAGE */
	$('#ctl00_WebPartManager1_wp1711833325 div:eq(0)').css('display', 'none');
	$('#ctl00_WebPartManager1_wp1202805046 div:eq(0)').css('display', 'none'); /*GET RID OF VERY FIRST DIV WITH HEIGHT*/
	$('table.RegistrationForm > tbody > tr:eq(1) > td:eq(0)').addClass('col1'); /*WHO ARE YOU COLUMN CLASS ADDED*/
	$('table.RegistrationForm > tbody > tr:eq(1) > td:eq(2)').addClass('col2'); /*YOUR ADDRESS COLUMN CLASS ADDED*/
	$('table.RegistrationForm > tbody > tr:eq(1) .TxtDropDownList:eq(2)').addClass('yearField'); /*CLASSNAME ADDED TO ALLOW YEARFIELD STYLING*/
	$('table.RegistrationForm > tbody > tr:eq(5) > td').addClass('subscribeInfo'); /*CLASSNAME ADDED TO ALLOW STYLING OF CONTENT BELOW COL1/2*/
	$('table.RegistrationForm > tbody > tr:eq(1) > td:eq(2) table').addClass('yourAddress');
	$('table.RegistrationForm > tbody > tr:eq(5) > td:eq(0)').addClass('borderBg');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table:eq(0)').addClass('borderBg');
	$('table.RegistrationForm > tbody > tr:eq(6) > td:eq(0)').addClass('bottomCorner');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(0)').addClass('hide');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(1) > td').addClass('recieveOffersOptIn');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) > td').addClass('yourFamliy');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) input:eq(0)').addClass('addRemoveBtns').attr('src', '../App_Themes/FutureFriendly/images/WebPartSubscription/add.gif');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) input:eq(1)').addClass('addRemoveBtns').attr('src', '../App_Themes/FutureFriendly/images/WebPartSubscription/remove.gif');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) > td > table > tbody > tr:eq(13) input:eq(0)').addClass('addRemoveBtns').attr('src', '../App_Themes/FutureFriendly/images/WebPartSubscription/add.gif');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) > td > table > tbody > tr:eq(13) input:eq(1)').addClass('addRemoveBtns').attr('src', '../App_Themes/FutureFriendly/images/WebPartSubscription/remove.gif');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(6) > td > table > tbody > tr:eq(0) > td').empty().html('<div class="yourFamilyText">Your Family </div><div class="ensureText">To ensure we send the most relevant information and offers for you and your family, please answer the following questions.</div>');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(10) > td > input:eq(1)').addClass('hide');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(10) > td').addClass('registerCell');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(10) > td > input:eq(0)').addClass('registerBtn').attr('src', '../App_Themes/FutureFriendly/images/WebPartSubscription/btn_valider.gif');
	$('table.RegistrationForm > tbody > tr:eq(6) > td > table > tbody > tr:eq(12) > td > div > p').addClass('conditions');
	$('table.RegistrationForm .DetailsRowspace').css('display', 'none');
	
	$('table.RegistrationForm tr[title="Date of birth"] td:eq(1) > table > tbody > tr:eq(0) > td:eq(0)').css('display', 'none');
	/* CONTENT REWRITE */
	$('table.RegistrationForm .yourAddress .title').text('Your address');
	$('table.RegistrationForm > tbody > tr > td > table > tbody > tr > td:eq(0)').html('<img src="../ITGCFiles/BrandSite/FutureFriendly/registration-header.gif" alt="Registration - Please tell us about yourself" /><span id="ctl00_WebPartManager1_wp1202805046_ctl00_lblUserFound" class="TextAlertGlobalBold"></span>');
	/* CONTENT REWRITE */
	/* REGISTER PAGE */
	
	
	/* LOGIN PAGE */
	$('.PaddingLogin > table > tbody > tr > td:eq(0)').addClass('loginTd');
	$('.LoginTextInnerPadding span').before('<h2>Get your free bag for life</h2>');
	$('.PaddingLogin .LoginHeaderText').text('To do your bit for the environment, make sure you get your hands on a free reusable bag, made from recycled plastic bottles. The colour dyes all comply with European environmental guidelines.');
	$('.btncreateac input').attr('src', '../App_Themes/FutureFriendly/images/WebPartLogin/btn_createAccount.gif');
	$('.btnaligment input').attr('src', '../App_Themes/FutureFriendly/images/WebPartLogin/btn_valider.gif');
	
	var checkLostPasswordPage = $('.PaddingLogin .MemberHeader h1').text();
	
	if(checkLostPasswordPage == "Password forgotten"){
		/*PASSWORD FORGOT*/
		$('.PaddingLogin').addClass('passwordForgot');
		$('.passwordForgot .MemberHeader').html('<h1>I need a password reminder</h1><h2><img height="34" width="708" alt="Forgotten your password? Please type in your email address below:" src="../ITGCFiles/BrandSite/FutureFriendly/passwordforgotten-header.gif"></h2>');
		$('.passwordForgot .calageinnercontainer .txtLoginMemberSmallFont').after('<img src="../ITGCFiles/BrandSite/FutureFriendly/thankyou-products-image.jpg" alt="" />');
		$('.passwordForgot .btnaligment input').attr('src', '../ITGCFiles/BrandSite/FutureFriendly/passwordforgot-confirm.gif');
		/*PASSWORD FORGOT*/
	}else{
		$('.PaddingLogin .MemberHeader h1').html('<img src="../ITGCFiles/BrandSite/FutureFriendly/login-input-header.gif" width="407" height="34px" alt="Already a supersavvyme member?" />');
	}
	
	$('.PaddingLogin .NotMemberHeader h1').html('<img src="../ITGCFiles/BrandSite/FutureFriendly/notmember-header.gif" alt="New to Supersavvyme" />');
	$('.PaddingLogin .shadowborder').css('display', 'none');
	$('.PaddingLogin .InnerContainer_PaddingLeft div:eq(0), .PaddingLogin .InnerContainer_PaddingLeft div:eq(1)').css('display', 'none');
	$('.PaddingLogin .InnerContainer_PaddingLeft div:eq(2)').before('<div>Email:</div>');
	$('.PaddingLogin .RowPaddingTop span:eq(0) span').text('Password:');
	$('.PaddingLogin .RowPaddingTop:eq(1) span span').css('display', 'none');
	$('.PaddingLogin .RowPaddingTop:eq(1) span a').text('I need a password reminder');
	$('.PaddingLogin .visiomember img').before('<img class="login-box-image" src="../ITGCFiles/BrandSite/FutureFriendly/login-bags.gif" width="194" height="171" alt="" />');
	$('.PaddingLogin .visiomember img:eq(1)').css('display', 'none');
	$('.innernotmember .txtLoginMemberSmallFont').html('<p>Register with supersavvyme.com to get your free bag, as well as inspirational ideas to help you make the most out of life.</p><p>Registering only takes a few moments, and gives you access to lots of exclusive offers and extras.</p>');
	/* LOGIN PAGE */
	
	/* SEND TO FRIEND*/
	$('.MemberGetMemberMain .form_layout').wrap('<div class="form_layout_tile"></div>');
	$('.MemberGetMemberMain .form_layout').wrap('<div class="form_layout_botcnr"></div>');
	$('.form_layout_tile .form_layout_botcnr').before('<h2><img src="../ITGCFiles/BrandSite/FutureFriendly/sendtofriend-header.gif" alt="Tell a friend"></h2><h3>Tell a friend</h3><p>Why don\'t you spread the word? Simply fill in your friends\' details below:</p>');
	$('.MemberGetMemberLabelError').before('<p class="sendtofriend-terms"><a target="_blank" href="termsandconditionsff.aspx">Terms and conditions</a></p><div class="sendtofriend-terms-form"><input id="terms" type="checkbox" /><label>The recipient/s of these emails must be 18 years old and happy to receive this information. Please note that the email addresses will not be kept after this email is sent.</label></div>');
	$('.form_layout .sendtofriend-terms-form').before('<p class="error">Please confirm you agree to the terms and conditions.</p>');
	$('.form_layout .form_buttons input').addClass('submit');
	$('.form_layout .form_buttons input').attr('src', '../ITGCFiles/BrandSite/FutureFriendly/sendtofriend-submit.gif');
	/* SEND TO FRIEND*/
	
	
	/* bagforlife.aspx AND sendtofriend.aspx FORM ACTION VALIDATION */
	$('#submit, input.submit').click(function(){
		var termsValidationBagsForLife = $('#terms').attr('checked');
		if(termsValidationBagsForLife){
			// Submission allowed
		}else{
			// Submission denied
			$('.error').show();
			return false;
		}
	});
	/* bagforlife.aspx AND sendtofriend.aspx FORM ACTION VALIDATION */
	
	
	$(".AspNet-WebPart:eq(3) > div > div > table > tbody > tr > td:contains('Request already processed')").css('display', 'none');
	
	var queryString = window.location.search;
	if (queryString.indexOf("tellafriend.aspx")>0){
		$('.LoginTextInnerPadding h2').text("Tell a friend");
		$('.LoginHeaderText').text("If you'd like your friends to hear about the Future Friendly initiative and order their own free bag for life, here's the place to tell them about it.");
		$('#header-log ul li:eq(1) a img').attr('src', '../ITGCFiles/BrandSite/FutureFriendly/bagforlife-nav.gif');
		$('#header-log ul li:eq(2) a img').attr('src', '../ITGCFiles/BrandSite/FutureFriendly/tellafriend-nav-on.gif');
		$('.head-image-lessmore').attr('src', '../ITGCFiles/BrandSite/FutureFriendly/less-more-logo-tell.jpg');
		$('#header-log').css('background', 'url("../../ITGCFiles/BrandSite/FutureFriendly/header-background-tell.jpg") no-repeat scroll 0 0 transparent');
		$('.PaddingLogin').css('background', 'url("../../ITGCFiles/BrandSite/FutureFriendly/login-form-bg-tell.jpg") no-repeat scroll 0 0 transparent');
	}				
});


