// alert (currentFontSize);

jQuery(document).ready(function() {

// Remove things from the login box
	jQuery('#dnn_loginPane table tr:nth-child(2)').addClass('hide');
	jQuery('#dnn_loginPane table table tr:nth-child(2)').removeClass('hide');
	
	jQuery('#member-login td input + span').remove();

	jQuery('#member-login td a').each(function() {
		if(jQuery(this).text() == 'Forgot Password ?') {
			jQuery(this).parent().parent().remove();
		}
	});
// END Remove things from the login box
	
// Login
	if(jQuery('a#dnn_dnnLOGIN_cmdLogin').text() == 'Login') {
		jQuery('span#loginButtonContainer').css('display','none')
	}
	if(jQuery('a#dnn_dnnLOGIN_cmdLogin').text() == 'Logout') {
		jQuery('span#loginButtonContainer').css('display','block')
	}
// End Login

// Homepage Branding
	//Start Random one and timed rotation
	var randomStart = Math.ceil(Math.random()*(jQuery('#branding-nav li').length));
	if(randomStart != 0) {
		jQuery('#branding-nav li.current, #home div#dnn_ContentPane div.current').removeClass('current');
		jQuery('#branding-nav li:nth-child('+randomStart+')').addClass('current');
		var boxId = jQuery('#branding-nav li:nth-child('+randomStart+')').attr('id').split('_')[1];
		jQuery('#dnn_ContentPane #'+boxId+'').addClass('current');
	}
	
	var timedRotation;

	function autoRotate() {
		var numItems = jQuery('#branding-nav li').length;
		var currentIndex = jQuery('#branding-nav li.current').prevAll().length + 1;
		var nextItem;
		
		if(currentIndex == numItems) {
			nextItem = 1;
		} else {
			nextItem = currentIndex + 1;
		}
		jQuery('#branding-nav li.current').removeClass('current');
		jQuery('#branding-nav li:nth-child('+nextItem+')').addClass('current');		
		var boxId = jQuery('#branding-nav li:nth-child('+nextItem+')').attr('id').split('_')[1];
		jQuery('#dnn_ContentPane div.current').fadeOut('slow',function() {
			jQuery(this).removeClass('current');
			jQuery('#dnn_ContentPane #'+boxId+'').addClass('current').fadeIn('slow');
		});
		timedRotation = setTimeout(autoRotate,5000);
	}
	if(randomStart != 0) {
		timedRotation = setTimeout(autoRotate,5000);
	}
	//End Random one and timed rotation
	
	jQuery('#branding-nav a').click(function() {
		clearTimeout(timedRotation);
		var boxId = jQuery(this).parent().attr('id').split('_')[1];
		
		jQuery('#branding-nav li').removeClass('current');
		jQuery(this).parent().addClass('current');		
		
		jQuery('#dnn_ContentPane div.current').fadeOut('slow',function() {
			jQuery(this).removeClass('current');
			jQuery('#dnn_ContentPane #'+boxId+'').addClass('current').fadeIn('slow');
		});
		
		//timedRotation = setTimeout(autoRotate,5000);
		return false;
	});
// END Homepage Branding

// SubPage Tabbed Branding
	//Start Subpage timed rotation
	var subTimedRotation;
	var numItems = jQuery('#tab-navigation li').length;
	function subAutoRotate() {
		var numItems = jQuery('#tab-navigation li').length;
		var currentIndex = jQuery('#tab-navigation li.current').prevAll().length + 1;
		var nextItem;
		
		if(currentIndex == numItems) {
			nextItem = 1;
		} else {
			nextItem = currentIndex + 1;
		}
		jQuery('#tab-navigation li.current').removeClass('current');
		jQuery('#tab-navigation li:nth-child('+nextItem+')').addClass('current');		
		var current = jQuery('#tab-navigation li:nth-child('+nextItem+')').children().attr('id');
		current = current.replace('tab','');
		jQuery('#tabContainer > .current').fadeOut('fast',function() {
			jQuery(this).removeClass('current');
			jQuery('#tabContainer > div:nth-child('+current+')').fadeIn('normal');
			jQuery('#tabContainer > div:nth-child('+current+')').addClass('current');
		});
		subTimedRotation = setTimeout(subAutoRotate,5000);
	}
	if(numItems != 0) {
		subTimedRotation = setTimeout(subAutoRotate,5000);
	}
	//End Subpage timed rotation
	
	jQuery('#tab-navigation a').click(function() {
		clearTimeout(subTimedRotation);
		jQuery('#tab-navigation li').removeClass('current');
		jQuery(this).parent().addClass('current');
		var current = jQuery(this).attr('id');
		current = current.replace('tab','');
		
		jQuery('#tabContainer > .current').fadeOut('fast',function() {
			jQuery(this).removeClass('current');
			jQuery('#tabContainer > div:nth-child('+current+')').fadeIn('normal');
			jQuery('#tabContainer > div:nth-child('+current+')').addClass('current');
		});
		
		return false;									
	});
// END SubPage Tabbed Branding

// Text Resizer
	if(jQuery.cookie('textSize')){
		jQuery('#content').css('font-size', jQuery.cookie('textSize')+'px');
	}
	
	jQuery('#larger a').click(function(){
		var currentFontSize = jQuery('#content').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum < 16) {
			var newFontSize = currentFontSizeNum+2;
			jQuery('#content').css('font-size', newFontSize+'px');
			jQuery.cookie('textSize', newFontSize, { path: '/'});
		}
		return false;
	});
	
	jQuery('#default a').click(function(){
		jQuery('#content').css('font-size', '12px');
		jQuery.cookie('textSize', '12px', { path: '/'});
		return false;
	});
	
	jQuery('#smaller a').click(function(){
		var currentFontSize = jQuery('#content').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum > 10) {
			var newFontSize = currentFontSizeNum-2;
			jQuery('#content').css('font-size', newFontSize);
			jQuery.cookie('textSize', newFontSize, { path: '/'});
		}
		return false;
	});
// END Text Resizer

// Saving & Discounts page
	var containers = jQuery('#savings-discounts .module');
	containers.hide();
	
	jQuery('#savings-discounts h2 a').click(function () {
		containers.filter(this.hash).slideToggle();
		return false;
	})	

// Score Widget
jQuery('a.score-widget').click(function(){
	window.open(jQuery(this).attr('href'),'widgetWindow','width=500,height=410');
	return false;
});
// END Score Widget
});