$(document).ready(
	function() {
	 	/*
		| check to see if this is the home page
		*/
		//home_news();
		
		process_gmaps();
		
		rotate_testamonials();
		
		$('#site_spotlights').innerfade({ speed: 1000, timeout: 10000, type: 'sequence', containerheight: '275px' });
		
		//$('#site_testimonials').innerfade({ speed: 1000, timeout: 7000, type: 'sequence', containerheight: '300px' });
		
		setTimeout('toggle_page_main_news()', 10000);
		setTimeout('toggle_page_single_news()', 10000);
	}
);

function rotate_testamonials() {
	if($('.testamonial_container').length > 0) {
		
		var main_cont_height = 0;
		
		$('.testamonial_container').each(
			function(e) {
				if($(this).height() > main_cont_height){
					main_cont_height = $(this).height();
				}
			}
		);
		
		var new_height = (main_cont_height < 200) ? main_cont_height + 120 : main_cont_height + 70;
		
		$('#testamonial_container').height(new_height);
		
		if($('.testamonial_container').length > 1) {
			
			var inview = 0;
			
			setInterval(
				function(e){
					
					next_inview = (inview >= ($('.testamonial_container').length - 1)) ? 0 : inview + 1;
					
					$('#testamonial_'+inview).fadeOut(1000);
					$('#testamonial_'+next_inview).fadeIn(1000);
					inview = next_inview;
				},
				10000
			);
		}
	}
}

function home_news()
{
	if($('#home_page_news').length > 0)
	{
		$.post('/index_ajax/home_news', { }, function(data) {
			
			$('#home_page_news').html(data);
			
		});
	}
}

function set_home_page_news_text(num)
{
	var header = '&nbsp;';
	var text = '&nbsp;';
	
	if(num > 0)
	{
		header = eval('h'+num);
		text = eval('t'+num);
	}
	
	$('#home_news_header').html(header)
	$('#home_news_text').html(text);
}

function toggle_menu(oObj)
{
	var oSubmenu = $(oObj).siblings('.menu_second_container');
	var iSubmenu = oSubmenu.length;
	
	if(iSubmenu > 0) {
		var sClass = $(oObj).attr('class');
		
		if(sClass.search(/menu_in/) > -1)
		{
			$(oObj).removeClass('menu_in').addClass('menu_out');
		}
		else
		{
			$(oObj).removeClass('menu_out').addClass('menu_in');
		}
		
		oSubmenu.slideToggle();
	}
}

function accessability()
{
	var height = ($('#accessability_inner').css('height') == '50px') ? '0px' : '50px';
	
	if(height == '50px') {
		$('#accessability_inner').show();
	}
	
	$('#accessability_inner').animate(
		{
			height: height
		}, 
		500, 
		'', 
		function(e){
			if(height == '0px') {
				$('#accessability_inner').hide();
			}
		}
	);		
}

function setFontSize(sSymb)
{
	if(sSymb == undefined) {
		
		$('#content_middle').css('font-size', '11px')
		
		
		$('#menu').children().find('li').css('font-size', '11px')
	}
	else
	{
		var content = $('#content_middle').css('font-size');
		
		if(content != undefined)
		{
			content = content.replace(/px/, '');
			var new_content_eval = content+sSymb+'1';
			var new_content = eval(new_content_eval);
			
			$('#content_middle').css('font-size', new_content+'px');
		}
		
		if($('#menu').children().find('li').length > 0)
		{
			$('#menu').children().find('li').each(
				function(e) {
					var menu = $(this).css('font-size');
					
					if(menu != undefined)
					{
						menu = menu.replace(/px/, '');
						var new_menu_eval = menu+sSymb+'1';
						var new_menu = eval(new_menu_eval);
						
						$(this).css('font-size', new_menu+'px');
					}
				}
			);
		}
	}
}

var gmap_side_bar_html = "";
var gmap_gmarkers = [];
var gmap_htmls = [];
var gmap_i = 0;

//google maps
function createMarker(point, name, html, letteredIcon) {
  	var marker = new GMarker(point, { icon:letteredIcon });
    GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml('<div align="left">' + html + '</div>');
   	});
    marker.icon = 'b';
    // save the info we need to use later for the side_bar
    gmap_gmarkers[gmap_i] = marker;
    gmap_htmls[gmap_i] = html;
    // add a line to the side_bar html
    gmap_side_bar_html += '<a href="javascript:myclick(' + gmap_i + ')">' + name + '</a><br>';
    gmap_i++;
    return marker;
}

/*
|Pgae News
*/

function toggle_page_main_news() {
	if($('.pageNewsMainContainer').length > 0)
	{
		$('.pageNewsMainContainer').each(
			function(e) {
				var newsContainer = $(this);
				
				if(newsContainer.children('.pageNewsMain').length > 1) {
					var newsChildren = newsContainer.children('.pageNewsMain');
					
					var firstNewsChild = newsContainer.children('.pageNewsMain:first');
					
					var currentDisplayed;
					
					newsChildren.each(
						function(e) {
							var newsChild = $(this);
							if(newsChild.css('display') == 'block') {
								//this is the current displayed
								currentDisplayed = newsChild;
							}
						}
					);
					
					//get the next one (or first)
					if(currentDisplayed.next().length > 0) {
						var nextDisplayed = currentDisplayed.next();
					} else {
						var nextDisplayed = firstNewsChild;
					}
					
					currentDisplayed.fadeOut('normal',
						function(e) {
							nextDisplayed.fadeIn('normal');
						}
					);
					
					setTimeout('toggle_page_main_news()', 10000);
				}
			}
		);
	}
	
	return;
}

function toggle_page_single_news() {
	if($('.pageNewsMainSContainer').length > 0)
	{
		$('.pageNewsMainSContainer').each(
			function(e) {
				var newsContainer = $(this);
				
				if(newsContainer.children('.pageNewsMainS').length > 1) {
					var newsChildren = newsContainer.children('.pageNewsMainS');
					
					var firstNewsChild = newsContainer.children('.pageNewsMainS:first');
					
					var currentDisplayed;
					
					newsChildren.each(
						function(e) {
							var newsChild = $(this);
							if(newsChild.css('display') == 'block') {
								//this is the current displayed
								currentDisplayed = newsChild;
							}
						}
					);
					
					//get the next one (or first)
					if(currentDisplayed.next().length > 0) {
						var nextDisplayed = currentDisplayed.next();
					} else {
						var nextDisplayed = firstNewsChild;
					}
					
					currentDisplayed.fadeOut('normal',
						function(e) {
							nextDisplayed.fadeIn('normal');
						}
					);
					
					setTimeout('toggle_page_single_news()', 10000);
				}
			}
		);
	}
	
	return;
}
