$(document).ready(function() {

	$("p.searcharchives a").toggle(function(){
		//mimick checkbox
		$(this).addClass("checked");
		
		//add hidden fields
		$("#search form").prepend('<input name="site" type="hidden" value="default_collection" /><input name="client" type="hidden" value="default_frontend" /><input name="output" type="hidden" value="xml_no_dtd" /><input name="sitesearch" type="hidden" value="www.usc.edu/uscnews/stories" />');
		$('#search form input[name="IncludeBlogs"], #search form input[name="limit"]').remove();
		
		//change form action
		$("#search form").attr("action","http://uscnews.usc.edu/search/index.php");
		$("#search form input#searchbox").attr("name","q");
		$("#search form input#searchbox").attr("value","SEARCH NEWS ARCHIVE");
		return false;
	},
	function(){
		 
		//mimick empty checkbox
		$(this).removeClass("checked");
		
		//remove hidden fields
		$('#search form input[name="site"], #search form input[name="client"], #search form input[name="output"], #search form input[name="sitesearch"]').remove();
		$("#search form").prepend('<input type="hidden" name="IncludeBlogs" value="71" /><input type="hidden" name="limit" value="10" />');
		
		//change form action back
		$("#search form").attr("action","http://uscnews.usc.edu/mt/mt-search.cgi");
		$("#search form input#searchbox").attr("name","search");
		$("#search form input#searchbox").attr("value","SEARCH USC NEWS");
		return false;
	});
		
	
	//hiding stuff onLoad
	//$('li#forjournalists ul').hide();
	
	$('li#related-stories, li#latest-stories, li#inthenews_from88').after('<div class="gap"></div>');
	
	$('#share ul').hide();
	
	$('#share a.action').click(function(){
		$('#share ul').slideToggle('slow');
		return false;
	})

	//RSS feeds footer menu
	$('.feeds h3 a').mouseover(function(){
		$('#menu-rss').slideToggle();
		$(this).css('border','1px solid #999');
		return false;
	})
	
	$('.feeds h3 a').click(function(){return false;	})
	
	$('body, html').click(function(){
		$('#menu-rss').hide();
		$('.feeds h3 a').css('border','1px solid #ededed');
	})
	
	//For journalist sidebar action
	//$('li#forjournalists h3').click(function(){
	//	$('li#forjournalists ul').slideToggle('slow');
	//	$(this).toggleClass('downarrow');
	//	$('#content-sub').toggleClass('fixer');		
	//})
	
	/* Clears out the search box on click if the value is "Search" I
	did this for people who might misspell words so when they click back
	in the box they don't lose their search term */
	$("#search input").focus( function() {
		if ($(this).val()=="SEARCH USC NEWS") {$(this).val("");}
	});

	$("#search input").blur( function() {
		if ($(this).val()=="") {$(this).val("SEARCH USC NEWS");}
	});
	
	$("#search input").focus( function() {
		if ($(this).val()=="SEARCH NEWS ARCHIVE") {$(this).val("");}
	});

	$("#search input").blur( function() {
		if ($(this).val()=="") {$(this).val("SEARCH NEWS ARCHIVE");}
	});


	//USC in the News
	$('#news-usc li p').expander({
		slicePoint: 150, 
		widow: 2,
		expandText: '[show more]',
		expandPrefix: '... ',
		expandEffect: 'fadeIn',
		expandSpeed: '100',
		userCollapse: 'true',
		userCollapseText: '[show less]',
		userCollapsePrefix: ' '
	});
	
	//load youtube movie	
	$("#youtube #play a").click(function(){
		var movieid = $('#youtube #play p.title a').attr("title");
		
		$("#youtube #play a, #youtube img").hide();
		
		$(this).before('<object width="255" height="155"><param name="movie" value="http://www.youtube.com/v/'+movieid+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+movieid+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="255" height="155"></embed></object>');
		
		return false;
		});
	});

//Equal hieght columns
matchColumns=function(){ 
     var divs,contDivs,maxHeight,divHeight,d; 
     divs=document.getElementsByTagName('div'); 
     contDivs=[]; 
     maxHeight=0; 
     for(var i=0;i<divs.length;i++){ 
          if(/\bstretch\b/.test(divs[i].className)){ 
                d=divs[i]; 
                contDivs[contDivs.length]=d; 
                if(d.offsetHeight){ 
                     divHeight=d.offsetHeight; 					
                }
                else if(d.style.pixelHeight){ 
                     divHeight=d.style.pixelHeight;					 
                }
                maxHeight=Math.max(maxHeight,divHeight); 
          }
     }
     for(var i=0;i<contDivs.length;i++){ 
          contDivs[i].style.height=maxHeight + "px"; 
     }
}

// Runs the script when page loads 
window.onload=function(){ 
     if(document.getElementsByTagName){ 
          matchColumns();			 
     } 
}