$(document).ready(function() {
	$('#btnSearch').click(function() {
		if ($("#mySearch").valid()) {
			return true;
		}
		return false;
	});

	// Bookmark site
	if(window.opera) {
		if ($("a.bookmark").attr("rel") != ""){
			$("a.bookmark").attr("rel","sidebar");
		} 
	}

	$("a.bookmark").click(function(e){
		e.preventDefault();
		var url = this.href;
		var title = this.title;

		if (window.sidebar) { 
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { 
			window.external.AddFavorite( url, title);
		} else if(window.opera) { 
			return false; 
		} else { 
			 alert('Sorry, your browser does not support the requested action,'
			 + ' please add this page manually to your bookmarks.');
		}
	});

	$('.search').focus(function() {
		if (this.value == 'Search') { this.value=''; };
	});

	// print page function
	$('.print').click(function(e){e.preventDefault;window.print()});
	
	// sub menu - expand on click
	$('.folder').click(function() {
		$('#sub'+$(this).attr('id')).slideToggle();
	});
	
	// sub menu - expand parent element if child is selected
	// $('#panel ul li a.selected').parent().css('display', 'normal');
	// $("p").parent(".selected").css("background", "yellow");
	$("ul").parent("a.selected").css("padding-right", "10px");;

	// if blog panel exists move it to the panel
	if ($('#blog-panel').length) {
		$('#blog-panel').prependTo($('#panel'))
		$('#blog-panel').show()
	}

	// headline scroll content
	var headline_count;
	var headline_interval;
	var old_headline = 0;
	var current_headline = 0;
	headline_count = $("div.blog-scroll").size();
	$("div.blog-scroll:eq("+current_headline+")").css('top','0px');
	headline_interval = setInterval(headline_rotate,5000); //time in milliseconds

	function headline_rotate() {
		current_headline = (old_headline + 1) % headline_count; 
		$("div.blog-scroll:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
		$(this).css('top','210px');
		});
		$("div.blog-scroll:eq(" + current_headline + ")").show().animate({top: 0},"slow");  
		old_headline = current_headline;
	}

	$('#GuyQuote-link').fancyZoom({width:800, height:400});
	$('#GrahamQuote-link').fancyZoom({width:800, height:540});
	$('#SallyQuote-link').fancyZoom({width:800, height:800});
});

Cufon.replace('h1')('.inner-content h2')('.post h2')('h3')('#phone');
