
$(document).ready(function() {
	
	// Remove sitemap generator credits
	$('div.ddsg-wrapper div:last-child').hide();
	
	// Add class to end of footer-menu to remove divider
	$('#footer-menu li:last a').addClass('end');
	
	// Add hover effect for search button
	$('#searchsubmit').hover(
		function() { 
			$(this).css('border-style', 'solid').css('colo', '#FFF');
    	},
        function() {
			$(this).attr('style', '');
        }
	);
	
	// Add hover effect for search textbox
	$('#s').focusin(function(){ $(this).css('border-style', 'solid'); }).focusout(function(){ $(this).attr('style', ''); });

	// Set the min-height of the content div based on the browser window height
	resizeContent = function() {
		var newHeight = 380;
		if($('#content').outerHeight() < newHeight) {
			// Set new min height
			$('#content').css('min-height', newHeight+'px');      
			
			// Check for IE6 and set height
			if($.browser.msie && jQuery.browser.version.substr(0,3)=='6.0') {
				$('#content').css('height', newHeight+'px');    
			}
		}
	}
	
	$(window).bind('load', function(){  
		resizeContent();
	});

	// Setup colorbox for subscriber form
	if($('.widget_mailchimpsf_widget').length) {
		// Wrap and hide the sidebar mailchimp form
		$('.widget_mailchimpsf_widget').wrapInner('<div style="display:none;"><div id="mailchimp-form"></div></div>');
		
		// Add link to subscribe
		$('.widget_mailchimpsf_widget').append('<a id="mailchimp-link" href="#">Join Our<br />Mailing List</a>');
		
		// Set colorbox for form
		$('#mailchimp-link').colorbox({width:"300px", height:"380px", inline:true, href:"#mailchimp-form"});
		
		// Move widget to sidenav menu
		$('#menu').append( $('.widget_mailchimpsf_widget') );
		
		// Add class to end of menu to remove divider
		$('#menu li:last').addClass('end');
	
		// Show the widget
		$('.widget_mailchimpsf_widget').show();
	}
	
	setSidebarRollover = function() {
		// Get the index, need to check parent for blog related pages
		var index = $('li.current_page_item').index();
		if(index < 0) {
			index = $('li.current_page_parent').index();
			if(index < 0) {
				index = $('li.current-page-ancestor').index();
			}
		}
		
		// Get the new image based on current page and set the image source
		var src =  $('#menu-roller').attr("src").substring(0, $('#menu-roller').attr("src").lastIndexOf('/')+1) + index + '.png';
    	$('#menu-roller').attr("src", src);
	}
	
	$(window).bind('load', function(){  
		// Set the rollover image to the selected page
		setSidebarRollover();
	});
	
	// methods for the rollover effect on sidebar menu image
	$('#menu a').hover(
		function() { 
			// Get the new image and set the image source
        	var src =  $('#menu-roller').attr("src").substring(0, $('#menu-roller').attr("src").lastIndexOf('/')+1) + $(this).parent('li').index() + '.png';
        	$('#menu-roller').attr("src", src);
    	},
        function() {
			// Set the rollover image to the selected page
			setSidebarRollover();
        }
	);
	
	// Set solutions accordion
	if($('#solutions-pages').length) {
		$('#solutions-pages').accordion({ autoHeight: false, icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-arrow' } });

		// Check if header should be set to the solutions header
		if($('#hidden-header-url').length) {
			if($('#hidden-header-url').val().length) {
				$('#header-image').attr('src', $('#hidden-header-url').val());
			}
		}
	}
});


