//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
var i = 1;
var j = 1;
var curr = null;
$(window).load(function() {

		
		if( window.location.search != '' && window.location.hostname.indexOf("cms") < 0)
		{
			// put our query back into the search box
			var myQuery = escape(getQueryKey('q'));
			myQuery = myQuery.replace(/\+/g, " ");
			myQuery = myQuery.replace(/\%20/g, " ");
			$('#query').val(myQuery);

			// prepare Options Object for AJAX request
			var options =
			{
				type:		'GET',
				url:		'search.php',
				data:		location.href.split('?')[1],
				dataType: 	'xml',
				success:	processXml
			};
			$.ajax(options);
		}
		
	
	
	jQuery.getFeed({
       url: 'cmsxml/hot_topics.rss',
	   dataType: ($.browser.msie) ? "text" : "xml",
       success: function(feed) {
		   var length = feed.items.length;
		   var theHTML = "";
			for(var x = 0; x < length; x++ )
			{
				theHTML = theHTML + '<li><a href="' + feed.items[x].link + '">' + feed.items[x].title + '</a><br/><i>' + feed.items[x].description + '</i></li>'
				var bob = feed.items[x];
			}
		if($('#feedlist').length > 0)
			$('#feedlist')[0].innerHTML = theHTML;
		//$('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 16, dragMinHeight: 45, dragMaxHeight: 45});
       }
   });

	
	$("#recentNews li").each(function(){
		this.id = "a" + i;
		i = i + 1;
		
	});
	
	$("#brief .news div").each(function(){
		
		var myhref = $(this).children(".title")[0].href;
		var bob = $(this).children(".briefDiscriptionHolder").load(myhref + " .briefDiscription", function(){
			var length = this.childNodes.length - 1;
			var gina = $(this).children()[length];
			$(gina).append('<a href="' + myhref + '">More...</a>');
		});
		
		bob.append('<a href="' + myhref + '">More...</a>');
		this.id = "da" + j;
		j = j + 1;
	})
	
	/*$('.news li a').each(function()
	{
		var bob = this;
		var joe = $("<div id='" + 'da' + i + "'></div>").appendTo("#brief");
		this.id = 'a' + i;
		i = i + 1
		
		
	});*/
	
	$('#da1').show();
	$('#a1').addClass("active");
	curr = "a1";
	
	/*$('.news li a').each(function()
	{
		$('#' + 'da' + j).load( this.href + ' .title, .briefDiscription, .date');
		j = j + 1;
	});*/
	
	
	
	
	$('.news li').hover(function(){
		if(curr == this.id)
			return;
		
		
		$('#d' + this.id).show();
		$(this).addClass('active');
		
		if(curr != null)
		{
			$('#d' + curr).hide();
			$('#' + curr).removeClass("active");
			curr = this.id;
		}
		else
		{
			curr = this.id;
		}
			
	},
	function(){
	
	});
	
	$(".navtop > li.has_navchild").hover(function() {
	
			$(this).addClass("hoverstyle");
		},
		function () {
			$(this).removeClass("hoverstyle");
	});
	
	$(".movieImage").click(function()
	{
		var str = $(this)[0].className;
		var id = str.split(' ')[1];
		$('#' +  id).addClass("tabbed");
		$('#' + id + "_div").show();
		return false;
	});
	
	$(".movieToggle").toggle(function(){
		$(this).addClass("tabbed");
		$('#' + this.id + "_div").show();
	},
	function(){
		$(this).removeClass("tabbed");
		$('#' + this.id + "_div").hide();
	});
	
	$("#left .opinionnav li.selected li.selected").each(function(){
		 var ul = $(this).parent();
		var bob = $(ul).parent().addClass("nohighlight");
	
	});
	
	
	
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		
		$(".navtop > li li ").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
			
		});
		
		
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").mouseover(function () {
			$(this).addClass("redraw");
		});
		$(".navtop li ul").mouseout(function () {
			$(this).removeClass("redraw");
		});
	}
});
