// JavaScript Document
function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/";
}
// This functions reads & returns the cookie value of the specified cookie (by cookie name)
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

function search() {
    var $searchString = $("#searchBox input.searchInput").val();
    if ($searchString != undefined && ($searchString.toUpperCase() != "SEARCH" || $searchString != "")) {
        window.location = "search.aspx?q=" + $searchString;
    }
}

var enlargeState = parseInt(getCookie("TextSize"));
$(document).ready(function() {
	$("#searchBox input.searchSubmit").click(function() { search(); });
	$("#searchBox input.searchInput").keypress(function(e) {
	    if (e.which == 13) {
	        search();
	        return false;
	    }
	});
	var centerWidth = 0;
	var footerWidth = 0;
	$('#centerMenu>ul>li').each(function() {
		centerWidth = centerWidth + $(this).width();
	});
	$('#centerMenu').css('width', centerWidth+6);
	$('#topNav ul').superfish();
	if (isNaN(enlargeState)) {
		setCookie("TextSize", 1, 365);
		enlargeState = 1;
	}
	else {
		switch (enlargeState)
		{
			case 0:
				$('.enlargeThis h1').css('font-size', 18);
				$('.enlargeThis h2').css('font-size', 16);
				$('.enlargeThis h3').css('font-size', 14);
				$('.enlargeThis .subHead').css('font-size', 12);
				$('.enlargeThis').css('font-size', 12);
				$('#decrease').addClass('off');
			break;
			case 1:
				$('.enlargeThis h1').css('font-size', 21);
				$('.enlargeThis h2').css('font-size', 19);
				$('.enlargeThis h3').css('font-size', 17);
				$('.enlargeThis .subHead').css('font-size', 15);
				$('.enlargeThis').css('font-size', 15);
				$('#decrease').removeClass('off');
			break;
			case 2:
				$('.enlargeThis h1').css('font-size', 24);
				$('.enlargeThis h2').css('font-size', 22);
				$('.enlargeThis h3').css('font-size', 20);
				$('.enlargeThis .subHead').css('font-size', 18);
				$('.enlargeThis').css('font-size', 18);
				$('#decrease').removeClass('off');
			break;
			case 3:
				$('.enlargeThis h1').css('font-size', 27);
				$('.enlargeThis h2').css('font-size', 25);
				$('.enlargeThis h3').css('font-size', 23);
				$('.enlargeThis .subHead').css('font-size', 21);
				$('.enlargeThis').css('font-size', 21);
				$('#decrease').removeClass('off');
				$('#enlarge').addClass('off');
			break;
		}
	}
	$('#enlarge').click(function() {
		switch (enlargeState)
		{
			case 0:
				$('.enlargeThis h1').css('font-size', 21);
				$('.enlargeThis h2').css('font-size', 19);
				$('.enlargeThis h3').css('font-size', 17);
				$('.enlargeThis .subHead').css('font-size', 15);
				$('.enlargeThis').css('font-size', 15);
				enlargeState++;
				setCookie("TextSize", enlargeState, 365);
				$('#decrease').removeClass('off');
			break;
			case 1:
			  	$('.enlargeThis h1').css('font-size', 24);
				$('.enlargeThis h2').css('font-size', 22);
				$('.enlargeThis h3').css('font-size', 20);
				$('.enlargeThis .subHead').css('font-size', 18);
				$('.enlargeThis').css('font-size', 18);
			  	enlargeState++;
				setCookie("TextSize", enlargeState, 365);
			break;
			case 2:
			  	$('.enlargeThis h1').css('font-size', 27);
				$('.enlargeThis h2').css('font-size', 25);
				$('.enlargeThis h3').css('font-size', 23);
				$('.enlargeThis .subHead').css('font-size', 21);
				$('.enlargeThis').css('font-size', 21);
				enlargeState++;
				setCookie("TextSize", enlargeState, 365);
				$('#enlarge').addClass('off');
			break;
		}
	});
	$('#decrease').click(function() {
		switch (enlargeState)
		{
			case 3:
				$('.enlargeThis h1').css('font-size', 24);
				$('.enlargeThis h2').css('font-size', 22);
				$('.enlargeThis h3').css('font-size', 20);
				$('.enlargeThis .subHead').css('font-size', 18);
				$('.enlargeThis').css('font-size', 18);
				enlargeState--;
				setCookie("TextSize", enlargeState, 365);
				$('#enlarge').removeClass('off');
			break;
			 case 2:
				$('.enlargeThis h1').css('font-size', 21);
				$('.enlargeThis h2').css('font-size', 19);
				$('.enlargeThis h3').css('font-size', 17);
				$('.enlargeThis .subHead').css('font-size', 15);
				$('.enlargeThis').css('font-size', 15);
				enlargeState--;
				setCookie("TextSize", enlargeState, 365);
			break;
			case 1:
				$('.enlargeThis h1').css('font-size', 18);
				$('.enlargeThis h2').css('font-size', 16);
				$('.enlargeThis h3').css('font-size', 14);
				$('.enlargeThis .subHead').css('font-size', 12);
				$('.enlargeThis').css('font-size', 12);
				enlargeState--;
				setCookie("TextSize", enlargeState, 365);
				$('#decrease').addClass('off');
			break;
		}
	});
	
	
	
	$('#footerSiteMap>ul>li').each(function () {
		if(parseInt($(this).css('width')) > 120) {
			$(this).css('width', 120);
			footerWidth = footerWidth + $(this).width();
		}
	});
	
	$('.subpage .slideCT').hover(function() {
		$(this).find('.slideImg img').css('margin-top','-102px');
		$(this).find('.slideText .slideover').stop(true,true).animate({
			height: '70px'
		});
	},function() {
		$(this).find('.slideImg img').css('margin-top','0');
		$(this).find('.slideText .slideover').stop(true,true).animate({
			height: '0'
		});
	});
	
	$('.home .slideCT').hover(function() {
		$(this).find('.slideImg img').css('margin-top','-138px');
		$(this).find('.slideText .slideover').stop(true,true).animate({
			height: '70px'
		});
	},function() {
		$(this).find('.slideImg img').css('margin-top','0');
		$(this).find('.slideText .slideover').stop(true,true).animate({
			height: '0'
		});
	});
	
	$('#dnn_newsRight li .grow').each(function () {
		var i = $(this);
		var iH = i.height();
		var iW = i.width();
		var p = i.attr('src').toString();
		$(this).closest('li').hover(function() {
			$(this).stop(true,true).animate({backgroundColor:'#e9e9e9'},200);
			$(this).find('.grow').stop(true,true).animate({
				height: iH*1.1,
				width: iW*1.1,
				top: -(iH*0.05),
				left: -(iW*0.025)
			},200,function() {
				i.attr('src',p.replace('.png','-o.png'));
			});
		},function() {
			$(this).stop(true,true).animate({backgroundColor:'#d6d6d6'},200);
			$(this).find('.grow').stop(true,true).animate({
				height: iH,
				width: iW,
				top: 0,
				left: 0
			},200,function() {
				i.attr('src',p.replace('-o.png','.png'));
			});
		});
	});
	
	$('#footerSocial a').each(function () {
		var i = $(this).children('.grow');
		var iH = i.height();
		var iW = i.width();
		var p = i.attr('src').toString();
		i.css('position','absolute').parent('a').height(iH).width(iW);
		$(this).hover(function() {
			i.attr('src',p.replace('.jpg','-o.jpg'));
			i.stop(true,true).animate({
				height: iH*1.1,
				width: iW*1.1,
				top: -(iH*0.05),
				left: -(iW*0.05)
			},100);
		},function() {
			i.attr('src',p.replace('-o.jpg','.jpg'));
			i.stop(true,true).animate({
				height: iH,
				width: iW,
				top: 0,
				left: 0
			},100);
		});
	});
	
	$('.restore').each( function() {
		var input = $(this); 
		var inputVal = input.val();
		input.siblings('.inputValue').text(inputVal);
		input.siblings('.inputValue').click( function(){ 
			input.focus();
			
			if( input.val() != inputVal ) { 
				return false; 
				input.css('color','#8c2121');
			} 
			input.css('color','#8c2121'); 
			input.val('');
			$(this).stop(true,true).fadeOut(200);
		});
		input.focus( function(){ 
			if( input.val() != inputVal ) { 
				return false; 
			} 
			input.val('');
			input.css('color','#8c2121'); 
			$(this).siblings('.inputValue').fadeOut(200);
		});
		input.blur( function(){ 
			if( input.val() == '' ) { 
				input.val( inputVal );
				input.css('color','#FFFFFF'); 
				$(this).siblings('.inputValue').stop(true,true).fadeIn(200); 
			} 
		});
	});
	$('#leftNav li').each(function() {
		if ($(this).hasClass('selected')){
			$(this).parents('li').addClass('selected');
		}
	});
	
	$('#leftNav li li:not(.selected), #leftNav li li li:not(.selected').hover(function () {
		$(this).addClass('hover');
		$(this).find('span').stop(true,true).animate({
			paddingLeft: '15px'
		},150);
	},function() {
		$(this).removeClass('hover');
		$(this).find('span').stop(true,true).animate({
			paddingLeft: '0'
		},150);
	});
	
	$('#leftNav li li.selected').next().addClass('noBorder');
	$('#leftNav>ul>li>ul>li.mmHasChild>a>span').prepend('<img src="/portals/_default/skins/SeniorBridge/images/blank.png" class="hasChild" />');
	$('#leftNav li li li.selected span').prepend('<img src="/portals/_default/skins/SeniorBridge/images/blank.png" class="selectedChild" />');
});

$(function() {
$('#slideshow').cycle({
	fx:       'fade',
	timeout:   6500,
	after: onAfter,
	before: onBefore,
	random:  1		 
	});
});
function onAfter(curr,next,opts) {
		$('#slideshowcaption').html(this.alt).fadeIn(500);
}

function onBefore(curr,next,opts) {
		$('#slideshowcaption').html(this.alt).fadeOut(0);
}	
