//What does this javascript file do?
/*
It allows the top navigation bar to show
unlimited levels of navigation bars
*/


//load jquery

function mainmenu()
{
jQuery(" #nav ul ").css({display: "none"}); // Opera Fix
jQuery(" #nav li").hover(function(){
		jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		jQuery(this).find('ul:first').css({visibility: "hidden"});
		});
} 

 jQuery(document).ready(function(){
								 
	mainmenu();
	commonHeight = setEqualHeight(jQuery(".hiding-featured .article"));
	featured();
	document.getElementById('fabox').style.overflow = "hidden";
	jQuery(".rowtwoleft embed").each ( function()
												{
													this.width=250;
													this.height=250;
												}
												);
	jQuery(".rowtworight embed").each ( function()
												{
													this.width=300;
													this.height=260;
												}
												);
  setEqualHeight(jQuery(".column"));  
  setEqualHeight(jQuery(".maincolumn"));  
  startSlider();


});
 
 function setEqualHeight(columns)  
{  
    var tallestcolumn = 0;  
    columns.each(function()
    {
	     currentHeight = jQuery(this).height();  
    	 if(currentHeight > tallestcolumn)  
	     {  
      			tallestcolumn  = currentHeight;  
	     }
    });  
    columns.height(tallestcolumn);  
	return tallestcolumn;
 }  
 function setFeaturedVideosWidth(videos)
 {
	 videos.each (
				  function ()
				  {
					  this.setAttribute("height",200);
					  this.setAttribute("width",250);
					  this.setAttribute("vspace",10);
				  }
				  );	 
 }
 function setRecentPostsVideosWidth(videos)
 {
	 videos.each (
				  function ()
				  {
					  this.setAttribute("height",280);
					  this.setAttribute("width",340);
					  this.setAttribute("vspace",10);
				  }
				  );	 
 }
var timer;

function startSlider()
{
	timer = window.setInterval('slide()',featuredDelay);
}
function slide()
{
	highest = elements.length-1;
	if (highest == 0)
	 	return;
	if (currentElementDisplayed == highest)
	   num=0;
	else
		num=currentElementDisplayed+1;
	switchTo(num);	
}
 var currentElementDisplayed = 0;
var commonHeight;
var featuredCount = 0;
var i=0;
var elements = new Array();

function loadjquery()
{
  if (typeof jQuery == 'undefined')  // no jquery! :o
	{
		var jq = document.createElement("script");
		jq.setAttribute("src",templateDir+"jquery.js");
		document.getElementById('loadhere').appendChild(jq);
	}
  setFeaturedVideosWidth(jQuery(".rowtwoleft embed"));
  setRecentPostsVideosWidth(jQuery(".rowtworight embed"));
}

function makeElements()
{	
   elements[i] = this;
   i++;							   
}
function featured()
{
	collection = jQuery(".hiding-featured .article");
	featuredCount = collection.length;
	collection.each ( makeElements);
	e = elements[0];
	currentElementDisplayed=0;
	 var wrapper = document.createElement("div")
	 wrapper.style.position = 'relative';
	 wrapper.style.zIndex = '2';
	 wrapper.style.zIndex = elements.length;
	 wrapper.appendChild(e);
	document.getElementById('thepost').appendChild(wrapper);
	var count = collection.length;
	//create page numbers
	var sliders = document.getElementById('sliders');
	for (var i=0;i<count;i++)
	{
		var pg = document.createElement("div");

		pg.setAttribute("class","page");
		pg.setAttribute("onclick","switchTo("+i+")");
		pg.innerHTML = i+1;
		currentPost = pg;
		sliders.appendChild(pg);
	}
}

function switchTo(num)
{
	if (num==currentElementDisplayed)
		return;	
		
	window.clearInterval(timer);
	timer = window.setInterval('slide()',featuredDelay);
	ele = elements[num];
	width = document.getElementById('thepost').style.width;
	ele.style.position='relative';
	ele.style.zIndex=1;
	ele.style.opacity= "1";

//	ele.style.top=-commonHeight+'px';	
	ele.style.display = "none";
    document.getElementById('thepost').appendChild(ele);
	var curr =  document.getElementById('thepost').children[0];
	curr.style.position = 'relative';
	currentElementDisplayed=num;
	jQuery(curr).fadeOut("slow");
		
	jQuery(ele).fadeIn("slow");
	ele.style.zIndex=2;
	jQuery(curr).remove();

	 //slide the current post
}


