var loginID = 'wp323456577';
var fpwID = 'wp323456577';
var tafID = 'wp727688998';

var strUrl = "http://www.supersavvyme.com/lenorsk1/";
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

$(document).ready(function() {

	topNav(sPage);
	
	$('.nav-links A IMG').rollOverThis();

	var strThis = '<div class="reg-content-tile-top"></div><div class="reg-content-tile-base"></div><div class="reg-content-tile-swirl"></div>';

	/*LOGIN*/
	$('#ctl00_WebPartManager1_' + loginID + '_ctl00_Login1_LabelUserName').html('Just enter your details');
	$('#ctl00_WebPartManager1_' + loginID + '_ctl00_Login1_LabelAdresseEmail').html('Email');
	$('#ctl00_WebPartManager1_' + loginID + ' .LoginHeaderBackground').html('<h2><img height="138" width="657" src="/App_Themes/lenor-sk1/images/lenorsk1/h_lenor-pure-care-win.png" alt="Lenor Pure Care - Win a luxurious spa berak for two"></h2>')

	/*FPW*/
	$('#ctl00_WebPartManager1_' + fpwID + '_ctl00_PanelLostPassword .MemberHeader').before('<h2><img height="138" width="657" src="/App_Themes/lenor-sk1/images/lenorsk1/h_lenor-pure-care-win.png" alt="Lenor Pure Care - Win a luxurious spa berak for two"></h2>')

	/*TAF*/
	var strTafIntro = '<h2><img height="128" width="399" alt="Lenor Pure Care - Tell a friend" src="/App_Themes/lenor-sk1/images/lenorsk1/h_tell-a-friend.png" /></h2><p>You can tell you friends about Lenor\'s new Pure Care range and our fabulous competition.<br />Just fill in their details and we\'ll make sure they get your message</p><h3 class="form-header">Spread the word</h3>';
	$('#ctl00_WebPartManager1_' + tafID + ' .specific_header').html(strTafIntro);
	$('#ctl00_WebPartManager1_' + tafID + ' #ctl00_WebPartManager1_' + tafID + '_ctl00_DataListSponsoring').before('<p class="tellfriend-intro">Simply enter your friends\' names and email addresses on this page.</p>')
	$('#ctl00_WebPartManager1_' + tafID + '_ctl00_imgBtnSend').attr('src', '/App_Themes/lenor-sk1/images/lenorsk1/btn_submit.gif');
	$('#ctl00_WebPartManager1_' + tafID + '_ctl00_divMain .form_buttons').before('<input type="checkbox" id="tafconf" name="tafconf" class="dummy-check" /><p class="tell-friend-terms-info">All the recipients of these emails are over 18 years old and will be happy to receive this information. Note that the email addresses of your friends will not be kept and will not be utilised after this email is sent.*</p>');

	// have terms been checked on tell a friend?
	$('#ctl00_WebPartManager1_wp727688998_ctl00_imgBtnSend').click(function(){
		var getVal = $('.dummy-check').attr('checked');
			if(getVal){/*do nothing //window.location = "";*/}
			else
			{
				$('.error-tellfriend').remove();
				$('.divErrorMessages').remove();
				$('.dummy-check').before('<p class="error-tellfriend">* Please select the checkbox below</p>').css('display', 'block');
				return false;
			}
	});

	/*REGISTRATION*/
	$('#RegistrationLevel1').before('<div class="reg-content-tile-top"></div><div class="reg-content-tile-swirl"></div>');
	$('#RegistrationLevel1').before('<h2 class="title"><img height="138" width="657" src="/App_Themes/lenor-sk1/images/lenorsk1/h_lenor-pure-care-win.png" alt="Lenor Pure Care - Win a luxurious spa berak for two"></h2>');
	$('#RegistrationLevel1').before('<h2 class="registration-header">Registration - Please tell us about yourself</h2>');
	$('.RegistrationContainer').after('<div id="reg-form-footer"></div><div class="reg-content-tile-base"></div>');
	$('#ctl00_WebPartManager1_wp785451846_ctl00_imbCreateProfile').attr('src', '/App_Themes/lenor-sk1/images/lenorsk1/btn_register.gif');
	$('.imbAddChild').attr('src', '/App_Themes/lenor-sk1/images/lenorsk1/btn_add.gif');
	$('.imbRemoveChild').attr('src', '/App_Themes/lenor-sk1/images/lenorsk1/btn_remove.gif');

	/*CHX TERMS*/
	$('#competition-content-tile a#enter-now').click(function() { if ($('input:checkbox[name=competition-tsncs]:checked').val()) { return true; } else { $('#terms').addClass('error'); return false; } });

	$(document).pngFix();

});

//**********SOCIAL LINKS
var strUrl = 'http://www.supersavvyme.com/lenor/';
var strTitle = 'win an extravagant spa break for two';

function fbs_click() {
	u=strUrl;
	t='Just entered a great competition at ' + strUrl + ' to ' +strTitle+'.';
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer');
	return false;
}

function twitter(){
	u='';t='I\'ve just entered a great competition to ' + strTitle + ' - it\'s at ' + strUrl;
	window.open('http://twitter.com/home?status='+encodeURIComponent(t)+'+'+encodeURIComponent(u),'twitter');
	return false;
}

//**********ROLLOVER
(function($) {
	$.fn.rollOverThis = function() {
		var strtype = "";
		$(this).hover(function() {				
				strtype = findexts($(this).attr("src"));
				if($(this).attr("src").indexOf("active.") == -1) 
				{
					var newSrc = $(this).attr("src").replace("off."+strtype+"","active."+strtype+"#hover");
					$(this).attr("src",newSrc);
				}
			},
			function(){
				if($(this).attr("src").indexOf("active."+strtype+"#hover") != -1) {var oldSrc = $(this).attr("src").replace("active."+strtype+"#hover","off."+strtype+"");
				$(this).attr("src",oldSrc);}
			}
		);
		return this;
	};
})(jQuery);

//**********ROLLOVER UTIL (GETS FILE EXTENSION)
function findexts(filename) {if(filename != null){var from = filename.length - 3;var to = filename.length;filename = filename.substring(from,to);}return filename;}

//**********HI LITE TOP NAV TO SHOW SELECT STATE / AND O STUFF
function topNav(sPage){
	//if (sPage != 'register.aspx' && sPage != 'terms-and-conditions.aspx') {$('#footer-tile').css({ 'margin-top': '0' })}
	switch(sPage){
		case 'home.aspx': $('.home IMG').attr('src','/App_Themes/lenor-sk1/images/LenorSk1/bg_nav-home-active.png');break;
		case 'competition.aspx': $('.competition IMG').attr('src','/App_Themes/lenor-sk1/images/LenorSk1/bg_nav-competition-active.png');break;
		case 'products.aspx': $('.products IMG').attr('src','/App_Themes/lenor-sk1/images/LenorSk1/bg_nav-products-active.png');break;
		case 'peach-test.aspx': $('.peach-test IMG').attr('src','/App_Themes/lenor-sk1/images/LenorSk1/bg_nav-peach-test-active.png');break;
		case 
			'where-to-buy.aspx': $('.where-to-buy IMG').attr('src','/App_Themes/lenor-sk1/images/LenorSk1/bg_nav-where-to-buy-active.png');
			//RENDER DROPDOWN LIST && RENDER DEFAULT ITEMS
			for (var i=0;i<_products.length;i++){$('#range').append('<option value=' + _products[i][0] + '>' + _products[i][1] + '</option>');}		
			$('#shops').html(listShops(0));
			//RENDER ONCHANGE ITEMS	
			$("#range").change(function(){if (selRange != $(this).val()){selRange = $(this).val();$('#shops').fadeOut('fast');$('#shops').html(listShops($(this).val())).fadeIn('slow');}});
		break;
		case 'tell-a-friend.aspx': $('.tell-a-friend IMG').attr('src','/App_Themes/lenor-sk1/images/LenorSk1/bg_nav-tell-a-friend-active.png');break;
		case 'terms-and-conditions.aspx':break;
		case 'register.aspx':break;
		default:break;
	}
}

//**********WHERE TO BUY
var _products = new Array([0, 'Lenor Pure Care Sensitive'],[1, 'Lenor Pure Care Orange Blossom']);
var _shops = new Array(
	[0, 'asda','Asda','http://www.asda.com'],
	[1, 'tesco','Tesco','http://www.tesco.com'],
	[2, 'ocado','Ocado','http://www.ocado.com'],
	[3, 'sainsburys','Sainsbury\'s','http://www.sainsburys.co.uk'],
	[4, 'morrisons','Morrisons','http://www.morrisons.co.uk'],
	[5, 'waitrose','Waitrose','http://www.waitrosedeliver.com']);
var _options = new Array();_options[0] = [0, 1, 2, 3, 4, 5];_options[1] = [3, 5, 2];
var _speed = 800;
var strShops = '';
var selRange = 0;

function listObj(shop, name, url){return '<li><img alt="'+name+'" src="/App_Themes/lenor-sk1/images/lenorsk1/wtb_s_' + shop.toLowerCase() + '.jpg" /><a href="' + url + '" target="_blank"><img alt="Buy now from '+name+'" src="/App_Themes/lenor-sk1/images/lenorsk1/wtb_s_buy.jpg" /></a></li>'}
function listShops(range){var pstrShops='';for (var i=0;i<_options[range].length;i++){strThis = _options[0][i];pstrShops += listObj(_shops[strThis][1],_shops[strThis][2],_shops[strThis][3]);}return pstrShops;}

