$(document).ready(function() { init(); });

function init() {
	/* --- header --- */
	show_hide_text('#q');
	
	/* --- lead area --- */
	
	$('.quote_gallery').cycle({
		fx			: 'fade',
		random	: 1,
		timeout	: 10000,
		sync		: 0, 
    delay		: 1000
	});
	
	$('.news_gallery').cycle({
		fx			: 'fade',
		random	: 1,
		timeout	: 10000,
		sync		: 0, 
    delay		: -1000 
	});
	
	$('.blue_box_all').cycle({
		fx			: 'fade',
		random	: 1,
		timeout	: 20000,
		sync		: 0, 
    delay		: -2000 
	});
	
	/* --- galley --- */
	$('#gallery').cycle();
	
	/* --- navigation --- */
	$('.nav ul li').corner('top 7px');
	
	$('.nav ul li').hover(function(){
		$(this).css('background-position','0 -10px').click(function(){
			window.location = $(this).find('a').attr('href');
		}).find('a').css('color', '#3566b4');
	},function(){
		$(this).css('background-position','0 0').find('a').css('color', '#11234a');
	});
	
	set_external_links();
	find_safed();
}

function show_hide_text(el) {
	$(el).each(function() {
		document['def_'+$(this).attr('name')] = $(this).attr('value');
		$(this).focus(function() { if($(this).attr('value') == document['def_'+$(this).attr('name')]) $(this).attr('value','');	});
		$(this).blur(function()	 { if($(this).attr('value') == '') $(this).attr('value',document['def_'+$(this).attr('name')]);	});
	});
}

// open external links in a new window
function set_external_links() {
	var server = 	window.location.protocol + '//' +  window.location.host;
	
	// (get absolute links) (not on this server)
	$('a[href^=http]').not('a[href^="'+server+'"]').click(function(ev){
		ev.preventDefault();
		// open a new window
    window.open(this.href);
    return false;
	});
}

function find_safed() {

	// words to check against
	var words = ['SAFed','SAFED','safed','Safed'];
	
	// for each word in the list
	for(var i=0; i<words.length; i++) {
		
		// find h1's with the word in
		$("h1:contains('"+ words[i] + "')").each(function(){
			
			// remove the css styling
			$(this).css('text-transform','none');
			
			// get the text
			var text = $(this).html();
			
			// make the text uppercase again
			var uc = text.toUpperCase();
			
			// change the case of safed
			var new_text = uc.replace("SAFED","SAFed");
			
			// set the text of the h1 back to what it should be
			$(this).html(new_text);
		});
	
	}
}
