var SearchForm = {
	keyword_placeholder : "keyword",
	date_placeholder : 'mm/dd/yyyy',
	initialize : function() {	
		$('#keyword,#from,#to').each(this.populate).focus(this.clear).blur(this.populate); 
		$('#search-in-ae').submit(this.submit);
	},
	submit : function(e) {
		$('#search-in-ae-submit').attr('disabled',true);
		$('#keyword,#from,#to').each(SearchForm.clear);
	},
	clear : function() {
		if ($(this).val() === SearchForm.getPH(this)) {
			$(this).val("");
		} 		
	},
	populate : function() {
		if ($(this).val() === "") {
			$(this).val(SearchForm.getPH(this));
		} 		
	},
	getPH : function(el) {
		return ($(el).attr('id') === "keyword") ? SearchForm.keyword_placeholder : SearchForm.date_placeholder;
	}
}

var alonNav = {
	CLASS_NAME : 'over',
	initialize : function() {
		$("#nav li").hover(function(){
				$(this).addClass(alonNav.CLASS_NAME);
			}, 
			function(){
				$(this).removeClass(alonNav.CLASS_NAME);
			}
		);
	}
};

var Categories = {
	state : false,
	state_adv : false,
	initialize : function()
	{
		$('#categories-trigger').click(Categories.click);
	},
	click : function (e)
	{
		Categories.state = !Categories.state;
		if (Categories.state)
		{
			$('#categories-form').slideDown('fast');
		} 
		else
		{
			$('#categories-form').slideUp('fast');
		}
		e.preventDefault();
	}
}

var mySlideshow = {
	viewer : null,
	init : function(){
		$('ul.photos_a').each(function(){
			mySlideshow.viewer = new PhotoViewer();
			$('a.slideshow').each(function(i){
				mySlideshow.viewer.add(this.href);
				$(this).click(function(e){ e.preventDefault(); mySlideshow.viewer.show(i)});
			})
		});
	}
}

$(document).ready(function() {
	$('#article').tabs();
	alonNav.initialize();
	
	//external links
	$('a[rel=external]').click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href')); 
	});

	Categories.initialize();
	SearchForm.initialize();
	NewsTicker.initialize();
	$('#print').show();
	$('#print a').click(function(e) { 
		e.preventDefault();
		window.print();
	});
	
	mySlideshow.init();
});


//hide elements toggled with JS
document.write('<link rel="stylesheet" type="text/css" media="screen" href="/css/js.css" />');
