// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var featured_index	= 0;
var hot_message_index = 0;

function toggle_video_display()
{
	//Effect.Appear("embedded_video", { duration: 0.5 });	
	var embedded_video = document.getElementById("embedded_video");
	//document.getElementById("embedded_video").style.display = "none";
	if (embedded_video.style.display!= "")
	{
		//alert('show');
		embedded_video.style.display = "";
		//Effect.Appear('embedded_video');
		//Effect.Appear('embedded_video', { duration: 0.1 });
	}
	else
	{
		//alert('hide');
		embedded_video.style.display = "none";
		//Effect.Fade('embedded_video');

		//Effect.Fade('embedded_video', { duration: 0.1 });
	}
}

function update_featured_indicator(max_count)
{
	
	for (i=0; i< max_count; i++)
	{
		if (i==featured_index)
		{
			document.getElementById("featured-page-indicator-"+i+"-white").style.display = "";
			document.getElementById("featured-page-indicator-"+i+"-gray").style.display = "none";
		}
		else
		{
			document.getElementById("featured-page-indicator-"+i+"-gray").style.display = "";
			document.getElementById("featured-page-indicator-"+i+"-white").style.display = "none";
		}
	}
}

function update_hot_messages(max_count)
{
	for (i=0; i < max_count; i++)
	{
		if (i==hot_message_index)
		{
			Effect.Appear("hot-news-item-"+i, { duration: 0.5 });
			//document.getElementById("hot-news-item-"+i).style.display = "";
		}
		else
		{
			Effect.Fade("hot-news-item-"+i, { duration: 0.5 });		 
			//document.getElementById("hot-news-item-"+i).style.display = "none";
		}
	}
}
function cycle_hot_news(max_count)
{
	//alert("cycle_hot_news");
	update_hot_messages(max_count);
	hot_message_index++;
	if (hot_message_index >= max_count) hot_message_index = 0;
	setTimeout("cycle_hot_news("+max_count+");", 4000);
}

function update_featured_readmore(max_count)
{
	
	for (i=0; i< max_count; i++)
	{
		if (i==featured_index)
			document.getElementById("featured-readmore-"+i).style.display = "";
		else
			document.getElementById("featured-readmore-"+i).style.display = "none";
	}
}

function previous_feature(index_count)
{
	if (featured_index < 1)
	{
		featured_index = index_count-1;
	}
	else
	{
		featured_index--;
	}
	new Effect.Move('slide-wrapper', 
					{
					x: -803*featured_index,
					y: 0, 
					mode: 'absolute',
					duration: 0.4,  
					transition: Effect.Transitions.sinoidal 
					});
	update_featured_indicator(index_count);
	update_featured_readmore(index_count);
	//alert("featured_index ="+featured_index+" / index_count="+index_count);
 
}

function next_feature(index_count)
{
	if (featured_index >= (index_count-1))
	{
		featured_index = 0;
	}
	else
	{
		featured_index++;
	}
	new Effect.Move('slide-wrapper', 
					{	
					x: -803*featured_index, 
					y: 0, 
					mode: 'absolute', 
					duration: 0.4,  
					transition: Effect.Transitions.sinoidal
					});
	update_featured_indicator(index_count);
	update_featured_readmore(index_count);
	//alert("featured_index ="+featured_index);

}


function show_featured_content_controls()
{
	var pr = document.getElementById('featured-right-arrow');

	if (pr.style.display!= "")
	{
		Effect.Appear('featured-left-arrow', { duration: 0.1 });
		Effect.Appear('featured-right-arrow', { duration: 0.1 });

		//Element.show('featured-left-arrow');
		//Element.show('featured-right-arrow');	
		
	}

}

function hide_featured_content_controls()
{
	try {
		var featured_x =  document.getElementById('featured-container').offsetLeft;
		var featured_y =  document.getElementById('featured-container').offsetTop;
		var xPos = Event.pointerX(event);
		var yPos = Event.pointerY(event);
		var x = xPos-featured_x;
		var y = yPos-featured_y;
		//setTimeout("auto_hide();",1000);
		//alert("x="+x+" y="+y);
		//if (x <= 1 || x >= 800 || y <= 1 || y >= 375)
		if (x >= 20 && x <= 118 && y >= 118 && y <= 250)
		{
			//alert("left block"); 
		}
		else if (x >= 685 && x <= 783 && y >= 118 && y <= 250)
		{
			//alert("right block"); 	
		}
		else if (x >= 697 && y <= 111)
		{
			//alert("right block"); 	
		}
		else
		{
			//alert("out"); 	
			//Element.hide('featured-left-arrow');
			//Element.hide('featured-right-arrow');	
			//Element.hide('featured-readmore');	
			Effect.Fade('featured-left-arrow', { duration: 0.1 });
			Effect.Fade('featured-right-arrow', { duration: 0.1 });
		}
		 
	}
	catch(err)
	{
		//Element.hide('featured-left-arrow');
		//Element.hide('featured-right-arrow');	
		//alert("error");
	}
}


function auto_hide_featured_content_controls()
{
		
//	setTimeout("auto_hide_featured_content_controls();", 1000);
//	hide_featured_content_controls();
}
function check_position_in_body()
{
/*	var featured_x =  document.getElementById('featured-container').offsetLeft;
	var featured_y =  document.getElementById('featured-container').offsetTop;
	var xPos = Event.pointerX(event);
	var yPos = Event.pointerY(event);
	var x = xPos-featured_x;
	var y = yPos-featured_y;
	alert("x="+x+" y="+y);
	//	setTimeout("auto_hide_featured_content_controls();", 1000);
	//	hide_featured_content_controls();
 */
}
